Re: [PATCH v3 3/5] perf c2c: Refactor display filter

From: Joe Perches
Date: Thu Jan 14 2021 - 02:36:09 EST


On Thu, 2021-01-14 at 11:39 +0800, Leo Yan wrote:
> When sort on the respective metrics (lcl_hitm, rmt_hitm, tot_hitm),
> macro FILTER_HITM is to filter out the cache line entries if its
> overhead is less than 1%.
>
> This patch introduces static function filter_display() to replace macro;
> and refines its parameter with more flexbile way, rather than passing
> field name, it changes to pass the cache line's statistic value and the
> sum value.
[]
> diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
[]
> +static u8 filter_display(u32 val, u32 sum)
> +{
> + double ld_dist;
> +
> + if (sum) {
> + ld_dist = ((double)(val) / (sum));
> + if (ld_dist < DISPLAY_LINE_LIMIT)
> + return HIST_FILTER__C2C;
> + } else {
> + return HIST_FILTER__C2C;
> + }
> +
> + return 0;
> +}

style:

It's generally better to test and return early and unindent the remainder.
Also, parentheses aren't necessary around now not-macro args.

{
if (sum == 0 || ((double)val / sum) < DISPLAY_LINE_LIMIT)
return HIST_FILTER__C2C;

return 0;
}