linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Andi Kleen <ak@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 23/30] perf report: Support time sort key
Date: Mon, 11 Mar 2019 23:01:57 -0300	[thread overview]
Message-ID: <20190312020204.22092-24-acme@kernel.org> (raw)
In-Reply-To: <20190312020204.22092-1-acme@kernel.org>

From: Andi Kleen <ak@linux.intel.com>

Add a time sort key to perf report to display samples for different time
quantums separately. This allows easier analysis of workloads that
change over time, and also will allow looking at the context of samples.

% perf record ...
% perf report --sort time,overhead,symbol --time-quantum 1ms --stdio
...
     0.67%  277061.87300  [.] _dl_start
     0.50%  277061.87300  [.] f1
     0.50%  277061.87300  [.] f2
     0.33%  277061.87300  [.] main
     0.29%  277061.87300  [.] _dl_lookup_symbol_x
     0.29%  277061.87300  [.] dl_main
     0.29%  277061.87300  [.] do_lookup_x
     0.17%  277061.87300  [.] _dl_debug_initialize
     0.17%  277061.87300  [.] _dl_init_paths
     0.08%  277061.87300  [.] check_match
     0.04%  277061.87300  [.] _dl_count_modids
     1.33%  277061.87400  [.] f1
     1.33%  277061.87400  [.] f2
     1.33%  277061.87400  [.] main
     1.17%  277061.87500  [.] main
     1.08%  277061.87500  [.] f1
     1.08%  277061.87500  [.] f2
     1.00%  277061.87600  [.] main
     0.83%  277061.87600  [.] f1
     0.83%  277061.87600  [.] f2
     1.00%  277061.87700  [.] main

Committer notes:

Rename 'time' argument to hist_time() to htime to overcome this in older
distros:

  cc1: warnings being treated as errors
  util/hist.c: In function 'hist_time':
  util/hist.c:251: error: declaration of 'time' shadows a global declaration
  /usr/include/time.h:186: error: shadowed declaration is here

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20190311144502.15423-4-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-report.txt |  2 ++
 tools/perf/util/hist.c                   | 11 +++++++
 tools/perf/util/hist.h                   |  1 +
 tools/perf/util/sort.c                   | 39 ++++++++++++++++++++++++
 tools/perf/util/sort.h                   |  2 ++
 5 files changed, 55 insertions(+)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 9ec1702bccdd..546d87221ad8 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -105,6 +105,8 @@ OPTIONS
 	guest machine
 	- sample: Number of sample
 	- period: Raw number of event count of sample
+	- time: Separate the samples by time stamp with the resolution specified by
+	--time-quantum (default 100ms). Specify with overhead and before it.
 
 	By default, comm, dso and symbol keys are used.
 	(i.e. --sort comm,dso,symbol)
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index f9eb95bf3938..34c0f00c68d1 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -19,6 +19,7 @@
 #include <math.h>
 #include <inttypes.h>
 #include <sys/param.h>
+#include <linux/time64.h>
 
 static bool hists__filter_entry_by_dso(struct hists *hists,
 				       struct hist_entry *he);
@@ -192,6 +193,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 	hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3);
 	hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12);
 	hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12);
+	hists__new_col_len(hists, HISTC_TIME, 12);
 
 	if (h->srcline) {
 		len = MAX(strlen(h->srcline), strlen(sort_srcline.se_header));
@@ -246,6 +248,14 @@ static void he_stat__add_cpumode_period(struct he_stat *he_stat,
 	}
 }
 
+static long hist_time(unsigned long htime)
+{
+	unsigned long time_quantum = symbol_conf.time_quantum;
+	if (time_quantum)
+		return (htime / time_quantum) * time_quantum;
+	return htime;
+}
+
 static void he_stat__add_period(struct he_stat *he_stat, u64 period,
 				u64 weight)
 {
@@ -635,6 +645,7 @@ __hists__add_entry(struct hists *hists,
 		.raw_data = sample->raw_data,
 		.raw_size = sample->raw_size,
 		.ops = ops,
+		.time = hist_time(sample->time),
 	}, *he = hists__findnew_entry(hists, &entry, al, sample_self);
 
 	if (!hists->has_callchains && he && he->callchain_size != 0)
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 4af27fbab24f..6279eca56409 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -31,6 +31,7 @@ enum hist_filter {
 
 enum hist_column {
 	HISTC_SYMBOL,
+	HISTC_TIME,
 	HISTC_DSO,
 	HISTC_THREAD,
 	HISTC_COMM,
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index d2299e912e59..bdd30cab51cb 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -3,6 +3,7 @@
 #include <inttypes.h>
 #include <regex.h>
 #include <linux/mman.h>
+#include <linux/time64.h>
 #include "sort.h"
 #include "hist.h"
 #include "comm.h"
@@ -15,6 +16,7 @@
 #include <traceevent/event-parse.h>
 #include "mem-events.h"
 #include "annotate.h"
+#include "time-utils.h"
 #include <linux/kernel.h>
 
 regex_t		parent_regex;
@@ -654,6 +656,42 @@ struct sort_entry sort_socket = {
 	.se_width_idx	= HISTC_SOCKET,
 };
 
+/* --sort time */
+
+static int64_t
+sort__time_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+	return right->time - left->time;
+}
+
+static int hist_entry__time_snprintf(struct hist_entry *he, char *bf,
+				    size_t size, unsigned int width)
+{
+	unsigned long secs;
+	unsigned long long nsecs;
+	char he_time[32];
+
+	nsecs = he->time;
+	secs = nsecs / NSEC_PER_SEC;
+	nsecs -= secs * NSEC_PER_SEC;
+
+	if (symbol_conf.nanosecs)
+		snprintf(he_time, sizeof he_time, "%5lu.%09llu: ",
+			 secs, nsecs);
+	else
+		timestamp__scnprintf_usec(he->time, he_time,
+					  sizeof(he_time));
+
+	return repsep_snprintf(bf, size, "%-.*s", width, he_time);
+}
+
+struct sort_entry sort_time = {
+	.se_header      = "Time",
+	.se_cmp	        = sort__time_cmp,
+	.se_snprintf    = hist_entry__time_snprintf,
+	.se_width_idx	= HISTC_TIME,
+};
+
 /* --sort trace */
 
 static char *get_trace_output(struct hist_entry *he)
@@ -1634,6 +1672,7 @@ static struct sort_dimension common_sort_dimensions[] = {
 	DIM(SORT_DSO_SIZE, "dso_size", sort_dso_size),
 	DIM(SORT_CGROUP_ID, "cgroup_id", sort_cgroup_id),
 	DIM(SORT_SYM_IPC_NULL, "ipc_null", sort_sym_ipc_null),
+	DIM(SORT_TIME, "time", sort_time),
 };
 
 #undef DIM
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 2fbee0b1011c..19dceb7f6145 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -135,6 +135,7 @@ struct hist_entry {
 	char			*srcfile;
 	struct symbol		*parent;
 	struct branch_info	*branch_info;
+	long			time;
 	struct hists		*hists;
 	struct mem_info		*mem_info;
 	void			*raw_data;
@@ -231,6 +232,7 @@ enum sort_type {
 	SORT_DSO_SIZE,
 	SORT_CGROUP_ID,
 	SORT_SYM_IPC_NULL,
+	SORT_TIME,
 
 	/* branch stack specific sort keys */
 	__SORT_BRANCH_STACK,
-- 
2.20.1

  parent reply	other threads:[~2019-03-12  2:01 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-12  2:01 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 01/30] perf/core: Restore mmap record type correctly Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 02/30] perf script: Support insn output for normal samples Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 03/30] perf report: Support output in nanoseconds Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 04/30] perf time-utils: Add utility function to print time stamps " Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 05/30] perf report: Parse time quantum Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 06/30] perf probe: Fix getting the kernel map Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 07/30] perf vendor events amd: perf PMU events for AMD Family 17h Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 08/30] perf data: Support having perf.data stored as a directory Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 09/30] perf data: Don't store auxtrace index for directory data file Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 10/30] perf data: Add perf_data__update_dir() function Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 11/30] perf data: Make perf_data__size() work over directory Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 12/30] perf header: Add DIR_FORMAT feature to describe directory data Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 13/30] perf session: Add process callback to reader object Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 14/30] perf report: Use less for scripts output Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 15/30] perf script python: Add Python3 support to exported-sql-viewer.py Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 16/30] perf script python: Add Python3 support to export-to-postgresql.py Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 17/30] perf script python: Add Python3 support to export-to-sqlite.py Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 18/30] perf script python: Add printdate function to SQL exporters Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 19/30] perf tools: Update x86's syscall_64.tbl, no change in tools/perf behaviour Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 20/30] tools headers uapi: Sync copy of asm-generic/unistd.h with the kernel sources Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 21/30] tools headers uapi: Update linux/in.h copy Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 22/30] perf script: Filter COMM/FORK/.. events by CPU Arnaldo Carvalho de Melo
2019-03-12  2:01 ` Arnaldo Carvalho de Melo [this message]
2019-03-12  2:01 ` [PATCH 24/30] perf report: Support running scripts for current time range Arnaldo Carvalho de Melo
2019-03-12  2:01 ` [PATCH 25/30] perf report: Support builtin perf script in scripts menu Arnaldo Carvalho de Melo
2019-03-12  2:02 ` [PATCH 26/30] perf report: Implement browsing of individual samples Arnaldo Carvalho de Melo
2019-03-12  2:02 ` [PATCH 27/30] perf tools: Add some new tips describing the new options Arnaldo Carvalho de Melo
2019-03-12  2:02 ` [PATCH 28/30] perf script: Add array bound checking to list_scripts Arnaldo Carvalho de Melo
2019-03-12  2:02 ` [PATCH 29/30] perf ui browser: Fix ui popup argv browser for many entries Arnaldo Carvalho de Melo
2019-03-12  2:02 ` [PATCH 30/30] perf tools report: Add custom scripts to script menu Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190312020204.22092-24-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).