[PATCH 4/7] perf hists: Handle field separator properly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Namhyung Kim <namhyung.kim@xxxxxxx>

When a field separator is given, the output format doesn't need to be
fancy like aligning to column length, coloring the percent value and
so on. And since there's a slight difference to normal format, fix it
not to break backward compatibility.

Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
 tools/perf/ui/hist.c       | 42 ++++++++++++++++++++++++++++++++++++++++--
 tools/perf/ui/stdio/hist.c |  3 ++-
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 8062b38f7971..29c787c93452 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -30,6 +30,10 @@ static int hpp_entry_overhead(struct hpp_context *ctx,
 			      struct hist_entry *he)
 {
 	double percent = 100.0 * he->period / ctx->total_period;
+
+	if (symbol_conf.field_sep)
+		return scnprintf(ctx->s, ctx->size, "%.2f", percent);
+
 	return scnprintf(ctx->s, ctx->size, "  %5.2f%%", percent);
 }
 
@@ -54,6 +58,10 @@ static int hpp_entry_overhead_sys(struct hpp_context *ctx,
 				  struct hist_entry *he)
 {
 	double percent = 100.0 * he->period_sys / ctx->total_period;
+
+	if (symbol_conf.field_sep)
+		return scnprintf(ctx->s, ctx->size, "%.2f", percent);
+
 	return scnprintf(ctx->s, ctx->size, "%5.2f%%", percent);
 }
 
@@ -78,6 +86,10 @@ static int hpp_entry_overhead_us(struct hpp_context *ctx,
 				 struct hist_entry *he)
 {
 	double percent = 100.0 * he->period_us / ctx->total_period;
+
+	if (symbol_conf.field_sep)
+		return scnprintf(ctx->s, ctx->size, "%.2f", percent);
+
 	return scnprintf(ctx->s, ctx->size, "%5.2f%%", percent);
 }
 
@@ -102,6 +114,10 @@ static int hpp_entry_overhead_guest_sys(struct hpp_context *ctx,
 					struct hist_entry *he)
 {
 	double percent = 100.0 * he->period_guest_sys / ctx->total_period;
+
+	if (symbol_conf.field_sep)
+		return scnprintf(ctx->s, ctx->size, "%.2f", percent);
+
 	return scnprintf(ctx->s, ctx->size, "  %5.2f%% ", percent);
 }
 
@@ -126,6 +142,10 @@ static int hpp_entry_overhead_guest_us(struct hpp_context *ctx,
 				       struct hist_entry *he)
 {
 	double percent = 100.0 * he->period_guest_us / ctx->total_period;
+
+	if (symbol_conf.field_sep)
+		return scnprintf(ctx->s, ctx->size, "%.2f", percent);
+
 	return scnprintf(ctx->s, ctx->size, "  %5.2f%% ", percent);
 }
 
@@ -142,6 +162,9 @@ static int hpp_width_samples(struct hpp_context *ctx __used)
 static int hpp_entry_samples(struct hpp_context *ctx,
 			     struct hist_entry *he)
 {
+	if (symbol_conf.field_sep)
+		return scnprintf(ctx->s, ctx->size, "%" PRIu64, he->nr_events);
+
 	return scnprintf(ctx->s, ctx->size, "%11" PRIu64, he->nr_events);
 }
 
@@ -158,6 +181,9 @@ static int hpp_width_period(struct hpp_context *ctx __used)
 static int hpp_entry_period(struct hpp_context *ctx,
 			    struct hist_entry *he)
 {
+	if (symbol_conf.field_sep)
+		return scnprintf(ctx->s, ctx->size, "%" PRIu64, he->period);
+
 	return scnprintf(ctx->s, ctx->size, "%12" PRIu64, he->period);
 }
 
@@ -189,10 +215,16 @@ static int hpp_entry_delta(struct hpp_context *ctx,
 		new_percent = 100.0 * he->period / new_total;
 
 	diff = new_percent - old_percent;
-	if (fabs(diff) < 0.01)
+	if (fabs(diff) < 0.01) {
+		if (symbol_conf.field_sep)
+			return scnprintf(ctx->s, ctx->size, " ");
 		return scnprintf(ctx->s, ctx->size, "       ");
+	}
 
 	scnprintf(buf, sizeof(buf), "%+4.2F%%", diff);
+
+	if (symbol_conf.field_sep)
+		scnprintf(ctx->s, ctx->size, "%s", buf);
 	return scnprintf(ctx->s, ctx->size, "%7.7s", buf);
 }
 
@@ -211,10 +243,16 @@ static int hpp_entry_displ(struct hpp_context *ctx,
 {
 	char buf[32];
 
-	if (!ctx->displacement)
+	if (!ctx->displacement) {
+		if (symbol_conf.field_sep)
+			return scnprintf(ctx->s, ctx->size, " ");
 		return scnprintf(ctx->s, ctx->size, "     ");
+	}
 
 	scnprintf(buf, sizeof(buf), "%+4ld", ctx->displacement);
+
+	if (symbol_conf.field_sep)
+		scnprintf(ctx->s, ctx->size, "%s", buf);
 	return scnprintf(ctx->s, ctx->size, "%6.6s", buf);
 }
 
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index c040b03cc6f4..0712fb5c1bb7 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -319,11 +319,12 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
 		.displacement	= displacement,
 		.ptr		= pair_hists,
 	};
+	bool color = !symbol_conf.field_sep;
 
 	if (size == 0 || size > sizeof(bf))
 		size = ctx.size = sizeof(bf);
 
-	ret = hist_entry__period_snprintf(&ctx, he, true);
+	ret = hist_entry__period_snprintf(&ctx, he, color);
 	hist_entry__sort_snprintf(he, bf + ret, size - ret, hists);
 
 	ret = fprintf(fp, "%s\n", bf);
-- 
1.7.11.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[Other Archives]     [Linux Kernel Newbies]     [Linux Driver Development]     [Linux Kbuild]     [Fedora Kernel]     [Linux Kernel Testers]     [Linux SH]     [Linux Omap]     [Linux Tape]     [Linux Input]     [Linux LEDS]     [Linux Kernel Janitors]     [Linux Kernel Packagers]     [Linux Doc]     [Linux Man Pages]     [Linux API]     [Linux Memory Management]     [Linux Modules]     [Linux Standards]     [Kernel Announce]     [Netdev]     [Git]     [Linux PCI]     Linux CAN Development     [Linux I2C]     [Linux RDMA]     [Linux NUMA]     [Netfilter]     [Netfilter Devel]     [SELinux]     [Bugtraq]     [FIO]     [Linux Perf Users]     [Linux Serial]     [Linux PPP]     [Linux ISDN]     [Linux Next]     [Kernel Stable Commits]     [Linux Tip Commits]     [Kernel MM Commits]     [Linux Security Module]     [AutoFS]     [Filesystem Development]     [Ext3 Filesystem]     [Linux bcache]     [Ext4 Filesystem]     [Linux BTRFS]     [Linux CEPH Filesystem]     [Linux XFS]     [XFS]     [Linux NFS]     [Linux CIFS]     [Ecryptfs]     [Linux NILFS]     [Linux Cachefs]     [Reiser FS]     [Initramfs]     [Linux FB Devel]     [Linux OpenGL]     [DRI Devel]     [Fastboot]     [Linux RT Users]     [Linux RT Stable]     [eCos]     [Corosync]     [Linux Clusters]     [LVS Devel]     [Hot Plug]     [Linux Virtualization]     [KVM]     [KVM PPC]     [KVM ia64]     [Linux Containers]     [Linux Hexagon]     [Linux Cgroups]     [Util Linux]     [Wireless]     [Linux Bluetooth]     [Bluez Devel]     [Ethernet Bridging]     [Embedded Linux]     [Barebox]     [Linux MMC]     [Linux IIO]     [Sparse]     [Smatch]     [Linux Arch]     [x86 Platform Driver]     [Linux ACPI]     [Linux IBM ACPI]     [LM Sensors]     [CPU Freq]     [Linux Power Management]     [Linmodems]     [Linux DCCP]     [Linux SCTP]     [ALSA Devel]     [Linux USB]     [Linux PA RISC]     [Linux Samsung SOC]     [MIPS Linux]     [IBM S/390 Linux]     [ARM Linux]     [ARM Kernel]     [ARM MSM]     [Tegra Devel]     [Sparc Linux]     [Linux Security]     [Linux Sound]     [Linux Media]     [Video 4 Linux]     [Linux IRDA Users]     [Linux for the blind]     [Linux RAID]     [Linux ATA RAID]     [Device Mapper]     [Linux SCSI]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Linux IDE]     [Linux SMP]     [Linux AXP]     [Linux Alpha]     [Linux M68K]     [Linux ia64]     [Linux 8086]     [Linux x86_64]     [Linux Config]     [Linux Apps]     [Linux MSDOS]     [Linux X.25]     [Linux Crypto]     [DM Crypt]     [Linux Trace Users]     [Linux Btrace]     [Linux Watchdog]     [Utrace Devel]     [Linux C Programming]     [Linux Assembly]     [Dash]     [DWARVES]     [Hail Devel]     [Linux Kernel Debugger]     [Linux gcc]     [Gcc Help]     [X.Org]     [Wine]

Add to Google Powered by Linux

[Older Kernel Discussion]     [Yosemite National Park Forum]     [Large Format Photos]     [Gimp]     [Yosemite Photos]     [Stuff]