All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Wang Nan <wangnan0@huawei.com>,
	lkml <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH 1/6] perf tools: Add unit_number__scnprint function
Date: Tue, 10 Jan 2017 10:22:36 -0300	[thread overview]
Message-ID: <20170110132236.GB24073@kernel.org> (raw)
In-Reply-To: <1483955520-29063-2-git-send-email-jolsa@kernel.org>

Em Mon, Jan 09, 2017 at 10:51:55AM +0100, Jiri Olsa escreveu:
> Adding unit_number__scnprint function to display

Renaming to unit_number__scnprintf() for consistency.

- Arnaldo

> size units and use it in -m option info message.
> 
> Before:
>   $ perf record -m 10M ls
>   rounding mmap pages size to 16777216 bytes (4096 pages)
>   ...
> 
> After:
>   $ perf record -m 10M ls
>   rounding mmap pages size to 16M (4096 pages)
>   ...
> 
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Wang Nan <wangnan0@huawei.com>
> Link: http://lkml.kernel.org/n/tip-0gafw11lesghnbfoiw90kc3q@git.kernel.org
> ---
>  tools/perf/tests/Build                   |  1 +
>  tools/perf/tests/builtin-test.c          |  4 ++++
>  tools/perf/tests/tests.h                 |  1 +
>  tools/perf/tests/unit_number__scnprint.c | 37 ++++++++++++++++++++++++++++++++
>  tools/perf/util/evlist.c                 |  8 +++++--
>  tools/perf/util/util.c                   | 13 +++++++++++
>  tools/perf/util/util.h                   |  1 +
>  7 files changed, 63 insertions(+), 2 deletions(-)
>  create mode 100644 tools/perf/tests/unit_number__scnprint.c
> 
> diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
> index 6676c2dd6dcb..4f653d257225 100644
> --- a/tools/perf/tests/Build
> +++ b/tools/perf/tests/Build
> @@ -44,6 +44,7 @@ perf-y += is_printable_array.o
>  perf-y += bitmap.o
>  perf-y += perf-hooks.o
>  perf-y += clang.o
> +perf-y += unit_number__scnprint.o
>  
>  $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build
>  	$(call rule_mkdir)
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index a77dcc0d24e3..5d93c41803d3 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -247,6 +247,10 @@ static struct test generic_tests[] = {
>  		}
>  	},
>  	{
> +		.desc = "unit_number__scnprint",
> +		.func = test__unit_number__scnprint,
> +	},
> +	{
>  		.func = NULL,
>  	},
>  };
> diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
> index a512f0c8ff5b..1fa9b9d83aa5 100644
> --- a/tools/perf/tests/tests.h
> +++ b/tools/perf/tests/tests.h
> @@ -96,6 +96,7 @@ int test__perf_hooks(int subtest);
>  int test__clang(int subtest);
>  const char *test__clang_subtest_get_desc(int subtest);
>  int test__clang_subtest_get_nr(void);
> +int test__unit_number__scnprint(int subtest);
>  
>  #if defined(__arm__) || defined(__aarch64__)
>  #ifdef HAVE_DWARF_UNWIND_SUPPORT
> diff --git a/tools/perf/tests/unit_number__scnprint.c b/tools/perf/tests/unit_number__scnprint.c
> new file mode 100644
> index 000000000000..b336024b6c6a
> --- /dev/null
> +++ b/tools/perf/tests/unit_number__scnprint.c
> @@ -0,0 +1,37 @@
> +#include <linux/compiler.h>
> +#include <linux/types.h>
> +#include "tests.h"
> +#include "util.h"
> +#include "debug.h"
> +
> +int test__unit_number__scnprint(int subtest __maybe_unused)
> +{
> +	struct {
> +		u64		 n;
> +		const char	*str;
> +	} test[] = {
> +		{ 1,			"1B"	},
> +		{ 10*1024,		"10K"	},
> +		{ 20*1024*1024,		"20M"	},
> +		{ 30*1024*1024*1024ULL,	"30G"	},
> +		{ 0,			"0B"	},
> +		{ 0,			NULL	},
> +	};
> +	unsigned i = 0;
> +
> +	while (test[i].str) {
> +		char buf[100];
> +
> +		unit_number__scnprint(buf, sizeof(buf), test[i].n);
> +
> +		pr_debug("n %" PRIu64 ", str '%s', buf '%s'\n",
> +			 test[i].n, test[i].str, buf);
> +
> +		if (strcmp(test[i].str, buf))
> +			return TEST_FAIL;
> +
> +		i++;
> +	}
> +
> +	return TEST_OK;
> +}
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index d92e02006fb8..435ff1c94a66 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -1224,12 +1224,16 @@ static long parse_pages_arg(const char *str, unsigned long min,
>  	if (pages == 0 && min == 0) {
>  		/* leave number of pages at 0 */
>  	} else if (!is_power_of_2(pages)) {
> +		char buf[100];
> +
>  		/* round pages up to next power of 2 */
>  		pages = roundup_pow_of_two(pages);
>  		if (!pages)
>  			return -EINVAL;
> -		pr_info("rounding mmap pages size to %lu bytes (%lu pages)\n",
> -			pages * page_size, pages);
> +
> +		unit_number__scnprint(buf, sizeof(buf), pages * page_size);
> +		pr_info("rounding mmap pages size to %s (%lu pages)\n",
> +			buf, pages);
>  	}
>  
>  	if (pages > max)
> diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
> index 9ddd98827d12..c2b941dd8826 100644
> --- a/tools/perf/util/util.c
> +++ b/tools/perf/util/util.c
> @@ -789,3 +789,16 @@ int is_printable_array(char *p, unsigned int len)
>  	}
>  	return 1;
>  }
> +
> +int unit_number__scnprint(char *buf, size_t size, u64 n)
> +{
> +	char unit[4] = "BKMG";
> +	int i = 0;
> +
> +	while (((n / 1024) > 1) && (i < 3)) {
> +		n /= 1024;
> +		i++;
> +	}
> +
> +	return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]);
> +}
> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> index 1d639e38aa82..e2a627cd11dd 100644
> --- a/tools/perf/util/util.h
> +++ b/tools/perf/util/util.h
> @@ -363,4 +363,5 @@ int is_printable_array(char *p, unsigned int len);
>  
>  int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
>  
> +int unit_number__scnprint(char *buf, size_t size, u64 n);
>  #endif /* GIT_COMPAT_UTIL_H */
> -- 
> 2.7.4

  reply	other threads:[~2017-01-10 13:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-09  9:51 [PATCHv2 0/7] perf tools: Add switch-output size and time threshold options Jiri Olsa
2017-01-09  9:51 ` [PATCH 1/6] perf tools: Add unit_number__scnprint function Jiri Olsa
2017-01-10 13:22   ` Arnaldo Carvalho de Melo [this message]
2017-01-12  8:31   ` [tip:perf/core] perf tools: Add unit_number__scnprintf function tip-bot for Jiri Olsa
2017-01-09  9:51 ` [PATCH 2/6] perf record: Add struct switch_output Jiri Olsa
2017-01-12  8:32   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-01-09  9:51 ` [PATCH 3/6] perf record: Change switch-output option to take optional argument Jiri Olsa
2017-01-12  8:32   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-01-09  9:51 ` [PATCH 4/6] perf record: Add switch-output size option argument Jiri Olsa
2017-01-12  8:33   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-01-09  9:51 ` [PATCH 5/6] perf record: Add switch-output size warning Jiri Olsa
2017-01-12  8:33   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-01-09  9:52 ` [PATCH 6/6] perf record: Add switch-output time option argument Jiri Olsa
2017-01-12  8:34   ` [tip:perf/core] " tip-bot for 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=20170110132236.GB24073@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=wangnan0@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.