Lines Matching full:values
9 #include "values.h"
12 int perf_read_values_init(struct perf_read_values *values) in perf_read_values_init() argument
14 values->threads_max = 16; in perf_read_values_init()
15 values->pid = malloc(values->threads_max * sizeof(*values->pid)); in perf_read_values_init()
16 values->tid = malloc(values->threads_max * sizeof(*values->tid)); in perf_read_values_init()
17 values->value = zalloc(values->threads_max * sizeof(*values->value)); in perf_read_values_init()
18 if (!values->pid || !values->tid || !values->value) { in perf_read_values_init()
22 values->threads = 0; in perf_read_values_init()
24 values->counters_max = 16; in perf_read_values_init()
25 values->counterrawid = malloc(values->counters_max in perf_read_values_init()
26 * sizeof(*values->counterrawid)); in perf_read_values_init()
27 values->countername = malloc(values->counters_max in perf_read_values_init()
28 * sizeof(*values->countername)); in perf_read_values_init()
29 if (!values->counterrawid || !values->countername) { in perf_read_values_init()
33 values->counters = 0; in perf_read_values_init()
38 zfree(&values->counterrawid); in perf_read_values_init()
39 zfree(&values->countername); in perf_read_values_init()
41 zfree(&values->pid); in perf_read_values_init()
42 zfree(&values->tid); in perf_read_values_init()
43 zfree(&values->value); in perf_read_values_init()
47 void perf_read_values_destroy(struct perf_read_values *values) in perf_read_values_destroy() argument
51 if (!values->threads_max || !values->counters_max) in perf_read_values_destroy()
54 for (i = 0; i < values->threads; i++) in perf_read_values_destroy()
55 zfree(&values->value[i]); in perf_read_values_destroy()
56 zfree(&values->value); in perf_read_values_destroy()
57 zfree(&values->pid); in perf_read_values_destroy()
58 zfree(&values->tid); in perf_read_values_destroy()
59 zfree(&values->counterrawid); in perf_read_values_destroy()
60 for (i = 0; i < values->counters; i++) in perf_read_values_destroy()
61 zfree(&values->countername[i]); in perf_read_values_destroy()
62 zfree(&values->countername); in perf_read_values_destroy()
65 static int perf_read_values__enlarge_threads(struct perf_read_values *values) in perf_read_values__enlarge_threads() argument
67 int nthreads_max = values->threads_max * 2; in perf_read_values__enlarge_threads()
68 void *npid = realloc(values->pid, nthreads_max * sizeof(*values->pid)), in perf_read_values__enlarge_threads()
69 *ntid = realloc(values->tid, nthreads_max * sizeof(*values->tid)), in perf_read_values__enlarge_threads()
70 *nvalue = realloc(values->value, nthreads_max * sizeof(*values->value)); in perf_read_values__enlarge_threads()
75 values->threads_max = nthreads_max; in perf_read_values__enlarge_threads()
76 values->pid = npid; in perf_read_values__enlarge_threads()
77 values->tid = ntid; in perf_read_values__enlarge_threads()
78 values->value = nvalue; in perf_read_values__enlarge_threads()
88 static int perf_read_values__findnew_thread(struct perf_read_values *values, in perf_read_values__findnew_thread() argument
93 for (i = 0; i < values->threads; i++) in perf_read_values__findnew_thread()
94 if (values->pid[i] == pid && values->tid[i] == tid) in perf_read_values__findnew_thread()
97 if (values->threads == values->threads_max) { in perf_read_values__findnew_thread()
98 i = perf_read_values__enlarge_threads(values); in perf_read_values__findnew_thread()
103 i = values->threads; in perf_read_values__findnew_thread()
105 values->value[i] = zalloc(values->counters_max * sizeof(**values->value)); in perf_read_values__findnew_thread()
106 if (!values->value[i]) { in perf_read_values__findnew_thread()
110 values->pid[i] = pid; in perf_read_values__findnew_thread()
111 values->tid[i] = tid; in perf_read_values__findnew_thread()
112 values->threads = i + 1; in perf_read_values__findnew_thread()
117 static int perf_read_values__enlarge_counters(struct perf_read_values *values) in perf_read_values__enlarge_counters() argument
120 int i, counters_max = values->counters_max * 2; in perf_read_values__enlarge_counters()
121 u64 *counterrawid = realloc(values->counterrawid, counters_max * sizeof(*values->counterrawid)); in perf_read_values__enlarge_counters()
128 countername = realloc(values->countername, counters_max * sizeof(*values->countername)); in perf_read_values__enlarge_counters()
134 for (i = 0; i < values->threads; i++) { in perf_read_values__enlarge_counters()
135 u64 *value = realloc(values->value[i], counters_max * sizeof(**values->value)); in perf_read_values__enlarge_counters()
139 pr_debug("failed to enlarge read_values ->values array"); in perf_read_values__enlarge_counters()
143 for (j = values->counters_max; j < counters_max; j++) in perf_read_values__enlarge_counters()
146 values->value[i] = value; in perf_read_values__enlarge_counters()
149 values->counters_max = counters_max; in perf_read_values__enlarge_counters()
150 values->counterrawid = counterrawid; in perf_read_values__enlarge_counters()
151 values->countername = countername; in perf_read_values__enlarge_counters()
162 static int perf_read_values__findnew_counter(struct perf_read_values *values, in perf_read_values__findnew_counter() argument
167 for (i = 0; i < values->counters; i++) in perf_read_values__findnew_counter()
168 if (values->counterrawid[i] == rawid) in perf_read_values__findnew_counter()
171 if (values->counters == values->counters_max) { in perf_read_values__findnew_counter()
172 i = perf_read_values__enlarge_counters(values); in perf_read_values__findnew_counter()
177 i = values->counters++; in perf_read_values__findnew_counter()
178 values->counterrawid[i] = rawid; in perf_read_values__findnew_counter()
179 values->countername[i] = strdup(name); in perf_read_values__findnew_counter()
184 int perf_read_values_add_value(struct perf_read_values *values, in perf_read_values_add_value() argument
190 tindex = perf_read_values__findnew_thread(values, pid, tid); in perf_read_values_add_value()
193 cindex = perf_read_values__findnew_counter(values, rawid, name); in perf_read_values_add_value()
197 values->value[tindex][cindex] += value; in perf_read_values_add_value()
202 struct perf_read_values *values) in perf_read_values__display_pretty() argument
208 counterwidth = malloc(values->counters * sizeof(*counterwidth)); in perf_read_values__display_pretty()
215 for (j = 0; j < values->counters; j++) in perf_read_values__display_pretty()
216 counterwidth[j] = strlen(values->countername[j]); in perf_read_values__display_pretty()
217 for (i = 0; i < values->threads; i++) { in perf_read_values__display_pretty()
220 width = snprintf(NULL, 0, "%d", values->pid[i]); in perf_read_values__display_pretty()
223 width = snprintf(NULL, 0, "%d", values->tid[i]); in perf_read_values__display_pretty()
226 for (j = 0; j < values->counters; j++) { in perf_read_values__display_pretty()
227 width = snprintf(NULL, 0, "%" PRIu64, values->value[i][j]); in perf_read_values__display_pretty()
234 for (j = 0; j < values->counters; j++) in perf_read_values__display_pretty()
235 fprintf(fp, " %*s", counterwidth[j], values->countername[j]); in perf_read_values__display_pretty()
238 for (i = 0; i < values->threads; i++) { in perf_read_values__display_pretty()
239 fprintf(fp, " %*d %*d", pidwidth, values->pid[i], in perf_read_values__display_pretty()
240 tidwidth, values->tid[i]); in perf_read_values__display_pretty()
241 for (j = 0; j < values->counters; j++) in perf_read_values__display_pretty()
243 counterwidth[j], values->value[i][j]); in perf_read_values__display_pretty()
250 struct perf_read_values *values) in perf_read_values__display_raw() argument
261 for (i = 0; i < values->threads; i++) { in perf_read_values__display_raw()
262 width = snprintf(NULL, 0, "%d", values->pid[i]); in perf_read_values__display_raw()
265 width = snprintf(NULL, 0, "%d", values->tid[i]); in perf_read_values__display_raw()
269 for (j = 0; j < values->counters; j++) { in perf_read_values__display_raw()
270 width = strlen(values->countername[j]); in perf_read_values__display_raw()
273 width = snprintf(NULL, 0, "%" PRIx64, values->counterrawid[j]); in perf_read_values__display_raw()
277 for (i = 0; i < values->threads; i++) { in perf_read_values__display_raw()
278 for (j = 0; j < values->counters; j++) { in perf_read_values__display_raw()
279 width = snprintf(NULL, 0, "%" PRIu64, values->value[i][j]); in perf_read_values__display_raw()
289 for (i = 0; i < values->threads; i++) in perf_read_values__display_raw()
290 for (j = 0; j < values->counters; j++) in perf_read_values__display_raw()
292 pidwidth, values->pid[i], in perf_read_values__display_raw()
293 tidwidth, values->tid[i], in perf_read_values__display_raw()
294 namewidth, values->countername[j], in perf_read_values__display_raw()
295 rawwidth, values->counterrawid[j], in perf_read_values__display_raw()
296 countwidth, values->value[i][j]); in perf_read_values__display_raw()
299 void perf_read_values_display(FILE *fp, struct perf_read_values *values, int raw) in perf_read_values_display() argument
302 perf_read_values__display_raw(fp, values); in perf_read_values_display()
304 perf_read_values__display_pretty(fp, values); in perf_read_values_display()