linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Hari Bathini <hbathini@linux.vnet.ibm.com>
Cc: ast@fb.com, peterz@infradead.org,
	lkml <linux-kernel@vger.kernel.org>,
	alexander.shishkin@linux.intel.com,
	Ingo Molnar <mingo@kernel.org>,
	daniel@iogearbox.net, rostedt@goodmis.org,
	Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
	ebiederm@xmission.com, sargun@sargun.me,
	Aravinda Prasad <aravinda@linux.vnet.ibm.com>,
	brendan.d.gregg@gmail.com, jolsa@redhat.com
Subject: Re: [PATCH v7 8/8] perf tool: add cgroup identifier entry in perf report
Date: Wed, 1 Mar 2017 18:16:01 -0300	[thread overview]
Message-ID: <20170301211601.GN15145@kernel.org> (raw)
In-Reply-To: <148768579375.30285.4755821132989024168.stgit@hbathini.in.ibm.com>

Em Tue, Feb 21, 2017 at 07:33:13PM +0530, Hari Bathini escreveu:
> This patch introduces a cgroup identifier entry field in perf report to
> identify or distinguish data of different cgroups. It uses the device
> number and inode number of cgroup namespace, included in perf data with
> the new PERF_RECORD_NAMESPACES event, as cgroup identifier. With the
> assumption that each container is created with it's own cgroup namespace,
> this allows assessment/analysis of multiple containers at once.

Could you try to do this with some real world example? I.e. telling that
systemd creates some cgroups and then how to map the perf report output
you show below with what systemd puts in place.

Doing it with docker would be handy as well, no?

You also forgot to update the documentation with this new sort key,
please add it in the --sort part of
tools/perf/Documentation/perf-report.txt.

Ah, and just another minor request: please format the changeset
summaries as:

 perf tools: Add cgroup identifier sort order keyword


First the component, that in this case is the generic one, as it affects
multiple tools (top, report), and then start with a capital letter after
the colon.

A git log --oneline tools/perf/ -20

will show you the pattern used.

Thanks!

- Arnaldo
 
> Shown below is the output of perf report, sorted based on cgroup id, on
> a system that was running three containers at the time of perf record
> and clearly showing one of the containers' considerable use of kernel
> memory in comparison with others:
> 
> 
> 	$ perf report -s cgroup_id,sample --stdio
> 	#
> 	# Total Lost Samples: 0
> 	#
> 	# Samples: 16K of event 'kmem:kmalloc'
> 	# Event count (approx.): 16043
> 	#
> 	# Overhead  cgroup id (dev/inode)       Samples
> 	# ........  .....................  ............
> 	#
> 	    96.33%  3/0xf00000d0                  15454
> 	     3.02%  3/0xeffffffb                    485
> 	     0.31%  3/0xf00000ce                     49
> 	     0.29%  3/0xf00000cf                     47
> 	     0.05%  0/0x0                             8
> 
> While this is a start, there is further scope of improving this. For
> example, instead of cgroup namespace's device and inode numbers, dev
> and inode numbers of some or all namespaces may be used to distinguish
> which processes are running in a given container context. Also, scripts
> to map device and inode info to containers sounds plausible for better
> tracing of containers.
> 
> Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
> ---
>  tools/perf/util/hist.c |    7 +++++++
>  tools/perf/util/hist.h |    1 +
>  tools/perf/util/sort.c |   41 +++++++++++++++++++++++++++++++++++++++++
>  tools/perf/util/sort.h |    7 +++++++
>  4 files changed, 56 insertions(+)
> 
> diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
> index 32c6a93..559ea27 100644
> --- a/tools/perf/util/hist.c
> +++ b/tools/perf/util/hist.c
> @@ -3,6 +3,7 @@
>  #include "hist.h"
>  #include "map.h"
>  #include "session.h"
> +#include "namespaces.h"
>  #include "sort.h"
>  #include "evlist.h"
>  #include "evsel.h"
> @@ -169,6 +170,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
>  		hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);
>  	}
>  
> +	hists__new_col_len(hists, HISTC_CGROUP_ID, 20);
>  	hists__new_col_len(hists, HISTC_CPU, 3);
>  	hists__new_col_len(hists, HISTC_SOCKET, 6);
>  	hists__new_col_len(hists, HISTC_MEM_LOCKED, 6);
> @@ -574,9 +576,14 @@ __hists__add_entry(struct hists *hists,
>  		   bool sample_self,
>  		   struct hist_entry_ops *ops)
>  {
> +	struct namespaces *ns = thread__namespaces(al->thread);
>  	struct hist_entry entry = {
>  		.thread	= al->thread,
>  		.comm = thread__comm(al->thread),
> +		.cgroup_id = {
> +			.dev = ns ? ns->link_info[CGROUP_NS_INDEX].dev : 0,
> +			.ino = ns ? ns->link_info[CGROUP_NS_INDEX].ino : 0,
> +		},
>  		.ms = {
>  			.map	= al->map,
>  			.sym	= al->sym,
> diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
> index 28c216e..4c1da48 100644
> --- a/tools/perf/util/hist.h
> +++ b/tools/perf/util/hist.h
> @@ -30,6 +30,7 @@ enum hist_column {
>  	HISTC_DSO,
>  	HISTC_THREAD,
>  	HISTC_COMM,
> +	HISTC_CGROUP_ID,
>  	HISTC_PARENT,
>  	HISTC_CPU,
>  	HISTC_SOCKET,
> diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> index df622f4..9f5f404 100644
> --- a/tools/perf/util/sort.c
> +++ b/tools/perf/util/sort.c
> @@ -536,6 +536,46 @@ struct sort_entry sort_cpu = {
>  	.se_width_idx	= HISTC_CPU,
>  };
>  
> +/* --sort cgroup_id */
> +
> +static int64_t _sort__cgroup_dev_cmp(u64 left_dev, u64 right_dev)
> +{
> +	return (int64_t)(right_dev - left_dev);
> +}
> +
> +static int64_t _sort__cgroup_inode_cmp(u64 left_ino, u64 right_ino)
> +{
> +	return (int64_t)(right_ino - left_ino);
> +}
> +
> +static int64_t
> +sort__cgroup_id_cmp(struct hist_entry *left, struct hist_entry *right)
> +{
> +	int64_t ret;
> +
> +	ret = _sort__cgroup_dev_cmp(right->cgroup_id.dev, left->cgroup_id.dev);
> +	if (ret != 0)
> +		return ret;
> +
> +	return _sort__cgroup_inode_cmp(right->cgroup_id.ino,
> +				       left->cgroup_id.ino);
> +}
> +
> +static int hist_entry__cgroup_id_snprintf(struct hist_entry *he,
> +					  char *bf, size_t size,
> +					  unsigned int width __maybe_unused)
> +{
> +	return repsep_snprintf(bf, size, "%lu/0x%lx", he->cgroup_id.dev,
> +			       he->cgroup_id.ino);
> +}
> +
> +struct sort_entry sort_cgroup_id = {
> +	.se_header      = "cgroup id (dev/inode)",
> +	.se_cmp	        = sort__cgroup_id_cmp,
> +	.se_snprintf    = hist_entry__cgroup_id_snprintf,
> +	.se_width_idx	= HISTC_CGROUP_ID,
> +};
> +
>  /* --sort socket */
>  
>  static int64_t
> @@ -1418,6 +1458,7 @@ static struct sort_dimension common_sort_dimensions[] = {
>  	DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
>  	DIM(SORT_TRANSACTION, "transaction", sort_transaction),
>  	DIM(SORT_TRACE, "trace", sort_trace),
> +	DIM(SORT_CGROUP_ID, "cgroup_id", sort_cgroup_id),
>  };
>  
>  #undef DIM
> diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
> index 7aff317..68a5abb 100644
> --- a/tools/perf/util/sort.h
> +++ b/tools/perf/util/sort.h
> @@ -54,6 +54,11 @@ struct he_stat {
>  	u32			nr_events;
>  };
>  
> +struct namespace_id {
> +	u64			dev;
> +	u64			ino;
> +};
> +
>  struct hist_entry_diff {
>  	bool	computed;
>  	union {
> @@ -91,6 +96,7 @@ struct hist_entry {
>  	struct map_symbol	ms;
>  	struct thread		*thread;
>  	struct comm		*comm;
> +	struct namespace_id	cgroup_id;
>  	u64			ip;
>  	u64			transaction;
>  	s32			socket;
> @@ -211,6 +217,7 @@ enum sort_type {
>  	SORT_GLOBAL_WEIGHT,
>  	SORT_TRANSACTION,
>  	SORT_TRACE,
> +	SORT_CGROUP_ID,
>  
>  	/* branch stack specific sort keys */
>  	__SORT_BRANCH_STACK,

  parent reply	other threads:[~2017-03-01 21:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-21 14:01 [PATCH v7 0/8] perf: add support for analyzing events for containers Hari Bathini
2017-02-21 14:01 ` [PATCH v7 1/8] perf: add PERF_RECORD_NAMESPACES to include namespaces related info Hari Bathini
2017-02-24 12:14   ` Peter Zijlstra
2017-03-01 20:45     ` Arnaldo Carvalho de Melo
2017-02-21 14:01 ` [PATCH v7 2/8] perf tool: " Hari Bathini
2017-03-01 21:02   ` Arnaldo Carvalho de Melo
2017-03-03  8:54     ` Hari Bathini
2017-02-21 14:01 ` [PATCH v7 3/8] perf tool: update about the new option to record namespace events Hari Bathini
2017-03-01 21:03   ` Arnaldo Carvalho de Melo
2017-02-21 14:01 ` [PATCH v7 4/8] perf tool: synthesize namespace events for current processes Hari Bathini
2017-03-01 21:05   ` Arnaldo Carvalho de Melo
2017-03-03  8:57     ` Hari Bathini
2017-02-21 14:01 ` [PATCH v7 5/8] perf tool: add print support for namespace events Hari Bathini
2017-03-01 21:06   ` Arnaldo Carvalho de Melo
2017-02-21 14:02 ` [PATCH v7 6/8] perf tool: add script " Hari Bathini
2017-03-01 21:08   ` Arnaldo Carvalho de Melo
2017-02-21 14:02 ` [PATCH v7 7/8] perf tool: update about the new option to show " Hari Bathini
2017-02-21 14:03 ` [PATCH v7 8/8] perf tool: add cgroup identifier entry in perf report Hari Bathini
2017-02-22 16:48   ` Jiri Olsa
2017-03-01 21:16   ` Arnaldo Carvalho de Melo [this message]
2017-03-03  8:59     ` Hari Bathini
2017-02-22 11:11 ` [PATCH v7 0/8] perf: add support for analyzing events for containers Jiri Olsa
2017-02-22 12:40   ` Hari Bathini
2017-02-22 13:52     ` Jiri Olsa

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=20170301211601.GN15145@kernel.org \
    --to=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=aravinda@linux.vnet.ibm.com \
    --cc=ast@fb.com \
    --cc=brendan.d.gregg@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=ebiederm@xmission.com \
    --cc=hbathini@linux.vnet.ibm.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sargun@sargun.me \
    /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).