Skip to content

Commit 092b76a

Browse files
dedekindlenb
authored andcommitted
tools/power turbostat: Cleanup print helper functions
Make printer helper functions more readable by factoring out a local '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 typos, simplify] Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 08e11ed commit 092b76a

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
@@ -2866,31 +2866,38 @@ void bic_lookup(cpu_set_t *ret_set, char *name_list, enum show_hide_mode mode)
28662866
static inline int print_name(int width, int *printed, char *delim, char *name, enum counter_type type, enum counter_format format)
28672867
{
28682868
UNUSED(type);
2869+
char *sep = (*printed)++ ? delim : "";
28692870

28702871
if (format == FORMAT_RAW && width >= 64)
2871-
return (sprintf(outp, "%s%-8s", ((*printed)++ ? delim : ""), name));
2872+
return sprintf(outp, "%s%-8s", sep, name);
28722873
else
2873-
return (sprintf(outp, "%s%s", ((*printed)++ ? delim : ""), name));
2874+
return sprintf(outp, "%s%s", sep, name);
28742875
}
28752876

28762877
static inline int print_hex_value(int width, int *printed, char *delim, unsigned long long value)
28772878
{
2879+
char *sep = (*printed)++ ? delim : "";
2880+
28782881
if (width <= 32)
2879-
return (sprintf(outp, "%s%08x", ((*printed)++ ? delim : ""), (unsigned int)value));
2882+
return sprintf(outp, "%s%08llx", sep, value);
28802883
else
2881-
return (sprintf(outp, "%s%016llx", ((*printed)++ ? delim : ""), value));
2884+
return sprintf(outp, "%s%016llx", sep, value);
28822885
}
28832886

28842887
static inline int print_decimal_value(int width, int *printed, char *delim, unsigned long long value)
28852888
{
2889+
char *sep = (*printed)++ ? delim : "";
2890+
28862891
UNUSED(width);
28872892

2888-
return (sprintf(outp, "%s%lld", ((*printed)++ ? delim : ""), value));
2893+
return sprintf(outp, "%s%lld", sep, value);
28892894
}
28902895

28912896
static inline int print_float_value(int *printed, char *delim, double value)
28922897
{
2893-
return (sprintf(outp, "%s%0.2f", ((*printed)++ ? delim : ""), value));
2898+
char *sep = (*printed)++ ? delim : "";
2899+
2900+
return sprintf(outp, "%s%0.2f", sep, value);
28942901
}
28952902

28962903
void print_header(char *delim)

0 commit comments

Comments
 (0)