24 # include <linux/ctype.h> 25 # include <linux/sched.h> 29 #include <sys/types.h> 101 #undef M0_TRACE_SUBSYS 102 #define M0_TRACE_SUBSYS(name, value) [value] = #name, 113 [0] = { .name =
"NONE", .level =
M0_NONE },
114 [1] = { .name =
"ALWAYS", .level =
M0_ALWAYS },
115 [2] = { .name =
"FATAL", .level =
M0_FATAL },
116 [3] = { .name =
"ERROR", .level =
M0_ERROR },
117 [4] = { .name =
"WARN", .level =
M0_WARN },
118 [5] = { .name =
"NOTICE", .level =
M0_NOTICE },
119 [6] = { .name =
"INFO", .level =
M0_INFO },
120 [7] = { .name =
"DEBUG", .level =
M0_DEBUG },
121 [8] = { .name =
"CALL", .level =
M0_CALL },
167 __asm__ __volatile__(
"rdtsc" :
"=a"(count_lo),
"=d"(count_hi));
169 return ((uint64_t)count_lo) | (((uint64_t)count_hi) << 32);
170 #elif defined (CONFIG_AARCH64) 173 asm volatile(
"mrs %0, pmccntr_el0" :
"=r"(cycle));
176 #error "The Platform is not supported" 180 #define NULL_STRING_STUB "(null)" 186 uint32_t total_size = 0;
195 total_size += strlen(
s) + 1;
210 size_t str_len = strlen(src_str);
211 memcpy(dst_str, src_str, str_len + 1);
212 dst_str += str_len + 1;
232 uint32_t endpos_in_buf;
235 uint32_t str_data_size;
243 unsigned long sp = (
unsigned long)&tbh;
245 register unsigned long sp
asm(
"sp");
248 #ifdef ENABLE_RESTRICTED_TRACE_MODE 250 if (td->
td_level > M0_TRACE_HIGHEST_ALLOWED_LEVEL)
285 pos = endpos - record_len;
287 endpos_in_buf = endpos &
bufmask;
291 if (pos_in_buf > endpos_in_buf && endpos_in_buf) {
304 header->trh_pid = current->pid;
308 header->trh_no = record_num;
313 header->trh_string_data_size = str_data_size;
314 header->trh_record_size = record_len;
315 body_in_buf = (
char*)
header + header_len;
319 if (str_data_size > 0) {
327 #ifdef ENABLE_IMMEDIATE_TRACE 343 for (
i = 0; i < ARRAY_SIZE(trace_subsys_str); i++, subsys >>= 1)
357 for (
i = 0; i < ARRAY_SIZE(trace_subsys_str); i++, subsys >>= 1)
370 for (
p =
s; *
p !=
'\0'; ++
p)
380 for (
p =
s; *
p !=
'\0'; ++
p)
417 char *subsys = subsys_names;
425 subsys = subsys_names[0] ==
'!' ? subsys_names + 1 : subsys_names;
431 if (strcmp(subsys,
"all") == 0 || strcmp(subsys,
"ALL") == 0) {
440 p = strchr(subsys,
',');
446 " immediate mask: subsystem '%s' not" 455 *ret_mask = subsys_names[0] ==
'!' ? ~mask : mask;
491 size_t n = strlen(level_name);
492 bool is_plus_level =
false;
494 if (level_name[
n - 1] ==
'+') {
495 level_name[
n - 1] =
'\0';
496 is_plus_level =
true;
535 " level: no such level '%s'\n",
557 " invalid value '%s'\n", ctx_name);
566 if (ctx_name ==
NULL)
575 pr_info(
"motr: trace print context: %s\n", ctx_name);
584 char *level_str_copy;
590 if (level_str_copy ==
NULL)
598 " it should be in form of 'level[+][,level[+]]'" 599 " where 'level' is one of call|debug|info|notice|warn|" 606 pr_info(
"motr: trace level: %s\n",
level_str);
659 if (tbh == (
void*)
bootlog.bl_area.ta_buf)
695 size_t total_str_len = 0;
696 const char *str_data =
NULL;
731 str_len = strlen(str_data);
732 total_str_len += str_len + 1;
737 args[
i].v64 = (uint64_t)str_data;
738 str_data += str_len + 1;
755 char subsys_map_str[
sizeof(uint64_t) *
CHAR_BIT + 3];
760 " for M0_LOG() inside '%s' at '%s:%u'\n",
769 (
unsigned long long)trh->
trh_no,
771 (
unsigned) (trh->
trh_sp & 0xffff),
781 (
unsigned) (trh->
trh_sp & 0xffff),
814 size_t str_len = strlen(str);
815 ssize_t free_space = max_size - str_len;
816 const char *fill_chars =
" ";
819 if (free_space < 0 || strlen(fill_chars) < align_size)
822 while ((
p = strchr(
p,
'\n')) !=
NULL)
825 free_space -= align_size;
828 memmove(
p + align_size,
p, strlen(
p) + 1);
829 memcpy(
p, fill_chars, align_size);
838 const void *
tr_body,
bool yaml_stream_mode)
843 static char msg_buf[128 * 1024];
844 size_t outbuf_used = 0;
848 MSG_SHIFT_LEN_STREAM = 2,
849 MSG_SHIFT_LEN_NORMAL = 6,
856 " for M0_LOG() inside '%s' at '%s:%u'\n",
862 "timestamp: %" PRIu64 "\n" 864 "stack_addr: %" PRIx64 "\n" 873 :
" - record_num: %" PRIu64 "\n" 874 " timestamp: %" PRIu64 "\n" 876 " stack_addr: %" PRIx64 "\n" 885 outbuf_used += snprintf(outbuf, outbuf_size,
td_fmt,
895 if (outbuf_used >= outbuf_size)
901 if (
rc >
sizeof msg_buf)
903 " truncated to %zu bytes",
904 __func__,
sizeof msg_buf);
907 yaml_stream_mode ? MSG_SHIFT_LEN_STREAM :
908 MSG_SHIFT_LEN_NORMAL);
913 outbuf_used += snprintf(outbuf + outbuf_used, outbuf_size - outbuf_used,
915 if (outbuf_used >= outbuf_size)
918 if (yaml_stream_mode) {
919 outbuf_used += snprintf(outbuf + outbuf_used,
920 outbuf_size - outbuf_used,
"---\n");
921 if (outbuf_used >= outbuf_size)
945 while (
p >= curptr) {
M0_INTERNAL bool m0_addr_is_sane(const uint64_t *addr)
M0_INTERNAL void m0_trace_buf_header_init(struct m0_trace_buf_header *tbh, size_t buf_size)
M0_INTERNAL const void * m0_trace_logbuf_get(void)
static struct m0_addb2_philter p
M0_INTERNAL uint32_t m0_trace_logbuf_size_get(void)
static char * uppercase(char *s)
static struct m0_addb2_mach * m
void m0_error_printf(const char *fmt,...)
static struct @261 trace_levels[]
static enum m0_trace_level trace_level_value(char *level_name)
M0_INTERNAL void m0_trace_print_subsystems(void)
M0_INTERNAL void m0_trace_logbuf_size_set(size_t size)
enum m0_trace_level level
void m0_console_printf(const char *fmt,...)
M0_INTERNAL void m0_trace_level_allow(unsigned level)
enum m0_trace_level td_level
M0_INTERNAL int m0_trace_record_print_yaml(char *outbuf, size_t outbuf_size, const struct m0_trace_rec_header *trh, const void *tr_body, bool yaml_stream_mode)
static bool m0_is_po2(uint64_t val)
int m0_trace_magic_sym_extra_addr_add(const void *addr)
union m0_trace_rec_argument m0_trace_rec_args_t[M0_TRACE_ARGC_MAX]
M0_INTERNAL const struct m0_trace_rec_header * m0_trace_last_record_get(void)
static const char * trace_subsys_str[]
void m0_console_vprintf(const char *fmt, va_list args)
M0_INTERNAL const char * m0_trace_magic_sym_name_get(void)
#define M0_TRACE_KBUF_SIZE
M0_INTERNAL const char * m0_short_file_name(const char *fname)
M0_INTERNAL int m0_pagesize_get(void)
M0_INTERNAL void m0_arch_trace_fini(void)
const struct m0_build_info * m0_build_info_get(void)
M0_INTERNAL const char * m0_trace_subsys_name(uint64_t subsys)
M0_INTERNAL int m0_trace_subsys_list_to_mask(char *subsys_names, unsigned long *ret_mask)
M0_INTERNAL void m0_trace_switch_to_static_logbuf(void)
static const char * trace_print_ctx_str[]
M0_INTERNAL int m0_trace_set_print_context(const char *ctx_name)
M0_INTERNAL void m0_trace_stats_update(uint32_t rec_size)
m0_time_t m0_time_now(void)
static uint32_t calc_string_data_size(const struct m0_trace_descr *td, const void *body)
M0_INTERNAL void m0_trace_fini(void)
static struct @260 bootlog
M0_INTERNAL const char * m0_trace_level_name(enum m0_trace_level level)
static const char trace_magic_symbol_name[]
#define M0_TRACE_UBUF_SIZE
static int format_yaml_str(char *str, size_t max_size, size_t align_size)
const char * bi_git_describe
char * fmt(const char *format,...) __attribute__((format(printf
M0_INTERNAL const struct m0_trace_buf_header * m0_trace_logbuf_header_get(void)
static struct fdmi_ctx ctx
static struct m0_clink l[NR]
M0_INTERNAL void m0_trace_record_print(const struct m0_trace_rec_header *trh, const void *buf)
static int64_t m0_atomic64_get(const struct m0_atomic64 *a)
M0_INTERNAL void m0_trace_allot(const struct m0_trace_descr *td, const void *body)
static enum m0_trace_level trace_level_value_plus(char *level_name)
M0_INTERNAL int m0_trace_args_unpack(const struct m0_trace_rec_header *trh, m0_trace_rec_args_t args, const void *buf)
char bl_buf[BOOTLOG_BUF_SIZE]
static char * lowercase(char *s)
static unsigned allowed_level
static const uint64_t trace_magic_symbol
static char * subsys_str(uint64_t subsys, char *buf)
unsigned long m0_trace_immediate_mask
M0_INTERNAL const void * m0_trace_magic_sym_addr_get(void)
M0_INTERNAL int m0_trace_init(void)
static uint64_t m0_rdtsc(void)
struct m0_trace_area bl_area
M0_INTERNAL int m0_arch_trace_init()
static unsigned long subsys_name_to_mask(char *subsys_name)
M0_BASSERT(bootlog.bl_buf==bootlog.bl_area.ta_buf)
M0_INTERNAL void m0_arch_trace_buf_header_init(struct m0_trace_buf_header *tbh)
struct m0_trace_buf_header * m0_logbuf_header
M0_INTERNAL enum m0_trace_print_context m0_trace_print_context_parse(const char *ctx_name)
static struct m0_addb2_source * s
M0_INTERNAL uint64_t m0_trace_logbuf_pos_get(void)
static uint64_t m0_align(uint64_t val, uint64_t alignment)
static int64_t m0_atomic64_add_return(struct m0_atomic64 *a, int64_t d)
static void copy_string_data(char *dst_str, const char *body, const struct m0_trace_descr *td)
const char * bi_version_string
static void m0_atomic64_set(struct m0_atomic64 *a, int64_t num)
M0_INTERNAL enum m0_trace_level m0_trace_level_parse(char *str)
#define M0_IMPOSSIBLE(fmt,...)
M0_INTERNAL int m0_trace_set_level(const char *level_str)