diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-03-22 14:09:08 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-03-22 14:09:08 -0400 |
commit | 0d09eb7a9a2ca4d7ed32f7b440bea78c0622814a (patch) | |
tree | 177871323b183610017c65c68f0bde9af2f37f47 /tools/perf/util | |
parent | 9521d830b6341d1887dcfc2aebde23fbfa5f1473 (diff) | |
parent | 89c5bd08df5841326abbf167d136bcf14cf759ed (diff) |
Merge branch 'perf/urgent' into perf/core
Merge Reason: to pick the fix:
commit e7f01d1
perf tools: Use scnprintf where applicable
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/color.c | 9 | ||||
-rw-r--r-- | tools/perf/util/header.c | 4 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 30 | ||||
-rw-r--r-- | tools/perf/util/include/asm/unistd_32.h | 1 | ||||
-rw-r--r-- | tools/perf/util/include/asm/unistd_64.h | 1 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 2 | ||||
-rw-r--r-- | tools/perf/util/sort.c | 3 | ||||
-rw-r--r-- | tools/perf/util/strbuf.c | 7 | ||||
-rw-r--r-- | tools/perf/util/ui/browsers/hists.c | 12 | ||||
-rw-r--r-- | tools/perf/util/ui/helpline.c | 2 |
10 files changed, 39 insertions, 32 deletions
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c index 521c38a79190..11e46da17bbb 100644 --- a/tools/perf/util/color.c +++ b/tools/perf/util/color.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <linux/kernel.h> | ||
1 | #include "cache.h" | 2 | #include "cache.h" |
2 | #include "color.h" | 3 | #include "color.h" |
3 | 4 | ||
@@ -182,12 +183,12 @@ static int __color_vsnprintf(char *bf, size_t size, const char *color, | |||
182 | } | 183 | } |
183 | 184 | ||
184 | if (perf_use_color_default && *color) | 185 | if (perf_use_color_default && *color) |
185 | r += snprintf(bf, size, "%s", color); | 186 | r += scnprintf(bf, size, "%s", color); |
186 | r += vsnprintf(bf + r, size - r, fmt, args); | 187 | r += vscnprintf(bf + r, size - r, fmt, args); |
187 | if (perf_use_color_default && *color) | 188 | if (perf_use_color_default && *color) |
188 | r += snprintf(bf + r, size - r, "%s", PERF_COLOR_RESET); | 189 | r += scnprintf(bf + r, size - r, "%s", PERF_COLOR_RESET); |
189 | if (trail) | 190 | if (trail) |
190 | r += snprintf(bf + r, size - r, "%s", trail); | 191 | r += scnprintf(bf + r, size - r, "%s", trail); |
191 | return r; | 192 | return r; |
192 | } | 193 | } |
193 | 194 | ||
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 0d9b6da86a39..fcd9cf3ea63e 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -291,7 +291,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, | |||
291 | if (realname == NULL || filename == NULL || linkname == NULL) | 291 | if (realname == NULL || filename == NULL || linkname == NULL) |
292 | goto out_free; | 292 | goto out_free; |
293 | 293 | ||
294 | len = snprintf(filename, size, "%s%s%s", | 294 | len = scnprintf(filename, size, "%s%s%s", |
295 | debugdir, is_kallsyms ? "/" : "", realname); | 295 | debugdir, is_kallsyms ? "/" : "", realname); |
296 | if (mkdir_p(filename, 0755)) | 296 | if (mkdir_p(filename, 0755)) |
297 | goto out_free; | 297 | goto out_free; |
@@ -306,7 +306,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, | |||
306 | goto out_free; | 306 | goto out_free; |
307 | } | 307 | } |
308 | 308 | ||
309 | len = snprintf(linkname, size, "%s/.build-id/%.2s", | 309 | len = scnprintf(linkname, size, "%s/.build-id/%.2s", |
310 | debugdir, sbuild_id); | 310 | debugdir, sbuild_id); |
311 | 311 | ||
312 | if (access(linkname, X_OK) && mkdir_p(linkname, 0755)) | 312 | if (access(linkname, X_OK) && mkdir_p(linkname, 0755)) |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 2c624ad371a7..5fb19013ca0c 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -840,7 +840,7 @@ static int hist_entry__pcnt_snprintf(struct hist_entry *he, char *s, | |||
840 | sep ? "%.2f" : " %6.2f%%", | 840 | sep ? "%.2f" : " %6.2f%%", |
841 | (period * 100.0) / total); | 841 | (period * 100.0) / total); |
842 | else | 842 | else |
843 | ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%", | 843 | ret = scnprintf(s, size, sep ? "%.2f" : " %6.2f%%", |
844 | (period * 100.0) / total); | 844 | (period * 100.0) / total); |
845 | if (symbol_conf.show_cpu_utilization) { | 845 | if (symbol_conf.show_cpu_utilization) { |
846 | ret += percent_color_snprintf(s + ret, size - ret, | 846 | ret += percent_color_snprintf(s + ret, size - ret, |
@@ -863,20 +863,20 @@ static int hist_entry__pcnt_snprintf(struct hist_entry *he, char *s, | |||
863 | } | 863 | } |
864 | } | 864 | } |
865 | } else | 865 | } else |
866 | ret = snprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period); | 866 | ret = scnprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period); |
867 | 867 | ||
868 | if (symbol_conf.show_nr_samples) { | 868 | if (symbol_conf.show_nr_samples) { |
869 | if (sep) | 869 | if (sep) |
870 | ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events); | 870 | ret += scnprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events); |
871 | else | 871 | else |
872 | ret += snprintf(s + ret, size - ret, "%11" PRIu64, nr_events); | 872 | ret += scnprintf(s + ret, size - ret, "%11" PRIu64, nr_events); |
873 | } | 873 | } |
874 | 874 | ||
875 | if (symbol_conf.show_total_period) { | 875 | if (symbol_conf.show_total_period) { |
876 | if (sep) | 876 | if (sep) |
877 | ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period); | 877 | ret += scnprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period); |
878 | else | 878 | else |
879 | ret += snprintf(s + ret, size - ret, " %12" PRIu64, period); | 879 | ret += scnprintf(s + ret, size - ret, " %12" PRIu64, period); |
880 | } | 880 | } |
881 | 881 | ||
882 | if (pair_hists) { | 882 | if (pair_hists) { |
@@ -891,25 +891,25 @@ static int hist_entry__pcnt_snprintf(struct hist_entry *he, char *s, | |||
891 | diff = new_percent - old_percent; | 891 | diff = new_percent - old_percent; |
892 | 892 | ||
893 | if (fabs(diff) >= 0.01) | 893 | if (fabs(diff) >= 0.01) |
894 | snprintf(bf, sizeof(bf), "%+4.2F%%", diff); | 894 | ret += scnprintf(bf, sizeof(bf), "%+4.2F%%", diff); |
895 | else | 895 | else |
896 | snprintf(bf, sizeof(bf), " "); | 896 | ret += scnprintf(bf, sizeof(bf), " "); |
897 | 897 | ||
898 | if (sep) | 898 | if (sep) |
899 | ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); | 899 | ret += scnprintf(s + ret, size - ret, "%c%s", *sep, bf); |
900 | else | 900 | else |
901 | ret += snprintf(s + ret, size - ret, "%11.11s", bf); | 901 | ret += scnprintf(s + ret, size - ret, "%11.11s", bf); |
902 | 902 | ||
903 | if (show_displacement) { | 903 | if (show_displacement) { |
904 | if (displacement) | 904 | if (displacement) |
905 | snprintf(bf, sizeof(bf), "%+4ld", displacement); | 905 | ret += scnprintf(bf, sizeof(bf), "%+4ld", displacement); |
906 | else | 906 | else |
907 | snprintf(bf, sizeof(bf), " "); | 907 | ret += scnprintf(bf, sizeof(bf), " "); |
908 | 908 | ||
909 | if (sep) | 909 | if (sep) |
910 | ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); | 910 | ret += scnprintf(s + ret, size - ret, "%c%s", *sep, bf); |
911 | else | 911 | else |
912 | ret += snprintf(s + ret, size - ret, "%6.6s", bf); | 912 | ret += scnprintf(s + ret, size - ret, "%6.6s", bf); |
913 | } | 913 | } |
914 | } | 914 | } |
915 | 915 | ||
@@ -927,7 +927,7 @@ int hist_entry__snprintf(struct hist_entry *he, char *s, size_t size, | |||
927 | if (se->elide) | 927 | if (se->elide) |
928 | continue; | 928 | continue; |
929 | 929 | ||
930 | ret += snprintf(s + ret, size - ret, "%s", sep ?: " "); | 930 | ret += scnprintf(s + ret, size - ret, "%s", sep ?: " "); |
931 | ret += se->se_snprintf(he, s + ret, size - ret, | 931 | ret += se->se_snprintf(he, s + ret, size - ret, |
932 | hists__col_len(hists, se->se_width_idx)); | 932 | hists__col_len(hists, se->se_width_idx)); |
933 | } | 933 | } |
diff --git a/tools/perf/util/include/asm/unistd_32.h b/tools/perf/util/include/asm/unistd_32.h new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/tools/perf/util/include/asm/unistd_32.h | |||
@@ -0,0 +1 @@ | |||
diff --git a/tools/perf/util/include/asm/unistd_64.h b/tools/perf/util/include/asm/unistd_64.h new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/tools/perf/util/include/asm/unistd_64.h | |||
@@ -0,0 +1 @@ | |||
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index bec1cc6a1f38..201b40f0ca0b 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -165,7 +165,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) | |||
165 | struct tracepoint_path *path = NULL; | 165 | struct tracepoint_path *path = NULL; |
166 | DIR *sys_dir, *evt_dir; | 166 | DIR *sys_dir, *evt_dir; |
167 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | 167 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
168 | char id_buf[4]; | 168 | char id_buf[24]; |
169 | int fd; | 169 | int fd; |
170 | u64 id; | 170 | u64 id; |
171 | char evt_path[MAXPATHLEN]; | 171 | char evt_path[MAXPATHLEN]; |
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 88dbcf6f9575..a27237430c5f 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
@@ -34,6 +34,9 @@ static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...) | |||
34 | } | 34 | } |
35 | } | 35 | } |
36 | va_end(ap); | 36 | va_end(ap); |
37 | |||
38 | if (n >= (int)size) | ||
39 | return size - 1; | ||
37 | return n; | 40 | return n; |
38 | } | 41 | } |
39 | 42 | ||
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c index 92e068517c1a..2eeb51baf077 100644 --- a/tools/perf/util/strbuf.c +++ b/tools/perf/util/strbuf.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include "cache.h" | 1 | #include "cache.h" |
2 | #include <linux/kernel.h> | ||
2 | 3 | ||
3 | int prefixcmp(const char *str, const char *prefix) | 4 | int prefixcmp(const char *str, const char *prefix) |
4 | { | 5 | { |
@@ -89,14 +90,14 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...) | |||
89 | if (!strbuf_avail(sb)) | 90 | if (!strbuf_avail(sb)) |
90 | strbuf_grow(sb, 64); | 91 | strbuf_grow(sb, 64); |
91 | va_start(ap, fmt); | 92 | va_start(ap, fmt); |
92 | len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); | 93 | len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); |
93 | va_end(ap); | 94 | va_end(ap); |
94 | if (len < 0) | 95 | if (len < 0) |
95 | die("your vsnprintf is broken"); | 96 | die("your vscnprintf is broken"); |
96 | if (len > strbuf_avail(sb)) { | 97 | if (len > strbuf_avail(sb)) { |
97 | strbuf_grow(sb, len); | 98 | strbuf_grow(sb, len); |
98 | va_start(ap, fmt); | 99 | va_start(ap, fmt); |
99 | len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); | 100 | len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); |
100 | va_end(ap); | 101 | va_end(ap); |
101 | if (len > strbuf_avail(sb)) { | 102 | if (len > strbuf_avail(sb)) { |
102 | die("this should not happen, your snprintf is broken"); | 103 | die("this should not happen, your snprintf is broken"); |
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c index c4173c9733bb..d7a1c4afe28b 100644 --- a/tools/perf/util/ui/browsers/hists.c +++ b/tools/perf/util/ui/browsers/hists.c | |||
@@ -840,18 +840,18 @@ static int hists__browser_title(struct hists *self, char *bf, size_t size, | |||
840 | unsigned long nr_events = self->stats.nr_events[PERF_RECORD_SAMPLE]; | 840 | unsigned long nr_events = self->stats.nr_events[PERF_RECORD_SAMPLE]; |
841 | 841 | ||
842 | nr_events = convert_unit(nr_events, &unit); | 842 | nr_events = convert_unit(nr_events, &unit); |
843 | printed = snprintf(bf, size, "Events: %lu%c %s", nr_events, unit, ev_name); | 843 | printed = scnprintf(bf, size, "Events: %lu%c %s", nr_events, unit, ev_name); |
844 | 844 | ||
845 | if (self->uid_filter_str) | 845 | if (self->uid_filter_str) |
846 | printed += snprintf(bf + printed, size - printed, | 846 | printed += snprintf(bf + printed, size - printed, |
847 | ", UID: %s", self->uid_filter_str); | 847 | ", UID: %s", self->uid_filter_str); |
848 | if (thread) | 848 | if (thread) |
849 | printed += snprintf(bf + printed, size - printed, | 849 | printed += scnprintf(bf + printed, size - printed, |
850 | ", Thread: %s(%d)", | 850 | ", Thread: %s(%d)", |
851 | (thread->comm_set ? thread->comm : ""), | 851 | (thread->comm_set ? thread->comm : ""), |
852 | thread->pid); | 852 | thread->pid); |
853 | if (dso) | 853 | if (dso) |
854 | printed += snprintf(bf + printed, size - printed, | 854 | printed += scnprintf(bf + printed, size - printed, |
855 | ", DSO: %s", dso->short_name); | 855 | ", DSO: %s", dso->short_name); |
856 | return printed; | 856 | return printed; |
857 | } | 857 | } |
@@ -1174,7 +1174,7 @@ static void perf_evsel_menu__write(struct ui_browser *browser, | |||
1174 | HE_COLORSET_NORMAL); | 1174 | HE_COLORSET_NORMAL); |
1175 | 1175 | ||
1176 | nr_events = convert_unit(nr_events, &unit); | 1176 | nr_events = convert_unit(nr_events, &unit); |
1177 | printed = snprintf(bf, sizeof(bf), "%lu%c%s%s", nr_events, | 1177 | printed = scnprintf(bf, sizeof(bf), "%lu%c%s%s", nr_events, |
1178 | unit, unit == ' ' ? "" : " ", ev_name); | 1178 | unit, unit == ' ' ? "" : " ", ev_name); |
1179 | slsmg_printf("%s", bf); | 1179 | slsmg_printf("%s", bf); |
1180 | 1180 | ||
@@ -1184,8 +1184,8 @@ static void perf_evsel_menu__write(struct ui_browser *browser, | |||
1184 | if (!current_entry) | 1184 | if (!current_entry) |
1185 | ui_browser__set_color(browser, HE_COLORSET_TOP); | 1185 | ui_browser__set_color(browser, HE_COLORSET_TOP); |
1186 | nr_events = convert_unit(nr_events, &unit); | 1186 | nr_events = convert_unit(nr_events, &unit); |
1187 | snprintf(bf, sizeof(bf), ": %ld%c%schunks LOST!", nr_events, | 1187 | printed += scnprintf(bf, sizeof(bf), ": %ld%c%schunks LOST!", |
1188 | unit, unit == ' ' ? "" : " "); | 1188 | nr_events, unit, unit == ' ' ? "" : " "); |
1189 | warn = bf; | 1189 | warn = bf; |
1190 | } | 1190 | } |
1191 | 1191 | ||
diff --git a/tools/perf/util/ui/helpline.c b/tools/perf/util/ui/helpline.c index 4f48f5901b30..2f950c2641c8 100644 --- a/tools/perf/util/ui/helpline.c +++ b/tools/perf/util/ui/helpline.c | |||
@@ -64,7 +64,7 @@ int ui_helpline__show_help(const char *format, va_list ap) | |||
64 | static int backlog; | 64 | static int backlog; |
65 | 65 | ||
66 | pthread_mutex_lock(&ui__lock); | 66 | pthread_mutex_lock(&ui__lock); |
67 | ret = vsnprintf(ui_helpline__last_msg + backlog, | 67 | ret = vscnprintf(ui_helpline__last_msg + backlog, |
68 | sizeof(ui_helpline__last_msg) - backlog, format, ap); | 68 | sizeof(ui_helpline__last_msg) - backlog, format, ap); |
69 | backlog += ret; | 69 | backlog += ret; |
70 | 70 | ||