Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp68659imm; Wed, 5 Sep 2018 15:08:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaZilDBYq7YgE0QPC0PRZ/9Ln2f7RmktFi1v3DRoaTbQFDwx1QxrJWczG0uoslqknrhFRjx X-Received: by 2002:a63:e14a:: with SMTP id h10-v6mr38325945pgk.358.1536185305912; Wed, 05 Sep 2018 15:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536185305; cv=none; d=google.com; s=arc-20160816; b=Y+rJct+YDLZ7oxVUPA3TqKGYJA9sCz6WozFUHp+zwC5P9MvIRKTm5YBbiNSbMvgdFc A5ngZ/qnrI2XZBL5q6qMffVpNU+ZNUtVdqC/3/5idbVTdPkWt/BafD7Gvf41vLqPJSZ6 iCd2yHUp1yL8yZ0FgVrYioQfpZ0FiHqIOlrcEA1z/2wA7B1OQqBJqE6r3uxLYbvUhHKe OITXpMyv5WE0jYwmMTG+QAD8daOzmO2Hv2uH1UiOuXtBIZYrV9/rscs9b33AaT1Rq/qB omuoCIMjCVT3MlcQPOTajiDvhscgDVB3EFNuBT9YUg/aCq3OhoRaoPc7zNaZbDIjed8Z Q98g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Vsz4KeAS9QzSwY7Rmxpp2IvP68bZQMBWDPZO3xnpcVg=; b=u7NV5W9VCy/hNsUZWlDJeTb3dZc7/Llp7YLdDBgx6405t+JbTlFxbAv17GsZG1/WeG CM8SWoxqL8CAVlGrPTXSMEkmjOOilYL+Snv0iXsS3jufb/MvYiDsHMIERgX4JmEwotX2 RwOPxwa8XKTxidY9+HFi0GIDJGEJxkGDM+8LDv4oVkoW/dQtyzc8PFLJqe/Q7BPWGNt9 XxZ3QFRVjXI0M+QhxxL+8nBVsgsSaCgnatl7VwD9Fu5raxSdRyAcDdiNG2wj/v/19t1N E682eg8qZr0BFZR02NW9+bRrrOxc3ajgSZbDzvmhIO6VNS9y3Ib30zm8VYXAcv96hJp7 Gosg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gKxiwyRP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s29-v6si2981277pgn.47.2018.09.05.15.08.04; Wed, 05 Sep 2018 15:08:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gKxiwyRP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728560AbeIFCie (ORCPT + 99 others); Wed, 5 Sep 2018 22:38:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:53066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727626AbeIFCid (ORCPT ); Wed, 5 Sep 2018 22:38:33 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 442A520652; Wed, 5 Sep 2018 22:06:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1536185181; bh=tQPXWrNnNFk1KBgdORTIpeVUsxMpyIc5ozEdAMlpeio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gKxiwyRPBhZZ2+SnRopc1kMkrgUV7/pTV7s9PUF2SeHeVZq8reeLLpQWIB+koYOqQ jooLKZ+alJs7iooTTXoVQQf1PLGyML3reRQ/8qgkxaFj0/4+0IMjWZHyGtuH8K/w5I fj5u15ssc3nq6p1W0GYhmBQ/fOOahyOdXSM2kCTg= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Jiri Olsa , Alexander Shishkin , Andi Kleen , David Ahern , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH 33/77] perf stat: Move create_perf_stat_counter() to stat.c Date: Wed, 5 Sep 2018 19:03:56 -0300 Message-Id: <20180905220440.20256-34-acme@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180905220440.20256-1-acme@kernel.org> References: <20180905220440.20256-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Olsa Move create_perf_stat_counter() to the 'stat' class, so that we can use it globally. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20180830063252.23729-9-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-stat.c | 54 +---------------------------------------------- tools/perf/util/stat.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/stat.h | 4 ++++ 3 files changed, 58 insertions(+), 53 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 45bbd156d496..142cff8eb12b 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -234,58 +234,6 @@ static void perf_stat__reset_stats(void) perf_stat__reset_shadow_per_stat(&stat_config.stats[i]); } -static int create_perf_stat_counter(struct perf_evsel *evsel, - struct perf_stat_config *config) -{ - struct perf_event_attr *attr = &evsel->attr; - struct perf_evsel *leader = evsel->leader; - - if (config->scale) { - attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | - PERF_FORMAT_TOTAL_TIME_RUNNING; - } - - /* - * The event is part of non trivial group, let's enable - * the group read (for leader) and ID retrieval for all - * members. - */ - if (leader->nr_members > 1) - attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP; - - attr->inherit = !config->no_inherit; - - /* - * Some events get initialized with sample_(period/type) set, - * like tracepoints. Clear it up for counting. - */ - attr->sample_period = 0; - - if (config->identifier) - attr->sample_type = PERF_SAMPLE_IDENTIFIER; - - /* - * Disabling all counters initially, they will be enabled - * either manually by us or by kernel via enable_on_exec - * set later. - */ - if (perf_evsel__is_group_leader(evsel)) { - attr->disabled = 1; - - /* - * In case of initial_delay we enable tracee - * events manually. - */ - if (target__none(&target) && !config->initial_delay) - attr->enable_on_exec = 1; - } - - if (target__has_cpu(&target) && !target__has_per_thread(&target)) - return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel)); - - return perf_evsel__open_per_thread(evsel, evsel->threads); -} - static int process_synthesized_event(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample __maybe_unused, @@ -568,7 +516,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) evlist__for_each_entry(evsel_list, counter) { try_again: - if (create_perf_stat_counter(counter, &stat_config) < 0) { + if (create_perf_stat_counter(counter, &stat_config, &target) < 0) { /* Weak group failed. Reset the group. */ if ((errno == EINVAL || errno == EBADF) && diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index a0061e0b0fad..3bd24255376a 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -435,3 +435,56 @@ size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp) return ret; } + +int create_perf_stat_counter(struct perf_evsel *evsel, + struct perf_stat_config *config, + struct target *target) +{ + struct perf_event_attr *attr = &evsel->attr; + struct perf_evsel *leader = evsel->leader; + + if (config->scale) { + attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | + PERF_FORMAT_TOTAL_TIME_RUNNING; + } + + /* + * The event is part of non trivial group, let's enable + * the group read (for leader) and ID retrieval for all + * members. + */ + if (leader->nr_members > 1) + attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP; + + attr->inherit = !config->no_inherit; + + /* + * Some events get initialized with sample_(period/type) set, + * like tracepoints. Clear it up for counting. + */ + attr->sample_period = 0; + + if (config->identifier) + attr->sample_type = PERF_SAMPLE_IDENTIFIER; + + /* + * Disabling all counters initially, they will be enabled + * either manually by us or by kernel via enable_on_exec + * set later. + */ + if (perf_evsel__is_group_leader(evsel)) { + attr->disabled = 1; + + /* + * In case of initial_delay we enable tracee + * events manually. + */ + if (target__none(target) && !config->initial_delay) + attr->enable_on_exec = 1; + } + + if (target__has_cpu(target) && !target__has_per_thread(target)) + return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel)); + + return perf_evsel__open_per_thread(evsel, evsel->threads); +} diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 918cde064cdc..8fb596641545 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -175,4 +175,8 @@ int perf_event__process_stat_event(struct perf_tool *tool, size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp); size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp); size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp); + +int create_perf_stat_counter(struct perf_evsel *evsel, + struct perf_stat_config *config, + struct target *target); #endif -- 2.14.4