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

perf intel-pt: Make logging slightly more efficient

Logging is only used for debugging. Use macros to save calling into the
functions only to return immediately when logging is not enabled.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1443186956-18718-5-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
116f349c 9992c2d5

+43 -16
+11 -10
tools/perf/util/intel-pt-decoder/intel-pt-log.c
··· 29 29 30 30 static FILE *f; 31 31 static char log_name[MAX_LOG_NAME]; 32 - static bool enable_logging; 32 + bool intel_pt_enable_logging; 33 33 34 34 void intel_pt_log_enable(void) 35 35 { 36 - enable_logging = true; 36 + intel_pt_enable_logging = true; 37 37 } 38 38 39 39 void intel_pt_log_disable(void) 40 40 { 41 41 if (f) 42 42 fflush(f); 43 - enable_logging = false; 43 + intel_pt_enable_logging = false; 44 44 } 45 45 46 46 void intel_pt_log_set_name(const char *name) ··· 80 80 81 81 static int intel_pt_log_open(void) 82 82 { 83 - if (!enable_logging) 83 + if (!intel_pt_enable_logging) 84 84 return -1; 85 85 86 86 if (f) ··· 91 91 92 92 f = fopen(log_name, "w+"); 93 93 if (!f) { 94 - enable_logging = false; 94 + intel_pt_enable_logging = false; 95 95 return -1; 96 96 } 97 97 98 98 return 0; 99 99 } 100 100 101 - void intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len, 102 - uint64_t pos, const unsigned char *buf) 101 + void __intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len, 102 + uint64_t pos, const unsigned char *buf) 103 103 { 104 104 char desc[INTEL_PT_PKT_DESC_MAX]; 105 105 ··· 111 111 fprintf(f, "%s\n", desc); 112 112 } 113 113 114 - void intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip) 114 + void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip) 115 115 { 116 116 char desc[INTEL_PT_INSN_DESC_MAX]; 117 117 size_t len = intel_pt_insn->length; ··· 128 128 fprintf(f, "Bad instruction!\n"); 129 129 } 130 130 131 - void intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn, uint64_t ip) 131 + void __intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn, 132 + uint64_t ip) 132 133 { 133 134 char desc[INTEL_PT_INSN_DESC_MAX]; 134 135 ··· 143 142 fprintf(f, "Bad instruction!\n"); 144 143 } 145 144 146 - void intel_pt_log(const char *fmt, ...) 145 + void __intel_pt_log(const char *fmt, ...) 147 146 { 148 147 va_list args; 149 148
+32 -6
tools/perf/util/intel-pt-decoder/intel-pt-log.h
··· 25 25 void intel_pt_log_disable(void); 26 26 void intel_pt_log_set_name(const char *name); 27 27 28 - void intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len, 29 - uint64_t pos, const unsigned char *buf); 28 + void __intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len, 29 + uint64_t pos, const unsigned char *buf); 30 30 31 31 struct intel_pt_insn; 32 32 33 - void intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip); 34 - void intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn, 35 - uint64_t ip); 33 + void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip); 34 + void __intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn, 35 + uint64_t ip); 36 36 37 37 __attribute__((format(printf, 1, 2))) 38 - void intel_pt_log(const char *fmt, ...); 38 + void __intel_pt_log(const char *fmt, ...); 39 + 40 + #define intel_pt_log(fmt, ...) \ 41 + do { \ 42 + if (intel_pt_enable_logging) \ 43 + __intel_pt_log(fmt, ##__VA_ARGS__); \ 44 + } while (0) 45 + 46 + #define intel_pt_log_packet(arg, ...) \ 47 + do { \ 48 + if (intel_pt_enable_logging) \ 49 + __intel_pt_log_packet(arg, ##__VA_ARGS__); \ 50 + } while (0) 51 + 52 + #define intel_pt_log_insn(arg, ...) \ 53 + do { \ 54 + if (intel_pt_enable_logging) \ 55 + __intel_pt_log_insn(arg, ##__VA_ARGS__); \ 56 + } while (0) 57 + 58 + #define intel_pt_log_insn_no_data(arg, ...) \ 59 + do { \ 60 + if (intel_pt_enable_logging) \ 61 + __intel_pt_log_insn_no_data(arg, ##__VA_ARGS__); \ 62 + } while (0) 39 63 40 64 #define x64_fmt "0x%" PRIx64 65 + 66 + extern bool intel_pt_enable_logging; 41 67 42 68 static inline void intel_pt_log_at(const char *msg, uint64_t u) 43 69 {