Skip to content

Commit a23c129

Browse files
dedekindlenb
authored andcommitted
tools/power turbostat: Cleanup print helper functions
Factor error-prone turnary expressions into locak 'sep' variable. Remove the redundant parentheses around sprintf() calls. Remove an unnecessary cast to "unsigned int" by using the '%08llx' instead of '%08x'. No functional changes. [lenb: fix typo, simplify] Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent cdbefe9 commit a23c129

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

tools/power/x86/turbostat/turbostat.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,31 +2835,38 @@ void bic_lookup(cpu_set_t *ret_set, char *name_list, enum show_hide_mode mode)
28352835
static inline int print_name(int width, int *printed, char *delim, char *name, enum counter_type type, enum counter_format format)
28362836
{
28372837
UNUSED(type);
2838+
char *sep = (*printed)++ ? delim : "";
28382839

28392840
if (format == FORMAT_RAW && width >= 64)
2840-
return (sprintf(outp, "%s%-8s", ((*printed)++ ? delim : ""), name));
2841+
return sprintf(outp, "%s%-8s", sep, name);
28412842
else
2842-
return (sprintf(outp, "%s%s", ((*printed)++ ? delim : ""), name));
2843+
return sprintf(outp, "%s%s", sep, name);
28432844
}
28442845

28452846
static inline int print_hex_value(int width, int *printed, char *delim, unsigned long long value)
28462847
{
2848+
char *sep = (*printed)++ ? delim : "";
2849+
28472850
if (width <= 32)
2848-
return (sprintf(outp, "%s%08x", ((*printed)++ ? delim : ""), (unsigned int)value));
2851+
return (sprintf(outp, "%s%08llx", sep, value));
28492852
else
2850-
return (sprintf(outp, "%s%016llx", ((*printed)++ ? delim : ""), value));
2853+
return (sprintf(outp, "%s%016llx", sep, value));
28512854
}
28522855

28532856
static inline int print_decimal_value(int width, int *printed, char *delim, unsigned long long value)
28542857
{
2858+
char *sep = (*printed)++ ? delim : "";
2859+
28552860
UNUSED(width);
28562861

2857-
return (sprintf(outp, "%s%lld", ((*printed)++ ? delim : ""), value));
2862+
return (sprintf(outp, "%s%lld", sep, value));
28582863
}
28592864

28602865
static inline int print_float_value(int *printed, char *delim, double value)
28612866
{
2862-
return (sprintf(outp, "%s%0.2f", ((*printed)++ ? delim : ""), value));
2867+
char *sep = (*printed)++ ? delim : "";
2868+
2869+
return (sprintf(outp, "%s%0.2f", sep, value));
28632870
}
28642871

28652872
void print_header(char *delim)

0 commit comments

Comments
 (0)