13 die(
"failed to allocate read_values threads arrays");
22 die(
"failed to allocate read_values counters arrays");
33 for (i = 0; i < values->
threads; i++)
39 for (i = 0; i < values->
counters; i++)
47 values->
pid = realloc(values->
pid,
49 values->
tid = realloc(values->
tid,
54 die(
"failed to enlarge read_values threads arrays");
62 for (i = 0; i < values->
threads; i++)
63 if (values->
pid[i] == pid && values->
tid[i] == tid)
67 perf_read_values__enlarge_threads(values);
73 if (!values->
value[i])
74 die(
"failed to allocate read_values counters array");
79 static void perf_read_values__enlarge_counters(
struct perf_read_values *values)
89 die(
"failed to enlarge read_values counters arrays");
91 for (i = 0; i < values->
threads; i++) {
94 if (!values->
value[i])
95 die(
"failed to enlarge read_values counters arrays");
99 static int perf_read_values__findnew_counter(
struct perf_read_values *values,
104 for (i = 0; i < values->
counters; i++)
109 perf_read_values__enlarge_counters(values);
124 tindex = perf_read_values__findnew_thread(values, pid, tid);
125 cindex = perf_read_values__findnew_counter(values, rawid, name);
130 static void perf_read_values__display_pretty(FILE *
fp,
134 int pidwidth, tidwidth;
139 die(
"failed to allocate counterwidth array");
142 for (j = 0; j < values->
counters; j++)
144 for (i = 0; i < values->
threads; i++) {
148 if (width > pidwidth)
151 if (width > tidwidth)
153 for (j = 0; j < values->
counters; j++) {
155 if (width > counterwidth[j])
160 fprintf(fp,
"# %*s %*s", pidwidth,
"PID", tidwidth,
"TID");
161 for (j = 0; j < values->
counters; j++)
165 for (i = 0; i < values->
threads; i++) {
166 fprintf(fp,
" %*d %*d", pidwidth, values->
pid[i],
167 tidwidth, values->
tid[i]);
168 for (j = 0; j < values->
counters; j++)
170 counterwidth[j], values->
value[i][j]);
176 static void perf_read_values__display_raw(FILE *fp,
179 int width, pidwidth, tidwidth, namewidth, rawwidth, countwidth;
188 for (i = 0; i < values->
threads; i++) {
190 if (width > pidwidth)
193 if (width > tidwidth)
196 for (j = 0; j < values->
counters; j++) {
198 if (width > namewidth)
201 if (width > rawwidth)
204 for (i = 0; i < values->
threads; i++) {
205 for (j = 0; j < values->
counters; j++) {
207 if (width > countwidth)
212 fprintf(fp,
"# %*s %*s %*s %*s %*s\n",
213 pidwidth,
"PID", tidwidth,
"TID",
214 namewidth,
"Name", rawwidth,
"Raw",
215 countwidth,
"Count");
216 for (i = 0; i < values->
threads; i++)
217 for (j = 0; j < values->
counters; j++)
219 pidwidth, values->
pid[i],
220 tidwidth, values->
tid[i],
223 countwidth, values->
value[i][j]);
229 perf_read_values__display_raw(fp, values);
231 perf_read_values__display_pretty(fp, values);