Skip to content

Commit

Permalink
perf stat: Micro-optimize the code: memcpy is only required if no eve…
Browse files Browse the repository at this point in the history
…nt is selected and !null_run

Set attrs and nr_counters if no event is selected and !null_run.

Setting of attrs should depend on number of counters,
so we need to memcpy only for sizeof(default_attrs)

Also set nr_counters as ARRAY_SIZE(default_attrs) in place of
hardcoded value.

Signed-off-by: Jaswinder Singh Rajput <jaswinderrajput@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1246126749.32198.16.camel@hpdv5.satnam>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Jaswinder Singh Rajput authored and Ingo Molnar committed Jun 28, 2009
1 parent 6e750a8 commit c304356
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include <sys/prctl.h>
#include <math.h>

static struct perf_counter_attr default_attrs[MAX_COUNTERS] = {
static struct perf_counter_attr default_attrs[] = {

{ .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK },
{ .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES},
Expand Down Expand Up @@ -477,16 +477,17 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
{
int status;

memcpy(attrs, default_attrs, sizeof(attrs));

argc = parse_options(argc, argv, options, stat_usage, 0);
if (!argc)
usage_with_options(stat_usage, options);
if (run_count <= 0 || run_count > MAX_RUN)
usage_with_options(stat_usage, options);

if (!null_run && !nr_counters)
nr_counters = 8;
/* Set attrs and nr_counters if no event is selected and !null_run */
if (!null_run && !nr_counters) {
memcpy(attrs, default_attrs, sizeof(default_attrs));
nr_counters = ARRAY_SIZE(default_attrs);
}

nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
assert(nr_cpus <= MAX_NR_CPUS);
Expand Down

0 comments on commit c304356

Please sign in to comment.