Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Artem Bityutskiy and committed by
Len Brown
092b76a3 08e11edd

+13 -6
+13 -6
tools/power/x86/turbostat/turbostat.c
··· 2866 2866 static inline int print_name(int width, int *printed, char *delim, char *name, enum counter_type type, enum counter_format format) 2867 2867 { 2868 2868 UNUSED(type); 2869 + char *sep = (*printed)++ ? delim : ""; 2869 2870 2870 2871 if (format == FORMAT_RAW && width >= 64) 2871 - return (sprintf(outp, "%s%-8s", ((*printed)++ ? delim : ""), name)); 2872 + return sprintf(outp, "%s%-8s", sep, name); 2872 2873 else 2873 - return (sprintf(outp, "%s%s", ((*printed)++ ? delim : ""), name)); 2874 + return sprintf(outp, "%s%s", sep, name); 2874 2875 } 2875 2876 2876 2877 static inline int print_hex_value(int width, int *printed, char *delim, unsigned long long value) 2877 2878 { 2879 + char *sep = (*printed)++ ? delim : ""; 2880 + 2878 2881 if (width <= 32) 2879 - return (sprintf(outp, "%s%08x", ((*printed)++ ? delim : ""), (unsigned int)value)); 2882 + return sprintf(outp, "%s%08llx", sep, value); 2880 2883 else 2881 - return (sprintf(outp, "%s%016llx", ((*printed)++ ? delim : ""), value)); 2884 + return sprintf(outp, "%s%016llx", sep, value); 2882 2885 } 2883 2886 2884 2887 static inline int print_decimal_value(int width, int *printed, char *delim, unsigned long long value) 2885 2888 { 2889 + char *sep = (*printed)++ ? delim : ""; 2890 + 2886 2891 UNUSED(width); 2887 2892 2888 - return (sprintf(outp, "%s%lld", ((*printed)++ ? delim : ""), value)); 2893 + return sprintf(outp, "%s%lld", sep, value); 2889 2894 } 2890 2895 2891 2896 static inline int print_float_value(int *printed, char *delim, double value) 2892 2897 { 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); 2894 2901 } 2895 2902 2896 2903 void print_header(char *delim)