17 if (!values->
pid || !values->
tid || !values->
value) {
18 pr_debug(
"failed to allocate read_values threads arrays");
29 pr_debug(
"failed to allocate read_values counters arrays");
30 goto out_free_counter;
53 for (i = 0; i < values->
threads; i++)
59 for (i = 0; i < values->
counters; i++)
67 void *npid = realloc(values->
pid, nthreads_max *
sizeof(*values->
pid)),
68 *ntid = realloc(values->
tid, nthreads_max *
sizeof(*values->
tid)),
69 *nvalue = realloc(values->
value, nthreads_max *
sizeof(*values->
value));
71 if (!npid || !ntid || !nvalue)
77 values->
value = nvalue;
83 pr_debug(
"failed to enlarge read_values threads arrays");
92 for (i = 0; i < values->
threads; i++)
93 if (values->
pid[i] == pid && values->
tid[i] == tid)
105 if (!values->
value[i]) {
106 pr_debug(
"failed to allocate read_values counters array");
123 pr_debug(
"failed to enlarge read_values rawid array");
129 pr_debug(
"failed to enlarge read_values rawid array");
133 for (i = 0; i < values->
threads; i++) {
134 u64 *
value = realloc(values->
value[i], counters_max *
sizeof(**values->
value));
138 pr_debug(
"failed to enlarge read_values ->values array");
162 u64 rawid,
const char *
name)
166 for (i = 0; i < values->
counters; i++)
204 int pidwidth, tidwidth;
209 fprintf(fp,
"INTERNAL ERROR: Failed to allocate counterwidth array\n");
214 for (j = 0; j < values->
counters; j++)
216 for (i = 0; i < values->
threads; i++) {
219 width = snprintf(NULL, 0,
"%d", values->
pid[i]);
220 if (width > pidwidth)
222 width = snprintf(NULL, 0,
"%d", values->
tid[i]);
223 if (width > tidwidth)
225 for (j = 0; j < values->
counters; j++) {
226 width = snprintf(NULL, 0,
"%" PRIu64, values->
value[i][j]);
227 if (width > counterwidth[j])
228 counterwidth[j] = width;
232 fprintf(fp,
"# %*s %*s", pidwidth,
"PID", tidwidth,
"TID");
233 for (j = 0; j < values->
counters; j++)
234 fprintf(fp,
" %*s", counterwidth[j], values->
countername[j]);
237 for (i = 0; i < values->
threads; i++) {
238 fprintf(fp,
" %*d %*d", pidwidth, values->
pid[i],
239 tidwidth, values->
tid[i]);
240 for (j = 0; j < values->
counters; j++)
241 fprintf(fp,
" %*" PRIu64,
242 counterwidth[j], values->
value[i][j]);
251 int width, pidwidth, tidwidth, namewidth, rawwidth, countwidth;
260 for (i = 0; i < values->
threads; i++) {
261 width = snprintf(NULL, 0,
"%d", values->
pid[i]);
262 if (width > pidwidth)
264 width = snprintf(NULL, 0,
"%d", values->
tid[i]);
265 if (width > tidwidth)
268 for (j = 0; j < values->
counters; j++) {
270 if (width > namewidth)
272 width = snprintf(NULL, 0,
"%" PRIx64, values->
counterrawid[j]);
273 if (width > rawwidth)
276 for (i = 0; i < values->
threads; i++) {
277 for (j = 0; j < values->
counters; j++) {
278 width = snprintf(NULL, 0,
"%" PRIu64, values->
value[i][j]);
279 if (width > countwidth)
284 fprintf(fp,
"# %*s %*s %*s %*s %*s\n",
285 pidwidth,
"PID", tidwidth,
"TID",
286 namewidth,
"Name", rawwidth,
"Raw",
287 countwidth,
"Count");
288 for (i = 0; i < values->
threads; i++)
289 for (j = 0; j < values->
counters; j++)
290 fprintf(fp,
" %*d %*d %*s %*" PRIx64
" %*" PRIu64,
291 pidwidth, values->
pid[i],
292 tidwidth, values->
tid[i],
295 countwidth, values->
value[i][j]);
int perf_read_values_add_value(struct perf_read_values *values, u32 pid, u32 tid, u64 rawid, const char *name, u64 value)
static int perf_read_values__findnew_thread(struct perf_read_values *values, u32 pid, u32 tid)
#define pr_debug(fmt,...)
static int perf_read_values__enlarge_counters(struct perf_read_values *values)
void perf_read_values_display(FILE *fp, struct perf_read_values *values, int raw)
static int raw(yyscan_t scanner)
int perf_read_values_init(struct perf_read_values *values)
static int perf_read_values__findnew_counter(struct perf_read_values *values, u64 rawid, const char *name)
static void perf_read_values__display_pretty(FILE *fp, struct perf_read_values *values)
static int perf_read_values__enlarge_threads(struct perf_read_values *values)
static void perf_read_values__display_raw(FILE *fp, struct perf_read_values *values)
void perf_read_values_destroy(struct perf_read_values *values)
void static void * zalloc(size_t size)