aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/values.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/values.c')
-rw-r--r--tools/perf/util/values.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c
index 8551c0b8b233..614cfaf4712a 100644
--- a/tools/perf/util/values.c
+++ b/tools/perf/util/values.c
@@ -126,7 +126,8 @@ void perf_read_values_add_value(struct perf_read_values *values,
126 values->value[tindex][cindex] = value; 126 values->value[tindex][cindex] = value;
127} 127}
128 128
129void perf_read_values_display(FILE *fp, struct perf_read_values *values) 129static void perf_read_values__display_pretty(FILE *fp,
130 struct perf_read_values *values)
130{ 131{
131 int i, j; 132 int i, j;
132 int pidwidth, tidwidth; 133 int pidwidth, tidwidth;
@@ -169,3 +170,62 @@ void perf_read_values_display(FILE *fp, struct perf_read_values *values)
169 fprintf(fp, "\n"); 170 fprintf(fp, "\n");
170 } 171 }
171} 172}
173
174static void perf_read_values__display_raw(FILE *fp,
175 struct perf_read_values *values)
176{
177 int width, pidwidth, tidwidth, namewidth, rawwidth, countwidth;
178 int i, j;
179
180 tidwidth = 3; /* TID */
181 pidwidth = 3; /* PID */
182 namewidth = 4; /* "Name" */
183 rawwidth = 3; /* "Raw" */
184 countwidth = 5; /* "Count" */
185
186 for (i = 0; i < values->threads; i++) {
187 width = snprintf(NULL, 0, "%d", values->pid[i]);
188 if (width > pidwidth)
189 pidwidth = width;
190 width = snprintf(NULL, 0, "%d", values->tid[i]);
191 if (width > tidwidth)
192 tidwidth = width;
193 }
194 for (j = 0; j < values->counters; j++) {
195 width = strlen(values->countername[j]);
196 if (width > namewidth)
197 namewidth = width;
198 width = snprintf(NULL, 0, "%llx", values->counterrawid[j]);
199 if (width > rawwidth)
200 rawwidth = width;
201 }
202 for (i = 0; i < values->threads; i++) {
203 for (j = 0; j < values->counters; j++) {
204 width = snprintf(NULL, 0, "%Lu", values->value[i][j]);
205 if (width > countwidth)
206 countwidth = width;
207 }
208 }
209
210 fprintf(fp, "# %*s %*s %*s %*s %*s\n",
211 pidwidth, "PID", tidwidth, "TID",
212 namewidth, "Name", rawwidth, "Raw",
213 countwidth, "Count");
214 for (i = 0; i < values->threads; i++)
215 for (j = 0; j < values->counters; j++)
216 fprintf(fp, " %*d %*d %*s %*llx %*Lu\n",
217 pidwidth, values->pid[i],
218 tidwidth, values->tid[i],
219 namewidth, values->countername[j],
220 rawwidth, values->counterrawid[j],
221 countwidth, values->value[i][j]);
222}
223
224void perf_read_values_display(FILE *fp, struct perf_read_values *values,
225 int raw)
226{
227 if (raw)
228 perf_read_values__display_raw(fp, values);
229 else
230 perf_read_values__display_pretty(fp, values);
231}