Skip to contentSkip to conversation

perf script: Add missing closedir() calls

PATCH In review Namhyung Kim 1 participant 16 messages Jan 7, 2012 – Jan 9, 2012 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/8 perf script: Add missing closedir() calls

The get_script_path() calls opendir() but misses corresponding closedir()'s. Add them.

---
 tools/perf/builtin-script.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
tools/perf/builtin-script.c +4 -0
index fd1909afcfd6..bb68ddf257b7 100644
@@ -1018,13 +1018,17 @@ static char *get_script_path(const char *script_root, const char *suffix)
 			__script_root = get_script_root(&script_dirent, suffix);
 			if (__script_root && !strcmp(script_root, __script_root)) {
 				free(__script_root);
+				closedir(lang_dir);
+				closedir(scripts_dir);
 				snprintf(script_path, MAXPATHLEN, "%s/%s",
 					 lang_path, script_dirent.d_name);
 				return strdup(script_path);
 			}
 			free(__script_root);
 		}
+		closedir(lang_dir);
 	}
+	closedir(scripts_dir);
 
 	return NULL;
 }
Signature · 1 line
1.7.6
#1 lore raw

PATCH 2/8 perf test: Change type of '-v' option to INCR

The '-v' option is usually defined via OPT_INCR not _INTEGER. Follow the trend :).

---
 tools/perf/builtin-test.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/builtin-test.c +1 -1
index 2b9a7f497a20..3854e869dce1 100644
@@ -1396,7 +1396,7 @@ int cmd_test(int argc, const char **argv, const char *prefix __used)
 	NULL,
 	};
 	const struct option test_options[] = {
-	OPT_INTEGER('v', "verbose", &verbose,
+	OPT_INCR('v', "verbose", &verbose,
 		    "be more verbose (show symbol address, etc)"),
 	OPT_END()
 	};
Signature · 1 line
1.7.6
#2 lore raw

[tip:perf/core] perf test: Change type of '-v' option to INCR

Commit-ID:  c30ab8aa084843159b4679e9a3d7f63187d5906a
Gitweb:     http://git.kernel.org/tip/c30ab8aa084843159b4679e9a3d7f63187d5906a
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sun, 8 Jan 2012 02:25:26 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 8 Jan 2012 13:25:00 -0200

perf test: Change type of '-v' option to INCR

The '-v' option is usually defined via OPT_INCR not _INTEGER. Follow the trend :).

---
 tools/perf/builtin-test.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/builtin-test.c +1 -1
index 2b9a7f4..3854e86 100644
@@ -1396,7 +1396,7 @@ int cmd_test(int argc, const char **argv, const char *prefix __used)
 	NULL,
 	};
 	const struct option test_options[] = {
-	OPT_INTEGER('v', "verbose", &verbose,
+	OPT_INCR('v', "verbose", &verbose,
 		    "be more verbose (show symbol address, etc)"),
 	OPT_END()
 	};
#3 lore raw

PATCH 3/8 perf top: Add error message for EMFILE

In reply to Namhyung Kim

When a user tries to open so many events, perf_event_open syscall may fail with EMFILE. Provide advise for that case.

---
 tools/perf/builtin-top.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
tools/perf/builtin-top.c +4 -0
index 4f81eeb99875..ad18dd37e87d 100644
@@ -889,6 +889,10 @@ try_again:
 				ui__warning("The %s event is not supported.\n",
 					    event_name(counter));
 				goto out_err;
+			} else if (err == EMFILE) {
+				ui__warning("Too many events are opened.\n"
+					    "Try again after reducing the number of events\n");
+				goto out_err;
 			}
 
 			ui__warning("The sys_perf_event_open() syscall "
Signature · 1 line
1.7.6
#4 lore raw

[tip:perf/core] perf top: Add error message for EMFILE

Commit-ID:  cdce445906852d90efdc773ca7ba460e6e41664d
Gitweb:     http://git.kernel.org/tip/cdce445906852d90efdc773ca7ba460e6e41664d
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sun, 8 Jan 2012 02:25:27 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 8 Jan 2012 13:26:11 -0200

perf top: Add error message for EMFILE

When a user tries to open so many events, perf_event_open syscall may fail with EMFILE. Provide advise for that case.

---
 tools/perf/builtin-top.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
tools/perf/builtin-top.c +4 -0
index d89dec9..8f80df8 100644
@@ -888,6 +888,10 @@ try_again:
 				ui__warning("The %s event is not supported.\n",
 					    event_name(counter));
 				goto out_err;
+			} else if (err == EMFILE) {
+				ui__warning("Too many events are opened.\n"
+					    "Try again after reducing the number of events\n");
+				goto out_err;
 			}
 
 			ui__warning("The sys_perf_event_open() syscall "
#5 lore raw

PATCH 4/8 perf kmem: Add missing closedir() calls

In reply to Namhyung Kim

The setup_cpunode_map() calls opendir() but misses corresponding closedir(). Add them.

---
 tools/perf/builtin-kmem.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
tools/perf/builtin-kmem.c +2 -0
index fe1ad8f21961..7a9b5c55ad5a 100644
@@ -108,7 +108,9 @@ static void setup_cpunode_map(void)
 				continue;
 			cpunode_map[cpu] = mem;
 		}
+		closedir(dir2);
 	}
+	closedir(dir1);
 }
 
 static void insert_alloc_stat(unsigned long call_site, unsigned long ptr,
Signature · 1 line
1.7.6
#6 lore raw

[tip:perf/core] perf kmem: Add missing closedir() calls

Commit-ID:  8442da1d9f445b454accdb148355ee990ebf3b32
Gitweb:     http://git.kernel.org/tip/8442da1d9f445b454accdb148355ee990ebf3b32
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sun, 8 Jan 2012 02:25:28 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 8 Jan 2012 13:27:06 -0200

perf kmem: Add missing closedir() calls

The setup_cpunode_map() calls opendir() but misses corresponding closedir(). Add them.

---
 tools/perf/builtin-kmem.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
tools/perf/builtin-kmem.c +2 -0
index fe1ad8f..7a9b5c5 100644
@@ -108,7 +108,9 @@ static void setup_cpunode_map(void)
 				continue;
 			cpunode_map[cpu] = mem;
 		}
+		closedir(dir2);
 	}
+	closedir(dir1);
 }
 
 static void insert_alloc_stat(unsigned long call_site, unsigned long ptr,
#7 lore raw

PATCH 5/8 perf kmem: Fix a memory leak

In reply to Namhyung Kim

The 'str' should be freed when sort_dimension__add() failed too.

---
 tools/perf/builtin-kmem.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
tools/perf/builtin-kmem.c +1 -0
index 7a9b5c55ad5a..39104c0beea3 100644
@@ -647,6 +647,7 @@ static int setup_sorting(struct list_head *sort_list, const char *arg)
 			break;
 		if (sort_dimension__add(tok, sort_list) < 0) {
 			error("Unknown --sort key: '%s'", tok);
+			free(str);
 			return -1;
 		}
 	}
Signature · 1 line
1.7.6
#8 lore raw

[tip:perf/core] perf kmem: Fix a memory leak

Commit-ID:  1b22859d4320d472a7a51ff4a43f62b0578469de
Gitweb:     http://git.kernel.org/tip/1b22859d4320d472a7a51ff4a43f62b0578469de
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sun, 8 Jan 2012 02:25:29 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 8 Jan 2012 13:27:54 -0200

perf kmem: Fix a memory leak

The 'str' should be freed when sort_dimension__add() failed too.

---
 tools/perf/builtin-kmem.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
tools/perf/builtin-kmem.c +1 -0
index 7a9b5c5..39104c0 100644
@@ -647,6 +647,7 @@ static int setup_sorting(struct list_head *sort_list, const char *arg)
 			break;
 		if (sort_dimension__add(tok, sort_list) < 0) {
 			error("Unknown --sort key: '%s'", tok);
+			free(str);
 			return -1;
 		}
 	}
#9 lore raw

PATCH 6/8 perf annotate: Fix usage string

In reply to Namhyung Kim

The annotate command doesn't take non-option arguments. In fact, it can take last argument as a symbol filter though, but that's a special case and, IMHO, it should be discouraged in favor of the -s option.

---
 tools/perf/builtin-annotate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/builtin-annotate.c +1 -1
index 214ba7f9f577..3ec2496f1e35 100644
@@ -235,7 +235,7 @@ out_delete:
 }
 
 static const char * const annotate_usage[] = {
-	"perf annotate [<options>] <command>",
+	"perf annotate [<options>]",
 	NULL
 };
 
Signature · 1 line
1.7.6
#10 lore raw

[tip:perf/core] perf annotate: Fix usage string

Commit-ID:  993452541796f3637da9f2e537b9333494b3b2a1
Gitweb:     http://git.kernel.org/tip/993452541796f3637da9f2e537b9333494b3b2a1
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sun, 8 Jan 2012 02:25:30 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 8 Jan 2012 13:28:48 -0200

perf annotate: Fix usage string

The annotate command doesn't take non-option arguments.

In fact, it can take last argument as a symbol filter though, but that's a special case and, IMHO, it should be discouraged in favor of the -s option.

---
 tools/perf/builtin-annotate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/builtin-annotate.c +1 -1
index 214ba7f..3ec2496 100644
@@ -235,7 +235,7 @@ out_delete:
 }
 
 static const char * const annotate_usage[] = {
-	"perf annotate [<options>] <command>",
+	"perf annotate [<options>]",
 	NULL
 };
 
#11 lore raw

PATCH 7/8 perf annotate: Get rid of field_sep check

In reply to Namhyung Kim

The 'field_sep' variable is not set anywhere. Just remove the conditional.

---
 tools/perf/builtin-annotate.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
tools/perf/builtin-annotate.c +0 -5
index 3ec2496f1e35..806e0a286634 100644
@@ -313,10 +313,5 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used)
 		annotate.sym_hist_filter = argv[0];
 	}
 
-	if (field_sep && *field_sep == '.') {
-		pr_err("'.' is the only non valid --field-separator argument\n");
-		return -1;
-	}
-
 	return __cmd_annotate(&annotate);
 }
Signature · 1 line
1.7.6
#12 lore raw

[tip:perf/core] perf annotate: Get rid of field_sep check

Commit-ID:  6714a04114639350a7fed93edf8e1b995c5e8059
Gitweb:     http://git.kernel.org/tip/6714a04114639350a7fed93edf8e1b995c5e8059
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sun, 8 Jan 2012 02:25:31 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 8 Jan 2012 13:29:34 -0200

perf annotate: Get rid of field_sep check

The 'field_sep' variable is not set anywhere. Just remove the conditional.

---
 tools/perf/builtin-annotate.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
tools/perf/builtin-annotate.c +0 -5
index 3ec2496..806e0a2 100644
@@ -313,10 +313,5 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used)
 		annotate.sym_hist_filter = argv[0];
 	}
 
-	if (field_sep && *field_sep == '.') {
-		pr_err("'.' is the only non valid --field-separator argument\n");
-		return -1;
-	}
-
 	return __cmd_annotate(&annotate);
 }
#13 lore raw

PATCH 8/8 perf report: Fix --stdio output alignment when --showcpuutilization used

In reply to Namhyung Kim

Current perf report output is broken if --showcpuutilization is used. Combination with -n and/or --show-total-period make things worse. This patch fixes it as follows:

before:
# Events: 13 cycles
#
# Overhead sys us Command Shared Object Symbol

# ........  .......  .................  .....................
#
    48.25%    48.25%     0.00%    sleep  [kernel.kallsyms]  [k] trace_hardirqs_off
    34.99%    34.99%     0.00%    sleep  [kernel.kallsyms]  [k] __find_get_block_slow
    15.99%    15.99%     0.00%    sleep  [kernel.kallsyms]  [k] lock_release_holdtime
     0.77%     0.77%     0.00%    sleep  [kernel.kallsyms]  [k] native_write_msr_safe

after:
# Events: 13 cycles
#
# Overhead sys us Command Shared Object Symbol

# ........   .......   .......  .......  .................  .....................
#
    48.25%    48.25%     0.00%    sleep  [kernel.kallsyms]  [k] trace_hardirqs_off
    34.99%    34.99%     0.00%    sleep  [kernel.kallsyms]  [k] __find_get_block_slow
    15.99%    15.99%     0.00%    sleep  [kernel.kallsyms]  [k] lock_release_holdtime
     0.77%     0.77%     0.00%    sleep  [kernel.kallsyms]  [k] native_write_msr_safe
---
 tools/perf/util/hist.c |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)
tools/perf/util/hist.c +18 -16
index abef2703cd24..7561d5c90d98 100644
@@ -917,20 +917,6 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
 
 	fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
 
-	if (symbol_conf.show_nr_samples) {
-		if (sep)
-			fprintf(fp, "%cSamples", *sep);
-		else
-			fputs("  Samples  ", fp);
-	}
-
-	if (symbol_conf.show_total_period) {
-		if (sep)
-			ret += fprintf(fp, "%cPeriod", *sep);
-		else
-			ret += fprintf(fp, "   Period    ");
-	}
-
 	if (symbol_conf.show_cpu_utilization) {
 		if (sep) {
 			ret += fprintf(fp, "%csys", *sep);
@@ -940,8 +926,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
 				ret += fprintf(fp, "%cguest us", *sep);
 			}
 		} else {
-			ret += fprintf(fp, "  sys  ");
-			ret += fprintf(fp, "  us  ");
+			ret += fprintf(fp, "     sys  ");
+			ret += fprintf(fp, "      us  ");
 			if (perf_guest) {
 				ret += fprintf(fp, "  guest sys  ");
 				ret += fprintf(fp, "  guest us  ");
@@ -949,6 +935,20 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
 		}
 	}
 
+	if (symbol_conf.show_nr_samples) {
+		if (sep)
+			fprintf(fp, "%cSamples", *sep);
+		else
+			fputs("  Samples  ", fp);
+	}
+
+	if (symbol_conf.show_total_period) {
+		if (sep)
+			ret += fprintf(fp, "%cPeriod", *sep);
+		else
+			ret += fprintf(fp, "   Period    ");
+	}
+
 	if (pair) {
 		if (sep)
 			ret += fprintf(fp, "%cDelta", *sep);
@@ -993,6 +993,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
 		goto print_entries;
 
 	fprintf(fp, "# ........");
+	if (symbol_conf.show_cpu_utilization)
+		fprintf(fp, "   .......   .......");
 	if (symbol_conf.show_nr_samples)
 		fprintf(fp, " ..........");
 	if (symbol_conf.show_total_period)
Signature · 1 line
1.7.6
#14 lore raw

[tip:perf/core] perf report: Fix --stdio output alignment when --showcpuutilization used

Commit-ID:  0ed35abc2b569e94498705d250c4767c5284f643
Gitweb:     http://git.kernel.org/tip/0ed35abc2b569e94498705d250c4767c5284f643
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sun, 8 Jan 2012 02:25:32 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 8 Jan 2012 13:32:51 -0200

perf report: Fix --stdio output alignment when --showcpuutilization used

Current perf report output is broken if --showcpuutilization is used. Combination with -n and/or --show-total-period make things worse. This patch fixes it as follows:

before:

    48.25%    48.25%     0.00%    sleep  [kernel.kallsyms]  [k] trace_hardirqs_off
    34.99%    34.99%     0.00%    sleep  [kernel.kallsyms]  [k] __find_get_block_slow
    15.99%    15.99%     0.00%    sleep  [kernel.kallsyms]  [k] lock_release_holdtime
     0.77%     0.77%     0.00%    sleep  [kernel.kallsyms]  [k] native_write_msr_safe

after:

    48.25%    48.25%     0.00%    sleep  [kernel.kallsyms]  [k] trace_hardirqs_off
    34.99%    34.99%     0.00%    sleep  [kernel.kallsyms]  [k] __find_get_block_slow
    15.99%    15.99%     0.00%    sleep  [kernel.kallsyms]  [k] lock_release_holdtime
     0.77%     0.77%     0.00%    sleep  [kernel.kallsyms]  [k] native_write_msr_safe
---
 tools/perf/util/hist.c |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)
tools/perf/util/hist.c +18 -16
index 4df4495..6f505d1 100644
@@ -919,20 +919,6 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
 
 	fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
 
-	if (symbol_conf.show_nr_samples) {
-		if (sep)
-			fprintf(fp, "%cSamples", *sep);
-		else
-			fputs("  Samples  ", fp);
-	}
-
-	if (symbol_conf.show_total_period) {
-		if (sep)
-			ret += fprintf(fp, "%cPeriod", *sep);
-		else
-			ret += fprintf(fp, "   Period    ");
-	}
-
 	if (symbol_conf.show_cpu_utilization) {
 		if (sep) {
 			ret += fprintf(fp, "%csys", *sep);
@@ -942,8 +928,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
 				ret += fprintf(fp, "%cguest us", *sep);
 			}
 		} else {
-			ret += fprintf(fp, "  sys  ");
-			ret += fprintf(fp, "  us  ");
+			ret += fprintf(fp, "     sys  ");
+			ret += fprintf(fp, "      us  ");
 			if (perf_guest) {
 				ret += fprintf(fp, "  guest sys  ");
 				ret += fprintf(fp, "  guest us  ");
@@ -951,6 +937,20 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
 		}
 	}
 
+	if (symbol_conf.show_nr_samples) {
+		if (sep)
+			fprintf(fp, "%cSamples", *sep);
+		else
+			fputs("  Samples  ", fp);
+	}
+
+	if (symbol_conf.show_total_period) {
+		if (sep)
+			ret += fprintf(fp, "%cPeriod", *sep);
+		else
+			ret += fprintf(fp, "   Period    ");
+	}
+
 	if (pair) {
 		if (sep)
 			ret += fprintf(fp, "%cDelta", *sep);
@@ -995,6 +995,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
 		goto print_entries;
 
 	fprintf(fp, "# ........");
+	if (symbol_conf.show_cpu_utilization)
+		fprintf(fp, "   .......   .......");
 	if (symbol_conf.show_nr_samples)
 		fprintf(fp, " ..........");
 	if (symbol_conf.show_total_period)
#15 lore raw
In reply to Namhyung Kim
Commit-ID:  946ef2a24523e59e5cf931068ab7e9443c63c9df
Gitweb:     http://git.kernel.org/tip/946ef2a24523e59e5cf931068ab7e9443c63c9df
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sun, 8 Jan 2012 02:25:25 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 8 Jan 2012 12:35:41 -0200

perf script: Add missing closedir() calls

The get_script_path() calls opendir() but misses corresponding closedir()'s. Add them.

---
 tools/perf/builtin-script.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
tools/perf/builtin-script.c +4 -0
index fd1909a..bb68ddf 100644
@@ -1018,13 +1018,17 @@ static char *get_script_path(const char *script_root, const char *suffix)
 			__script_root = get_script_root(&script_dirent, suffix);
 			if (__script_root && !strcmp(script_root, __script_root)) {
 				free(__script_root);
+				closedir(lang_dir);
+				closedir(scripts_dir);
 				snprintf(script_path, MAXPATHLEN, "%s/%s",
 					 lang_path, script_dirent.d_name);
 				return strdup(script_path);
 			}
 			free(__script_root);
 		}
+		closedir(lang_dir);
 	}
+	closedir(scripts_dir);
 
 	return NULL;
 }