From patchwork Mon Jan 25 09:56:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 60295 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp1254609lbb; Mon, 25 Jan 2016 01:59:45 -0800 (PST) X-Received: by 10.98.74.135 with SMTP id c7mr24367578pfj.129.1453715980461; Mon, 25 Jan 2016 01:59:40 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fm8si32680427pad.29.2016.01.25.01.59.40; Mon, 25 Jan 2016 01:59:40 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932330AbcAYJ7f (ORCPT + 30 others); Mon, 25 Jan 2016 04:59:35 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:27561 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756706AbcAYJ7S (ORCPT ); Mon, 25 Jan 2016 04:59:18 -0500 Received: from 172.24.1.47 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.47]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BVE53530; Mon, 25 Jan 2016 17:58:02 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Mon, 25 Jan 2016 17:57:54 +0800 From: Wang Nan To: Alexei Starovoitov , Arnaldo Carvalho de Melo CC: Brendan Gregg , Daniel Borkmann , "David S. Miller" , He Kuang , Jiri Olsa , Li Zefan , Masami Hiramatsu , Namhyung Kim , Peter Zijlstra , , Will Deacon , , Wang Nan Subject: [PATCH 53/54] perf record: Allow generate tracking events at the end of output Date: Mon, 25 Jan 2016 09:56:40 +0000 Message-ID: <1453715801-7732-54-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1453715801-7732-1-git-send-email-wangnan0@huawei.com> References: <1453715801-7732-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.56A5F1B0.00DC, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 209b194add088a625dfca3132b0a803f Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before this patch tracking events are generated based on information in /proc before all samples. However, with the introducing of overwrite evsel in perf record, it becomes inconvenience: 'perf record' now can executed as a daemon for sereval hours and only capture the last snapshot when it receives SIGUSR2. The tracking events generated at the head of output 'perf.data' becomes too old, but most of tracking events during 'perf record' running are dropped. This patch generates tracking events at the end of output. The output events series would better reflecting status of system when SIGUSR2 received. Signed-off-by: Wang Nan Signed-off-by: He Kuang Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Zefan Li Cc: pi3orama@163.com --- tools/perf/builtin-record.c | 62 +++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 19 deletions(-) -- 1.8.3.4 diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 1f03db0..6eaa43d 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -63,6 +63,7 @@ struct record { bool timestamp_filename; bool switch_output; enum overwrite_evt_state overwrite_evt_state; + bool tail_tracking; unsigned long long samples; }; @@ -683,6 +684,26 @@ record__finish_output(struct record *rec) static int record__synthesize(struct record *rec); +static void record__synthesize_target(struct record *rec) +{ + if (target__none(&rec->opts.target)) { + struct { + struct thread_map map; + struct thread_map_data map_data; + } thread_map; + + thread_map.map.nr = 1; + thread_map.map.map[0].pid = rec->evlist->workload.pid; + thread_map.map.map[0].comm = NULL; + perf_event__synthesize_thread_map(&rec->tool, + &thread_map.map, + process_synthesized_event, + &rec->session->machines.host, + rec->opts.sample_address, + rec->opts.proc_map_timeout); + } +} + static int record__switch_output(struct record *rec, bool at_exit) { @@ -692,6 +713,11 @@ record__switch_output(struct record *rec, bool at_exit) /* Same Size: "2015122520103046"*/ char timestamp[] = "InvalidTimestamp"; + if (rec->tail_tracking) { + record__synthesize(rec); + record__synthesize_target(rec); + } + rec->samples = 0; record__finish_output(rec); err = fetch_current_timestamp(timestamp, sizeof(timestamp)); @@ -718,23 +744,10 @@ record__switch_output(struct record *rec, bool at_exit) machines__init(&rec->session->machines); perf_session__create_kernel_maps(rec->session); perf_session__set_id_hdr_size(rec->session); - record__synthesize(rec); - if (target__none(&rec->opts.target)) { - struct { - struct thread_map map; - struct thread_map_data map_data; - } thread_map; - - thread_map.map.nr = 1; - thread_map.map.map[0].pid = rec->evlist->workload.pid; - thread_map.map.map[0].comm = NULL; - perf_event__synthesize_thread_map(&rec->tool, - &thread_map.map, - process_synthesized_event, - &rec->session->machines.host, - rec->opts.sample_address, - rec->opts.proc_map_timeout); + if (!rec->tail_tracking) { + record__synthesize(rec); + record__synthesize_target(rec); } } return fd; @@ -930,9 +943,11 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) machine = &session->machines.host; - err = record__synthesize(rec); - if (err < 0) - goto out_child; + if (!rec->tail_tracking) { + err = record__synthesize(rec); + if (err < 0) + goto out_child; + } if (rec->realtime_prio) { struct sched_param param; @@ -1073,6 +1088,13 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) disabled = true; } } + + if (rec->tail_tracking) { + err = record__synthesize(rec); + if (err < 0) + goto out_child; + } + auxtrace_snapshot_disable(); if (forks && workload_exec_errno) { @@ -1499,6 +1521,8 @@ struct option __record_options[] = { "append timestamp to output filename"), OPT_BOOLEAN(0, "switch-output", &record.switch_output, "Switch output when receive SIGUSR2"), + OPT_BOOLEAN(0, "tail-tracking", &record.tail_tracking, + "Generate tracking events at the end of output"), OPT_END() };