public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf config: Tidy up the code setting buildid dir
@ 2016-03-24  7:49 Taeung Song
  2016-03-27 11:16 ` Jiri Olsa
  0 siblings, 1 reply; 3+ messages in thread
From: Taeung Song @ 2016-03-24  7:49 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim, Ingo Molnar,
	Peter Zijlstra, Taeung Song, Wang Nan

Add new perf_buildid_config() into perf_default_config,
bring set_buildid_dir() next to perf_default_config,
rename some variable name as more readable name and etc
in order to clean up code about buildid dir.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 tools/perf/perf.c        |  3 +--
 tools/perf/util/config.c | 57 +++++++++++++++++++-----------------------------
 2 files changed, 23 insertions(+), 37 deletions(-)

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index aaee0a7..7b2df2b 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -549,6 +549,7 @@ int main(int argc, const char **argv)
 	srandom(time(NULL));
 
 	perf_config(perf_default_config, NULL);
+	set_buildid_dir(NULL);
 
 	/* get debugfs/tracefs mount point from /proc/mounts */
 	tracing_path_mount();
@@ -572,7 +573,6 @@ int main(int argc, const char **argv)
 	}
 	if (!prefixcmp(cmd, "trace")) {
 #ifdef HAVE_LIBAUDIT_SUPPORT
-		set_buildid_dir(NULL);
 		setup_path();
 		argv[0] = "trace";
 		return cmd_trace(argc, argv, NULL);
@@ -587,7 +587,6 @@ int main(int argc, const char **argv)
 	argc--;
 	handle_options(&argv, &argc, NULL);
 	commit_pager_choice();
-	set_buildid_dir(NULL);
 
 	if (argc > 0) {
 		if (!prefixcmp(argv[0], "--"))
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 4e72763..5c20d78 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -377,6 +377,21 @@ const char *perf_config_dirname(const char *name, const char *value)
 	return value;
 }
 
+static int perf_buildid_config(const char *var, const char *value)
+{
+	/* same dir for all commands */
+	if (!strcmp(var, "buildid.dir")) {
+		const char *dirname = perf_config_dirname(var, value);
+
+		if (!dirname)
+			return -1;
+		strncpy(buildid_dir, dirname, MAXPATHLEN-1);
+		buildid_dir[MAXPATHLEN-1] = '\0';
+	}
+
+	return 0;
+}
+
 static int perf_default_core_config(const char *var __maybe_unused,
 				    const char *value __maybe_unused)
 {
@@ -412,6 +427,9 @@ int perf_default_config(const char *var, const char *value,
 	if (!prefixcmp(var, "llvm."))
 		return perf_llvm_config(var, value);
 
+	if (!prefixcmp(var, "buildid."))
+		return perf_buildid_config(var, value);
+
 	/* Add other config variables here. */
 	return 0;
 }
@@ -515,49 +533,18 @@ int config_error_nonbool(const char *var)
 	return error("Missing value for '%s'", var);
 }
 
-struct buildid_dir_config {
-	char *dir;
-};
-
-static int buildid_dir_command_config(const char *var, const char *value,
-				      void *data)
-{
-	struct buildid_dir_config *c = data;
-	const char *v;
-
-	/* same dir for all commands */
-	if (!strcmp(var, "buildid.dir")) {
-		v = perf_config_dirname(var, value);
-		if (!v)
-			return -1;
-		strncpy(c->dir, v, MAXPATHLEN-1);
-		c->dir[MAXPATHLEN-1] = '\0';
-	}
-	return 0;
-}
-
-static void check_buildid_dir_config(void)
-{
-	struct buildid_dir_config c;
-	c.dir = buildid_dir;
-	perf_config(buildid_dir_command_config, &c);
-}
-
 void set_buildid_dir(const char *dir)
 {
 	if (dir)
 		scnprintf(buildid_dir, MAXPATHLEN-1, "%s", dir);
 
-	/* try config file */
-	if (buildid_dir[0] == '\0')
-		check_buildid_dir_config();
-
 	/* default to $HOME/.debug */
 	if (buildid_dir[0] == '\0') {
-		char *v = getenv("HOME");
-		if (v) {
+		char *home = getenv("HOME");
+
+		if (home) {
 			snprintf(buildid_dir, MAXPATHLEN-1, "%s/%s",
-				 v, DEBUG_CACHE_DIR);
+				 home, DEBUG_CACHE_DIR);
 		} else {
 			strncpy(buildid_dir, DEBUG_CACHE_DIR, MAXPATHLEN-1);
 		}
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf config: Tidy up the code setting buildid dir
  2016-03-24  7:49 [PATCH] perf config: Tidy up the code setting buildid dir Taeung Song
@ 2016-03-27 11:16 ` Jiri Olsa
  2016-03-27 15:41   ` Taeung Song
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2016-03-27 11:16 UTC (permalink / raw)
  To: Taeung Song
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Jiri Olsa, Namhyung Kim,
	Ingo Molnar, Peter Zijlstra, Wang Nan

On Thu, Mar 24, 2016 at 04:49:33PM +0900, Taeung Song wrote:
> Add new perf_buildid_config() into perf_default_config,
> bring set_buildid_dir() next to perf_default_config,
> rename some variable name as more readable name and etc
> in order to clean up code about buildid dir.
> 
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Wang Nan <wangnan0@huawei.com>
> Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
> ---
>  tools/perf/perf.c        |  3 +--
>  tools/perf/util/config.c | 57 +++++++++++++++++++-----------------------------
>  2 files changed, 23 insertions(+), 37 deletions(-)

though it's failry simple change we try to separate changes

seems like 3 independent changes:

  - perf.c hunk change
  - buildid_dir_command_config/perf_buildid_config rework
  - set_buildid_dir fix

thanks,
jirka

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf config: Tidy up the code setting buildid dir
  2016-03-27 11:16 ` Jiri Olsa
@ 2016-03-27 15:41   ` Taeung Song
  0 siblings, 0 replies; 3+ messages in thread
From: Taeung Song @ 2016-03-27 15:41 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Jiri Olsa, Namhyung Kim,
	Ingo Molnar, Peter Zijlstra, Wang Nan

Hi, jirka

Thank you for your review :-)

On 03/27/2016 08:16 PM, Jiri Olsa wrote:
> On Thu, Mar 24, 2016 at 04:49:33PM +0900, Taeung Song wrote:
>> Add new perf_buildid_config() into perf_default_config,
>> bring set_buildid_dir() next to perf_default_config,
>> rename some variable name as more readable name and etc
>> in order to clean up code about buildid dir.
>>
>> Cc: Jiri Olsa <jolsa@kernel.org>
>> Cc: Namhyung Kim <namhyung@kernel.org>
>> Cc: Wang Nan <wangnan0@huawei.com>
>> Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
>> ---
>>   tools/perf/perf.c        |  3 +--
>>   tools/perf/util/config.c | 57 +++++++++++++++++++-----------------------------
>>   2 files changed, 23 insertions(+), 37 deletions(-)
>
> though it's failry simple change we try to separate changes
>
> seems like 3 independent changes:
>
>    - perf.c hunk change
>    - buildid_dir_command_config/perf_buildid_config rework
>    - set_buildid_dir fix
>

You mean it is needed to separate this patch as 3 part?
I got it.

I'll resend the patchset.

Thanks,
Taeung

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-27 15:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-24  7:49 [PATCH] perf config: Tidy up the code setting buildid dir Taeung Song
2016-03-27 11:16 ` Jiri Olsa
2016-03-27 15:41   ` Taeung Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox