aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-03-14 11:29:29 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-03-14 11:36:19 -0400
commite7f01d1e3d8d501deb8abeaa269d5d48a703b8b0 (patch)
tree2746465309fd16392ed7c6265dea53366c6e52c7
parentb832796caa1fda8516464a003c8c7cc547bc20c2 (diff)
perf tools: Use scnprintf where applicable
Several places were expecting that the value returned was the number of characters printed, not what would be printed if there was space. Fix it by using the scnprintf and vscnprintf variants we inherited from the kernel sources. Some corner cases where the number of printed characters were not accounted were fixed too. Reported-by: Anton Blanchard <anton@samba.org> Cc: Anton Blanchard <anton@samba.org> Cc: Eric B Munson <emunson@mgebm.net> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com> Cc: stable@kernel.org Link: http://lkml.kernel.org/n/tip-kwxo2eh29cxmd8ilixi2005x@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/arch/powerpc/util/header.c2
-rw-r--r--tools/perf/arch/x86/util/header.c2
-rw-r--r--tools/perf/util/color.c9
-rw-r--r--tools/perf/util/header.c4
-rw-r--r--tools/perf/util/hist.c30
-rw-r--r--tools/perf/util/strbuf.c7
-rw-r--r--tools/perf/util/ui/browsers/hists.c12
-rw-r--r--tools/perf/util/ui/helpline.c2
8 files changed, 35 insertions, 33 deletions
diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c
index eba80c292945..2f7073d107fd 100644
--- a/tools/perf/arch/powerpc/util/header.c
+++ b/tools/perf/arch/powerpc/util/header.c
@@ -25,7 +25,7 @@ get_cpuid(char *buffer, size_t sz)
25 25
26 pvr = mfspr(SPRN_PVR); 26 pvr = mfspr(SPRN_PVR);
27 27
28 nb = snprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr)); 28 nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr));
29 29
30 /* look for end marker to ensure the entire data fit */ 30 /* look for end marker to ensure the entire data fit */
31 if (strchr(buffer, '$')) { 31 if (strchr(buffer, '$')) {
diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c
index f94006068d2b..146d12a1cec0 100644
--- a/tools/perf/arch/x86/util/header.c
+++ b/tools/perf/arch/x86/util/header.c
@@ -48,7 +48,7 @@ get_cpuid(char *buffer, size_t sz)
48 if (family >= 0x6) 48 if (family >= 0x6)
49 model += ((a >> 16) & 0xf) << 4; 49 model += ((a >> 16) & 0xf) << 4;
50 } 50 }
51 nb = snprintf(buffer, sz, "%s,%u,%u,%u$", vendor, family, model, step); 51 nb = scnprintf(buffer, sz, "%s,%u,%u,%u$", vendor, family, model, step);
52 52
53 /* look for end marker to ensure the entire data fit */ 53 /* look for end marker to ensure the entire data fit */
54 if (strchr(buffer, '$')) { 54 if (strchr(buffer, '$')) {
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 ecd7f4dd7eea..14bb035c5fd9 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -280,7 +280,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
280 if (realname == NULL || filename == NULL || linkname == NULL) 280 if (realname == NULL || filename == NULL || linkname == NULL)
281 goto out_free; 281 goto out_free;
282 282
283 len = snprintf(filename, size, "%s%s%s", 283 len = scnprintf(filename, size, "%s%s%s",
284 debugdir, is_kallsyms ? "/" : "", realname); 284 debugdir, is_kallsyms ? "/" : "", realname);
285 if (mkdir_p(filename, 0755)) 285 if (mkdir_p(filename, 0755))
286 goto out_free; 286 goto out_free;
@@ -295,7 +295,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
295 goto out_free; 295 goto out_free;
296 } 296 }
297 297
298 len = snprintf(linkname, size, "%s/.build-id/%.2s", 298 len = scnprintf(linkname, size, "%s/.build-id/%.2s",
299 debugdir, sbuild_id); 299 debugdir, sbuild_id);
300 300
301 if (access(linkname, X_OK) && mkdir_p(linkname, 0755)) 301 if (access(linkname, X_OK) && mkdir_p(linkname, 0755))
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 6f505d1abac7..e11e482bd185 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -768,7 +768,7 @@ static int hist_entry__pcnt_snprintf(struct hist_entry *he, char *s,
768 sep ? "%.2f" : " %6.2f%%", 768 sep ? "%.2f" : " %6.2f%%",
769 (period * 100.0) / total); 769 (period * 100.0) / total);
770 else 770 else
771 ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%", 771 ret = scnprintf(s, size, sep ? "%.2f" : " %6.2f%%",
772 (period * 100.0) / total); 772 (period * 100.0) / total);
773 if (symbol_conf.show_cpu_utilization) { 773 if (symbol_conf.show_cpu_utilization) {
774 ret += percent_color_snprintf(s + ret, size - ret, 774 ret += percent_color_snprintf(s + ret, size - ret,
@@ -791,20 +791,20 @@ static int hist_entry__pcnt_snprintf(struct hist_entry *he, char *s,
791 } 791 }
792 } 792 }
793 } else 793 } else
794 ret = snprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period); 794 ret = scnprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period);
795 795
796 if (symbol_conf.show_nr_samples) { 796 if (symbol_conf.show_nr_samples) {
797 if (sep) 797 if (sep)
798 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events); 798 ret += scnprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events);
799 else 799 else
800 ret += snprintf(s + ret, size - ret, "%11" PRIu64, nr_events); 800 ret += scnprintf(s + ret, size - ret, "%11" PRIu64, nr_events);
801 } 801 }
802 802
803 if (symbol_conf.show_total_period) { 803 if (symbol_conf.show_total_period) {
804 if (sep) 804 if (sep)
805 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period); 805 ret += scnprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period);
806 else 806 else
807 ret += snprintf(s + ret, size - ret, " %12" PRIu64, period); 807 ret += scnprintf(s + ret, size - ret, " %12" PRIu64, period);
808 } 808 }
809 809
810 if (pair_hists) { 810 if (pair_hists) {
@@ -819,25 +819,25 @@ static int hist_entry__pcnt_snprintf(struct hist_entry *he, char *s,
819 diff = new_percent - old_percent; 819 diff = new_percent - old_percent;
820 820
821 if (fabs(diff) >= 0.01) 821 if (fabs(diff) >= 0.01)
822 snprintf(bf, sizeof(bf), "%+4.2F%%", diff); 822 ret += scnprintf(bf, sizeof(bf), "%+4.2F%%", diff);
823 else 823 else
824 snprintf(bf, sizeof(bf), " "); 824 ret += scnprintf(bf, sizeof(bf), " ");
825 825
826 if (sep) 826 if (sep)
827 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); 827 ret += scnprintf(s + ret, size - ret, "%c%s", *sep, bf);
828 else 828 else
829 ret += snprintf(s + ret, size - ret, "%11.11s", bf); 829 ret += scnprintf(s + ret, size - ret, "%11.11s", bf);
830 830
831 if (show_displacement) { 831 if (show_displacement) {
832 if (displacement) 832 if (displacement)
833 snprintf(bf, sizeof(bf), "%+4ld", displacement); 833 ret += scnprintf(bf, sizeof(bf), "%+4ld", displacement);
834 else 834 else
835 snprintf(bf, sizeof(bf), " "); 835 ret += scnprintf(bf, sizeof(bf), " ");
836 836
837 if (sep) 837 if (sep)
838 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); 838 ret += scnprintf(s + ret, size - ret, "%c%s", *sep, bf);
839 else 839 else
840 ret += snprintf(s + ret, size - ret, "%6.6s", bf); 840 ret += scnprintf(s + ret, size - ret, "%6.6s", bf);
841 } 841 }
842 } 842 }
843 843
@@ -855,7 +855,7 @@ int hist_entry__snprintf(struct hist_entry *he, char *s, size_t size,
855 if (se->elide) 855 if (se->elide)
856 continue; 856 continue;
857 857
858 ret += snprintf(s + ret, size - ret, "%s", sep ?: " "); 858 ret += scnprintf(s + ret, size - ret, "%s", sep ?: " ");
859 ret += se->se_snprintf(he, s + ret, size - ret, 859 ret += se->se_snprintf(he, s + ret, size - ret,
860 hists__col_len(hists, se->se_width_idx)); 860 hists__col_len(hists, se->se_width_idx));
861 } 861 }
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 @@