CSV/JSON metric thresholds, fix printf modifiers
Subsystems (2)
Ian Rogers
reviewerv2 cover CSV/JSON metric thresholds, fix printf modifiers
Metric thresholds are being computed for CSV and JSON output but not displayed. Rename the color that encodes the threshold as enum values and use to generate string constants in a CSV column or json dictionary value.
Add printf attribute to functions in color.h that could support it. Fix bad printf format strings that this detected.
v2. Don't display metric-value for json output if there is no unit.
Ian Rogers (6):
perf color: Add printf format checking and resolve issues perf stat: Fix/add parameter names for print_metric perf stat: Display "none" for NaN with metric only json perf stat: Drop metric-unit if unit is NULL
perf stat: Change color to threshold in print_metric perf stat: Display metric threshold value in CSV output
tools/perf/Documentation/perf-stat.txt | 1 + tools/perf/arch/x86/util/iostat.c | 2 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-script.c | 6 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/shell/stat+csv_output.sh | 24 ++-- tools/perf/util/arm-spe.c | 2 +- tools/perf/util/color.h | 9 +- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/s390-cpumsf.c | 2 +- tools/perf/util/s390-sample-raw.c | 6 +- tools/perf/util/stat-display.c | 80 ++++++++++---- tools/perf/util/stat-shadow.c | 128 ++++++++++++---------- tools/perf/util/stat.h | 16 ++- 15 files changed, 174 insertions(+), 110 deletions(-)
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Ian Rogers
reviewerPATCH v2 1/6 perf color: Add printf format checking and resolve issues
Add printf format checking to vararg printf routines in color.h. Resolve build errors/bugs that are found through this checking.
--- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/arm-spe.c | 2 +- tools/perf/util/color.h | 9 +++++---- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/s390-cpumsf.c | 2 +- tools/perf/util/s390-sample-raw.c | 6 +++--- 8 files changed, 14 insertions(+), 13 deletions(-)
tools/perf/builtin-sched.c +1 -1
@@ -1739,7 +1739,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, }if (sched->map.comp && new_cpu) -color_fprintf (stdout, color," (CPU %d)" , this_cpu); +color_fprintf (stdout, color," (CPU %d)" , this_cpu.cpu);if (proceed !=1 ) {color_fprintf (stdout, color,"\n" );
tools/perf/builtin-trace.c +1 -1
@@ -1873,7 +1873,7 @@ static int trace__process_event(struct trace *trace, struct machine *machine,switch (event->header.type) {case PERF_RECORD_LOST :color_fprintf (trace->output,PERF_COLOR_RED , -"LOST %" PRIu64" events!\n" , event->lost.lost); +"LOST %" PRIu64" events!\n" , (u64 )event->lost.lost); ret =machine__process_lost_event (machine, event, sample);break ;default :
tools/perf/util/arm-spe.c +1 -1
@@ -122,7 +122,7 @@ static void arm_spe_dump(struct arm_spe *spe __maybe_unused,else pkt_len =1 ;printf ("." ); -color_fprintf (stdout, color," %08x: " , pos); +color_fprintf (stdout, color," %08zx: " , pos);for (i =0 ; i < pkt_len; i++)color_fprintf (stdout, color," %02x" , buf[i]);for (; i <16 ; i++)
tools/perf/util/color.h +5 -4
@@ -2,6 +2,7 @@#ifndef __PERF_COLOR_H#define __PERF_COLOR_H +#include <linux/compiler.h> #include <stdio.h> #include <stdarg.h>
@@ -37,12 +38,12 @@ int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty)int color_vsnprintf (char *bf,size_t size,const char *color,const char *fmt,va_list args);int color_vfprintf (FILE *fp,const char *color,const char *fmt,va_list args); -int color_fprintf (FILE *fp,const char *color,const char *fmt, ...); -int color_snprintf (char *bf,size_t size,const char *color,const char *fmt, ...); +int color_fprintf(FILE *fp, const char *color, const char *fmt, ...) __printf(3, 4); +int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...) __printf(4, 5);int color_fwrite_lines (FILE *fp,const char *color,size_t count,const char *buf);int value_color_snprintf (char *bf,size_t size,const char *fmt,double value); -int percent_color_snprintf (char *bf,size_t size,const char *fmt, ...); -int percent_color_len_snprintf (char *bf,size_t size,const char *fmt, ...); +int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...) __printf(3, 4); +int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...) __printf(3, 4);int percent_color_fprintf (FILE *fp,const char *fmt,double percent);const char *get_percent_color (double percent);
tools/perf/util/intel-bts.c +1 -1
@@ -100,7 +100,7 @@ static void intel_bts_dump(struct intel_bts *bts __maybe_unused,else sz = len;printf ("." ); -color_fprintf (stdout, color," %08x: " , pos); +color_fprintf (stdout, color," %08zx: " , pos);for (i =0 ; i < sz; i++)color_fprintf (stdout, color," %02x" , buf[i]);for (; i < br_sz; i++)
tools/perf/util/intel-pt.c +1 -1
@@ -249,7 +249,7 @@ static void intel_pt_dump(struct intel_pt *pt __maybe_unused,else pkt_len =1 ;printf ("." ); -color_fprintf (stdout, color," %08x: " , pos); +color_fprintf (stdout, color," %08zx: " , pos);for (i =0 ; i < pkt_len; i++)color_fprintf (stdout, color," %02x" , buf[i]);for (; i <16 ; i++)
tools/perf/util/s390-cpumsf.c +1 -1
@@ -345,7 +345,7 @@ static bool s390_cpumsf_trailer_show(const char *color, size_t pos, } color_fprintf(stdout, color, " [%#08zx] Trailer %c%c%c bsdes:%d" " dsdes:%d Overflow:%lld Time:%#llx\n" - "\t\tC:%d TOD:%#lx\n", + "\t\tC:%d TOD:%#llx\n", pos, te->f ? 'F' : ' ', te->a ? 'A' : ' ',
tools/perf/util/s390-sample-raw.c +3 -3
@@ -98,12 +98,12 @@ static void s390_cpumcfdg_dumptrail(const char *color, size_t offset, te.res2 =be32_to_cpu (tep->res2);color_fprintf (stdout, color," [%#08zx] Trailer:%c%c%c%c%c" -" Cfvn:%d Csvn:%d Speed:%d TOD:%#llx\n" , +" Cfvn:%d Csvn:%d Speed:%d TOD:%#lx\n" , offset, te.clock_base ?'T' :' ' , te.speed ?'S' :' ' , te.mtda ?'M' :' ' , te.caca ?'C' :' ' , te.lcda ?'L' :' ' , te.cfvn, te.csvn, te.cpu_speed, te.timestamp); -color_fprintf (stdout, color,"\t\t1:%lx 2:%lx 3:%lx TOD-Base:%#llx" +color_fprintf (stdout, color,"\t\t1:%lx 2:%lx 3:%lx TOD-Base:%#lx" " Type:%x\n\n" , te.progusage1, te.progusage2, te.progusage3, te.tod_base, te.mach_type);
@@ -205,7 +205,7 @@ static void s390_cpumcfdg_dump(struct perf_pmu *pmu, struct perf_sample *sample)char *ev_name =get_counter_name (ce.set, i, pmu);color_fprintf (stdout, color, -"\tCounter:%03d %s Value:%#018lx\n" , i, +"\tCounter:%03zd %s Value:%#018lx\n" , i, ev_name ?:"<unknown>" ,be64_to_cpu (*p));free (ev_name); }
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Ian Rogers
reviewerPATCH v2 2/6 perf stat: Fix/add parameter names for print_metric
In reply to Ian RogersThe print_metric parameter names were rearranged, fix and add comments in the stat-shadow callers to ensure they are correct.
--- tools/perf/util/stat-shadow.c | 55 ++++++++++++++++++++--------------- tools/perf/util/stat.h | 6 ++-- 2 files changed, 36 insertions(+), 25 deletions(-)
tools/perf/util/stat-shadow.c +32 -23
@@ -195,17 +195,21 @@ static void print_ratio(struct perf_stat_config *config, const struct evsel *evsel, int aggr_idx, double numerator, struct perf_stat_output_ctx *out, enum stat_type denominator_type, - const double color_ratios[3], const char *unit) + const double color_ratios[3], const char *_unit) { double denominator = find_stat(evsel, aggr_idx, denominator_type); +double ratio =0 ; +const char *color =NULL ; +const char *fmt =NULL ; +const char *unit =NULL ;if (numerator && denominator) { -double ratio = numerator / denominator *100.0 ; -const char *color =get_ratio_color (color_ratios, ratio); - - out->print_metric (config, out->ctx, color,"%7.2f%%" , unit, ratio); - }else - out->print_metric (config, out->ctx,NULL ,NULL , unit,0 ); + ratio = numerator / denominator *100.0 ; + color =get_ratio_color (color_ratios, ratio); + fmt ="%7.2f%%" ; + unit = _unit; + } + out->print_metric (config, out->ctx, color, fmt, unit, ratio); } static void print_stalled_cycles_front(struct perf_stat_config *config,
@@ -319,14 +323,15 @@ static void print_instructions(struct perf_stat_config *config, find_stat(evsel, aggr_idx, STAT_STALLED_CYCLES_BACK));if (cycles) { -print_metric (config, ctxp,NULL ,"%7.2f " ,"insn per cycle" , - instructions / cycles); - }else -print_metric (config, ctxp,NULL ,NULL ,"insn per cycle" ,0 ); +print_metric (config, ctxp,/*color=*/ NULL ,"%7.2f " ,"insn per cycle" , + instructions / cycles); + }else { +print_metric (config, ctxp,/*color=*/ NULL ,/*fmt=*/ NULL ,"insn per cycle" ,0 ); + }if (max_stalled && instructions) { out->new_line (config, ctxp); -print_metric (config, ctxp,NULL ,"%7.2f " ,"stalled cycles per insn" , +print_metric (config, ctxp,/*color=*/ NULL ,"%7.2f " ,"stalled cycles per insn" , max_stalled / instructions); } }
@@ -341,9 +346,10 @@ static void print_cycles(struct perf_stat_config *config,if (cycles && nsecs) {double ratio = cycles / nsecs; - out->print_metric (config, out->ctx,NULL ,"%8.3f" ,"GHz" , ratio); - }else - out->print_metric (config, out->ctx,NULL ,NULL ,"GHz" ,0 ); + out->print_metric (config, out->ctx,/*color=*/ NULL ,"%8.3f" ,"GHz" , ratio); + }else { + out->print_metric (config, out->ctx,/*color=*/ NULL ,/*fmt=*/ NULL ,"GHz" ,0 ); + } } static void print_nsecs(struct perf_stat_config *config,
@@ -356,10 +362,11 @@ static void print_nsecs(struct perf_stat_config *config,double wall_time =avg_stats (&walltime_nsecs_stats);if (wall_time) { -print_metric (config, ctxp,NULL ,"%8.3f" ,"CPUs utilized" , +print_metric (config, ctxp,/*color=*/ NULL ,"%8.3f" ,"CPUs utilized" , nsecs / (wall_time * evsel->scale)); - }else -print_metric (config, ctxp,NULL ,NULL ,"CPUs utilized" ,0 ); + }else { +print_metric (config, ctxp,/*color=*/ NULL ,/*fmt=*/ NULL ,"CPUs utilized" ,0 ); + } } static int prepare_metric(const struct metric_expr *mexp,
@@ -532,12 +539,12 @@ static void generic_metric(struct perf_stat_config *config, ratio); } }else { -print_metric (config, ctxp, color,/*unit=*/ NULL , +print_metric (config, ctxp, color,/*fmt=*/ NULL , out->force_header ? (metric_name ?: evsel->name) :"" ,0 ); } }else { -print_metric (config, ctxp, color,/*unit=*/ NULL , +print_metric (config, ctxp, color,/*fmt=*/ NULL , out->force_header ? (metric_name ?: evsel->name) :"" ,0 ); }
@@ -708,9 +715,11 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config,if (unit !=' ' )snprintf (unit_buf,sizeof (unit_buf),"%c/sec" , unit); -print_metric (config, ctxp,NULL ,"%8.3f" , unit_buf, ratio); - }else +print_metric (config, ctxp,/*color=*/ NULL ,"%8.3f" , + unit_buf, ratio); + }else { num =0 ; + } } }
@@ -718,7 +727,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, &num, NULL, out, metric_events);if (num ==0 ) -print_metric (config, ctxp,NULL ,NULL ,NULL ,0 ); +print_metric (config, ctxp,/*color=*/ NULL ,/*fmt=*/ NULL ,/*unit=*/ NULL ,0 ); }/**
tools/perf/util/stat.h +4 -2
@@ -155,8 +155,10 @@ extern struct stats walltime_nsecs_stats;extern struct rusage_stats ru_stats;typedef void (*print_metric_t )(struct perf_stat_config *config, -void *ctx,const char *color,const char *unit, -const char *fmt,double val); +void *ctx,const char *color, +const char *fmt, +const char *unit, +double val);typedef void (*new_line_t )(struct perf_stat_config *config,void *ctx);/* Used to print the display name of the Default metricgroup for now. */
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Ian Rogers
reviewerPATCH v2 3/6 perf stat: Display "none" for NaN with metric only json
In reply to Ian RogersReturn earlier for an empty unit case. If snprintf of the fmt doesn't produce digits between vals and ends, as happens with NaN, make the value "none" as happens in print_metric_end.
--- tools/perf/util/stat-display.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
tools/perf/util/stat-display.c +7 -4
@@ -609,19 +609,22 @@ static void print_metric_only_json(struct perf_stat_config *config __maybe_unuse {struct outstate *os = ctx;FILE *out = os->fh; -char buf[64 ], *vals, *ends; +char buf[64 ], *ends;char tbuf[1024 ]; +const char *vals;if (!valid_only_metric (unit))return ; unit =fixunit (tbuf, os->evsel, unit); +if (!unit[0 ]) +return ;snprintf (buf,sizeof (buf), fmt ?:"" , val); - ends = vals =skip_spaces (buf); + vals = ends =skip_spaces (buf);while (isdigit (*ends) || *ends =='.' ) ends++; *ends =0 ; -if (!unit[0 ] || !vals[0 ]) -return ; +if (!vals[0 ]) + vals ="none" ;fprintf (out,"%s\"%s\" : \"%s\"" , os->first ?"" :", " , unit, vals); os->first = false; }
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Ian Rogers
reviewerPATCH v2 4/6 perf stat: Drop metric-unit if unit is NULL
In reply to Ian RogersAvoid cases like:
```
$ perf stat -a -M topdownl1 -j -I 1000
...
{"interval" : 11.127757275, "counter-value" : "85715898.000000", "unit" : "", "event" : "IDQ.MITE_UOPS", "event-runtime" : 988376123, "pcnt-running" : 100.00, "metric-value" : "0.000000", "metric-unit" : "(null)"}
...
```If there is no unit then drop the metric-value too as:
--- tools/perf/util/stat-display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/stat-display.c +2 -2
@@ -470,8 +470,8 @@ static void print_metric_json(struct perf_stat_config *config __maybe_unused,struct outstate *os = ctx;FILE *out = os->fh; -fprintf (out,"\"metric-value\" : \"%f\", " , val); -fprintf (out,"\"metric-unit\" : \"%s\"" , unit); +if (unit) +fprintf (out,"\"metric-value\" : \"%f\", \"metric-unit\" : \"%s\"" , val, unit);if (!config->metric_only)fprintf (out,"}" ); }
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Ian Rogers
reviewerPATCH v2 5/6 perf stat: Change color to threshold in print_metric
In reply to Ian RogersColors don't mean things in CSV and JSON output, switch to a threshold enum value that the standard output can convert to a color. Updating the CSV and JSON output will be later changes.
--- tools/perf/arch/x86/util/iostat.c | 2 +- tools/perf/builtin-script.c | 6 +- tools/perf/util/stat-display.c | 40 ++++++++---- tools/perf/util/stat-shadow.c | 105 +++++++++++++++--------------- tools/perf/util/stat.h | 12 +++- 5 files changed, 97 insertions(+), 68 deletions(-)
tools/perf/arch/x86/util/iostat.c +1 -1
@@ -444,7 +444,7 @@ void iostat_print_metric(struct perf_stat_config *config, struct evsel *evsel, iostat_value = (count->val - prev_count_val) / ((double ) count->run / count->ena); } - out->print_metric (config, out->ctx,NULL ,"%8.0f" , iostat_metric, + out->print_metric (config, out->ctx,METRIC_THRESHOLD_UNKNOWN ,"%8.0f" , iostat_metric, iostat_value / (256 *1024 )); }
tools/perf/builtin-script.c +3 -3
@@ -2136,11 +2136,11 @@ struct metric_ctx { };static void script_print_metric (struct perf_stat_config *config__maybe_unused , -void *ctx,const char *color, -const char *fmt, -const char *unit,double val) +void *ctx,enum metric_threshold_classify thresh, +const char *fmt,const char *unit,double val) {struct metric_ctx *mctx = ctx; +const char *color =metric_threshold_classify__color (thresh);if (!fmt)return ;
tools/perf/util/stat-display.c +29 -11
@@ -72,6 +72,19 @@ static const char *aggr_header_std[] = { [AGGR_GLOBAL ] ="" }; +const char *metric_threshold_classify__color (enum metric_threshold_classify thresh) +{ +const char *const colors[] = { +"" ,/* unknown */ +PERF_COLOR_RED ,/* bad */ +PERF_COLOR_MAGENTA ,/* nearly bad */ +PERF_COLOR_YELLOW ,/* less good */ +PERF_COLOR_GREEN ,/* good */ + }; +static_assert (ARRAY_SIZE (colors) -1 ==METRIC_THRESHOLD_GOOD ,"missing enum value" ); +return colors[thresh]; +} +static void print_running_std (struct perf_stat_config *config,u64 run,u64 ena) {if (run != ena)
@@ -404,13 +417,14 @@ static void do_new_line_std(struct perf_stat_config *config, }static void print_metric_std (struct perf_stat_config *config, -void *ctx,const char *color,const char *fmt, -const char *unit,double val) +void *ctx,enum metric_threshold_classify thresh, +const char *fmt,const char *unit,double val) {struct outstate *os = ctx;FILE *out = os->fh;int n;bool newline = os->newline; +const char *color =metric_threshold_classify__color (thresh); os->newline = false;
@@ -442,7 +456,7 @@ static void new_line_csv(struct perf_stat_config *config, void *ctx)static void print_metric_csv (struct perf_stat_config *config__maybe_unused ,void *ctx, -const char *color__maybe_unused , +enum metric_threshold_classify thresh__maybe_unused ,const char *fmt,const char *unit,double val) {struct outstate *os = ctx;
@@ -463,7 +477,7 @@ static void print_metric_csv(struct perf_stat_config *config __maybe_unused,static void print_metric_json (struct perf_stat_config *config__maybe_unused ,void *ctx, -const char *color__maybe_unused , +enum metric_threshold_classify thresh__maybe_unused ,const char *fmt__maybe_unused ,const char *unit,double val) {
@@ -558,13 +572,14 @@ static const char *fixunit(char *buf, struct evsel *evsel, }static void print_metric_only (struct perf_stat_config *config, -void *ctx,const char *color,const char *fmt, -const char *unit,double val) +void *ctx,enum metric_threshold_classify thresh, +const char *fmt,const char *unit,double val) {struct outstate *os = ctx;FILE *out = os->fh;char buf[1024 ], str[1024 ];unsigned mlen = config->metric_only_len; +const char *color =metric_threshold_classify__color (thresh);if (!valid_only_metric (unit))return ;
@@ -581,7 +596,8 @@ static void print_metric_only(struct perf_stat_config *config, }static void print_metric_only_csv (struct perf_stat_config *config__maybe_unused , -void *ctx,const char *color__maybe_unused , +void *ctx, +enum metric_threshold_classify thresh__maybe_unused ,const char *fmt,const char *unit,double val) {
@@ -603,7 +619,8 @@ static void print_metric_only_csv(struct perf_stat_config *config __maybe_unused }static void print_metric_only_json (struct perf_stat_config *config__maybe_unused , -void *ctx,const char *color__maybe_unused , +void *ctx, +enum metric_threshold_classify thresh__maybe_unused ,const char *fmt,const char *unit,double val) {
@@ -635,7 +652,8 @@ static void new_line_metric(struct perf_stat_config *config __maybe_unused, }static void print_metric_header (struct perf_stat_config *config, -void *ctx,const char *color__maybe_unused , +void *ctx, +enum metric_threshold_classify thresh__maybe_unused ,const char *fmt__maybe_unused ,const char *unit,double val__maybe_unused ) {
@@ -809,7 +827,7 @@ static void printout(struct perf_stat_config *config, struct outstate *os,if (run ==0 || ena ==0 || counter->counts->scaled ==-1 ) {if (config->metric_only) { -pm (config, os,NULL ,"" ,"" ,0 ); +pm (config, os,METRIC_THRESHOLD_UNKNOWN ,"" ,"" ,0 );return ; }
@@ -864,7 +882,7 @@ static void printout(struct perf_stat_config *config, struct outstate *os,perf_stat__print_shadow_stats (config, counter, uval, aggr_idx, &out, &config->metric_events); }else { -pm (config, os,/*color=*/ NULL ,/*format=*/ NULL ,/*unit=*/ "" ,/*val=*/ 0 ); +pm (config, os,METRIC_THRESHOLD_UNKNOWN ,/*format=*/ NULL ,/*unit=*/ "" ,/*val=*/ 0 ); }if (!config->metric_only) {
tools/perf/util/stat-shadow.c +53 -52
260 lines not on this page · raw message
tools/perf/util/stat.h +11 -1
@@ -154,8 +154,18 @@ struct evlist;extern struct stats walltime_nsecs_stats;extern struct rusage_stats ru_stats; +enum metric_threshold_classify { +METRIC_THRESHOLD_UNKNOWN , +METRIC_THRESHOLD_BAD , +METRIC_THRESHOLD_NEARLY_BAD , +METRIC_THRESHOLD_LESS_GOOD , +METRIC_THRESHOLD_GOOD , +}; +const char *metric_threshold_classify__color (enum metric_threshold_classify thresh); +typedef void (*print_metric_t )(struct perf_stat_config *config, -void *ctx,const char *color, +void *ctx, +enum metric_threshold_classify thresh,const char *fmt,const char *unit,double val);
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Ian Rogers
reviewerPATCH v2 6/6 perf stat: Display metric threshold value in CSV output
In reply to Ian RogersAdd a column with a metric threshold value. For example, the bad/good in the last column below:
``` $ perf stat -a -M topdownl1 -x, -I 1000 1.000103288,4677067630,,TOPDOWN.SLOTS,16029302700,100.00,31.1,% tma_backend_bound,bad 1.000103288,,,,,,51.0,% tma_frontend_bound,bad 1.000103288,,,,,,7.6,% tma_bad_speculation,good 1.000103288,,,,,,10.2,% tma_retiring,good 1.000103288,476781750,,topdown-retiring,16029302700,100.00,, 1.000103288,2389693619,,topdown-fe-bound,16029302700,100.00,, 1.000103288,1431602465,,topdown-be-bound,16029302700,100.00,, 1.000103288,378991388,,topdown-bad-spec,16029302700,100.00,, 1.000103288,4934535,,INT_MISC.CLEARS_COUNT,16029339890,100.00,, 1.000103288,56474476,,IDQ.MS_UOPS,16029292873,100.00,, 1.000103288,3188888,,INT_MISC.UOP_DROPPING,16029239908,100.00,, 1.000103288,484429099,,UOPS_RETIRED.SLOTS,16029176080,100.00,, 1.000103288,49066178,,UOPS_DECODED.DEC0,16029100912,100.00,, 1.000103288,26472844,,cpu/UOPS_DECODED.DEC0,cmask=1/,16029009707,100.00,, 1.000103288,709313662,,UOPS_ISSUED.ANY,16028914990,100.00,, 1.000103288,346833383,,IDQ.MITE_UOPS,16028820330,100.00,, ```
--- tools/perf/Documentation/perf-stat.txt | 1 + tools/perf/tests/shell/stat+csv_output.sh | 24 ++++++++++---------- tools/perf/util/stat-display.c | 27 +++++++++++++++++++---- 3 files changed, 36 insertions(+), 16 deletions(-)
tools/perf/Documentation/perf-stat.txt +1 -0
@@ -622,6 +622,7 @@ The fields are in this order: - optional variance if multiple values are collected with -r - optional metric value - optional unit of metric + - optional how the value relates to a metric threshold Additional metrics may be printed with all earlier fields being empty.
tools/perf/tests/shell/stat+csv_output.sh +12 -12
@@ -31,19 +31,19 @@ function commachecker() local exp=0 case "$1" - in "--no-args") exp=6 - ;; "--system-wide") exp=6 - ;; "--event") exp=6 - ;; "--interval") exp=7 + in "--no-args") exp=7 + ;; "--system-wide") exp=7 + ;; "--event") exp=7 + ;; "--interval") exp=8 ;; "--per-thread") exp=7 - ;; "--system-wide-no-aggr") exp=7 - [ "$(uname -m)" = "s390x" ] && exp='^[6-7]$' - ;; "--per-core") exp=8 - ;; "--per-socket") exp=8 - ;; "--per-node") exp=8 - ;; "--per-die") exp=8 - ;; "--per-cluster") exp=8 - ;; "--per-cache") exp=8 + ;; "--system-wide-no-aggr") exp=8 + [ "$(uname -m)" = "s390x" ] && exp='^[7-8]$' + ;; "--per-core") exp=9 + ;; "--per-socket") exp=9 + ;; "--per-node") exp=9 + ;; "--per-die") exp=9 + ;; "--per-cluster") exp=9 + ;; "--per-cache") exp=9 esac while read line
tools/perf/util/stat-display.c +23 -4
@@ -85,6 +85,19 @@ const char *metric_threshold_classify__color(enum metric_threshold_classify threreturn colors[thresh]; } +static const char *metric_threshold_classify__str (enum metric_threshold_classify thresh) +{ +const char *const strs[] = { +"unknown" , +"bad" , +"nearly bad" , +"less good" , +"good" , + }; +static_assert (ARRAY_SIZE (strs) -1 ==METRIC_THRESHOLD_GOOD ,"missing enum value" ); +return strs[thresh]; +} +static void print_running_std (struct perf_stat_config *config,u64 run,u64 ena) {if (run != ena)
@@ -454,14 +467,15 @@ static void new_line_csv(struct perf_stat_config *config, void *ctx)fputs (config->csv_sep, os->fh); } -static void print_metric_csv (struct perf_stat_config *config__maybe_unused , +static void print_metric_csv (struct perf_stat_config *config,void *ctx, -enum metric_threshold_classify thresh__maybe_unused , +enum metric_threshold_classify thresh,const char *fmt,const char *unit,double val) {struct outstate *os = ctx;FILE *out = os->fh;char buf[64 ], *vals, *ends; +const char *thresh_str ="" ;if (unit ==NULL || fmt ==NULL ) {fprintf (out,"%s%s" , config->csv_sep, config->csv_sep);
@@ -472,7 +486,12 @@ static void print_metric_csv(struct perf_stat_config *config __maybe_unused,while (isdigit (*ends) || *ends =='.' ) ends++; *ends =0 ; -fprintf (out,"%s%s%s%s" , config->csv_sep, vals, config->csv_sep,skip_spaces (unit)); +if (thresh !=METRIC_THRESHOLD_UNKNOWN || !rblist__empty (&config->metric_events)) + thresh_str =metric_threshold_classify__str (thresh); +fprintf (out,"%s%s%s%s%s%s" , + config->csv_sep, vals, + config->csv_sep,skip_spaces (unit), + config->csv_sep, thresh_str); } static void print_metric_json(struct perf_stat_config *config __maybe_unused,
@@ -527,7 +546,7 @@ static void print_metricgroup_header_csv(struct perf_stat_config *config,for (i =0 ; i < os->nfields; i++)fputs (config->csv_sep, os->fh); -fprintf (config->output,"%s" , metricgroup_name); +fprintf (config->output,"%s%s" , metricgroup_name, config->csv_sep);new_line_csv (config, ctx); }
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog