2014-04-08 07:09:08

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH 04/15 V3] perf c2c: Dump raw records, decode data_src bits

On Mon, 24 Mar 2014 15:36:55 -0400, Don Zickus wrote:
> + union perf_mem_data_src dsrc = { .val = val, };
> + int printed = scnprintf(bf, size, PREFIX);
> + size_t i;
> + bool first_present = true;
> +
> + for (i = 0; i < ARRAY_SIZE(decode_bits); i++) {
> + int bitval;
> +
> + switch (decode_bits[i].field) {
> + case OP: bitval = decode_bits[i].bit & dsrc.mem_op; break;
> + case LVL: bitval = decode_bits[i].bit & dsrc.mem_lvl; break;
> + case SNP: bitval = decode_bits[i].bit & dsrc.mem_snoop; break;
> + case LCK: bitval = decode_bits[i].bit & dsrc.mem_lock; break;
> + case TLB: bitval = decode_bits[i].bit & dsrc.mem_dtlb; break;
> + default: bitval = 0; break;
> + }
> +
> + if (!bitval)
> + continue;
> +
> + if (strlen(decode_bits[i].name) + !!i > size - printed - sizeof(SUFFIX)) {
> + sprintf(bf + size - sizeof(SUFFIX) - sizeof(ELLIPSIS) + 1, ELLIPSIS);
> + printed = size - sizeof(SUFFIX);
> + break;
> + }
> +
> + printed += scnprintf(bf + printed, size - printed, "%s%s",
> + first_present ? "" : ",", decode_bits[i].name);
> + first_present = false;
> + }
> +
> + printed += scnprintf(bf + printed, size - printed, SUFFIX);

It seems that adjusting bf and size as printed might make the code
somewhat simpler and readable - i.e.:

ret = scnprintf(bf, size, "%s", ...);

bf += ret;
size -= ret;
printed += ret;


> + return printed;
> }
>
> -static int perf_c2c__process_load(struct perf_evsel *evsel,
> - struct perf_sample *sample,
> - struct addr_location *al)
> +static int perf_c2c__fprintf_header(FILE *fp)
> {
> - perf_sample__fprintf(sample, evsel, al, stdout);
> - return 0;
> + int printed = fprintf(fp, "%c %-16s %6s %6s %4s %18s %18s %18s %6s %-10s %-60s %s\n",
> + 'T',
> + "Status",
> + "Pid",
> + "Tid",
> + "CPU",
> + "Inst Adrs",
> + "Virt Data Adrs",
> + "Phys Data Adrs",
> + "Cycles",
> + "Source",
> + " Decoded Source",
> + "ObJect:Symbol");

s/ObJect/Object/ ?

Thanks,
Namhyung


> + return printed + fprintf(fp, "%-*.*s\n", printed, printed, graph_dotted_line);
> +}