Motr  M0
utrace.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2011-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include <string.h> /* memset, strlen */
24 #include <errno.h>
25 #include <err.h> /* warn */
26 #include <sysexits.h> /* EX_* exit codes (EX_OSERR, EX_SOFTWARE) */
27 #include <stdio.h>
28 #include <stdlib.h> /* getenv, strtoul */
29 #include <unistd.h> /* getpagesize, getpid */
30 #include <fcntl.h> /* open, O_RDWR|O_CREAT|O_TRUNC */
31 #include <sys/mman.h> /* mmap */
32 #include <sys/stat.h> /* fstat */
33 #include <limits.h> /* CHAR_BIT */
34 #include <stddef.h> /* ptrdiff_t */
35 #include <time.h> /* strftime */
36 
37 #include "lib/types.h"
38 #include "lib/arith.h"
39 #include "lib/memory.h"
40 #include "lib/string.h" /* m0_strdup */
41 #include "lib/trace.h"
42 #include "lib/trace_internal.h"
43 #include "lib/cookie.h" /* m0_addr_is_sane_and_aligned */
44 
45 #include "motr/magic.h"
46 
56 
57 static int logfd;
58 static bool use_mmaped_buffer = true;
59 static char trace_file_path[PATH_MAX];
61 
62 static int logbuf_map()
63 {
64  struct m0_trace_area *trace_area;
65  size_t trace_area_size = M0_TRACE_BUF_HEADER_SIZE + trace_buf_size;
66  int rc;
67 
68  M0_PRE((trace_area_size % m0_pagesize_get()) == 0);
69 
70  if (strlen(trace_file_path) == 0) {
71  if (getcwd(trace_file_path, sizeof trace_file_path) == NULL ) {
72  warn("failed to read CWD path, using relative path for"
73  " m0trace.PID file");
74  memset(trace_file_path, 0, sizeof trace_file_path);
75  } else {
76  strncat(trace_file_path, "/", sizeof trace_file_path -
77  strlen(trace_file_path) - 1);
78  }
79 
80  int available_bytes = sizeof trace_file_path -
81  strlen(trace_file_path);
82  rc = snprintf(trace_file_path + strlen(trace_file_path),
83  available_bytes, "m0trace.%u", m0_pid_cached);
84  if (rc < 0) {
85  warn("failed to construct trace file path");
86  return rc;
87  }
88  if (rc >= available_bytes) {
89  warnx("failed to construct trace file path, not enough"
90  " space in the path buffer");
91  return -ENOBUFS;
92  }
93  }
94 
95  if ((logfd = open(trace_file_path, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0700)) == -1) {
96  warn("open(\"%s\")", trace_file_path);
97  } else if ((errno = posix_fallocate(logfd, 0, trace_area_size)) != 0) {
98  warn("fallocate(\"%s\", %zu)", trace_file_path, trace_area_size);
99  } else if ((trace_area = mmap(NULL, trace_area_size, PROT_WRITE,
100  MAP_SHARED, logfd, 0)) == MAP_FAILED)
101  {
102  warn("mmap(\"%s\")", trace_file_path);
103  } else {
104  m0_logbuf_header = &trace_area->ta_header;
105  m0_logbuf = trace_area->ta_buf;
106  memset(trace_area, 0, trace_area_size);
109  }
110 
111  return -errno;
112 }
113 
114 M0_INTERNAL const char *m0_trace_file_path_get(void)
115 {
116  return trace_file_path;
117 }
118 
119 M0_INTERNAL int m0_trace_set_immediate_mask(const char *mask)
120 {
121  if (mask != NULL) {
122  char *endp;
123 
124  m0_trace_immediate_mask = strtoul(mask, &endp, 0);
125 
126  /*
127  * if mask string fails to convert to a number cleanly, then
128  * assume that mask string contains a comma separated list of
129  * subsystem names, which we use to build a numeric mask
130  */
131  if (errno != 0 || *endp != 0) {
132  unsigned long m = 0;
133  int rc;
134  char *s = m0_strdup(mask);
135 
136  if (s == NULL)
137  return -ENOMEM;
138 
140  m0_free(s);
141 
142  if (rc != 0)
143  return rc;
144 
146  }
147  }
148 
149  return 0;
150 }
151 
152 M0_INTERNAL void m0_trace_stats_update(uint32_t rec_size)
153 {
154 }
155 
156 M0_INTERNAL void m0_trace_set_mmapped_buffer(bool val)
157 {
159 }
160 
161 M0_INTERNAL bool m0_trace_use_mmapped_buffer(void)
162 {
163  return use_mmaped_buffer;
164 }
165 
167 {
168  if (m0_pid_cached) {
169  m0_error_printf("motr: can't set trace buffer size after it's"
170  " been initialized\n");
171  return -EBUSY;
172  }
173 
174  if (size == 0 || !m0_is_po2(size) || size % m0_pagesize_get() != 0) {
175  m0_error_printf("motr: incorrect value for trace buffer size"
176  " parameter (%zu), it can't be zero, should be a power of"
177  " 2 and a multiple of PAGE_SIZE(%u)\n",
178  size, m0_pagesize_get());
179  return -EINVAL;
180  }
181 
183  return 0;
184 }
185 
186 static int set_trace_dir(const char *path)
187 {
188  int rc;
189 
190  if (path == NULL)
191  return 0;
192 
193  rc = snprintf(trace_file_path, sizeof trace_file_path, "%s/m0trace.%u",
194  path, m0_pid_cached);
195  if (rc < 0) {
196  warn("ignoring environment variable M0_TRACE_DIR - failed"
197  " to construct trace file path");
198  memset(trace_file_path, 0, sizeof trace_file_path);
199  return rc;
200  }
201  if (rc >= sizeof trace_file_path) {
202  warnx("ignoring environment variable M0_TRACE_DIR - its content"
203  " is too long (%zu bytes), max allowed lengh is %zu bytes"
204  , strlen(path), (sizeof trace_file_path) - 16);
205  memset(trace_file_path, 0, sizeof trace_file_path);
206  return -EINVAL;
207  }
208 
209  return 0;
210 }
211 
212 M0_INTERNAL int m0_arch_trace_init()
213 {
214  int rc;
215  const char *var;
216 
217  m0_pid_cached = getpid();
218 
219  var = getenv("M0_TRACE_IMMEDIATE_MASK");
221  if (rc != 0)
222  return rc;
223 
224  var = getenv("M0_TRACE_LEVEL");
225  rc = m0_trace_set_level(var);
226  if (rc != 0)
227  return rc;
228 
229  var = getenv("M0_TRACE_PRINT_CONTEXT");
231  if (rc != 0)
232  return rc;
233 
234  var = getenv("M0_TRACE_DIR");
235  rc = set_trace_dir(var);
236  if (rc != 0 && rc != -EINVAL)
237  return rc;
238 
239  setlinebuf(stdout);
240  return m0_trace_use_mmapped_buffer() ? logbuf_map() : 0;
241 }
242 
243 M0_INTERNAL void m0_arch_trace_fini(void)
244 {
245  void *old_buffer = m0_logbuf_header;
246  uint32_t old_buffer_size = M0_TRACE_BUF_HEADER_SIZE +
248 
250 
252 
254  munmap(old_buffer, old_buffer_size);
255  close(logfd);
256 }
257 
258 M0_INTERNAL void m0_arch_trace_buf_header_init(struct m0_trace_buf_header *tbh)
259 {
260  int i;
261  int rc;
262  int cmdline_fd;
263  ssize_t read_bytes;
264 
266 
267 #define CMDLINE "/proc/self/cmdline"
268  cmdline_fd = open(CMDLINE, O_RDONLY);
269  if (cmdline_fd == -1)
270  return;
271 
272  read_bytes = read(cmdline_fd, tbh->tbh_cli_args,
273  sizeof(tbh->tbh_cli_args));
274  if (read_bytes == -1) {
275  warn("motr: failed to read " CMDLINE);
276  } else {
277  if (read_bytes == sizeof(tbh->tbh_cli_args)) {
278  warnx("motr: command line args don't fit into trace "
279  "buffer, truncating after %zu bytes", read_bytes);
280  tbh->tbh_cli_args[read_bytes - 1] = '\0';
281  } else {
282  tbh->tbh_cli_args[read_bytes] = '\0';
283  }
284  /* cli args are separated with '\0', replace it with spaces */
285  for (i = 0; i < read_bytes - 1; ++i)
286  if (tbh->tbh_cli_args[i] == '\0')
287  tbh->tbh_cli_args[i] = ' ';
288  }
289 
290  rc = close(cmdline_fd);
291  if (rc == -1)
292  warn("motr: failed to close " CMDLINE ": errno=%d", errno);
293 #undef CMDLINE
294 
295  if (strstr(tbh->tbh_cli_args, "m0mkfs") != NULL)
297 
299 }
300 
301 static unsigned align(FILE *file, uint64_t align, uint64_t pos)
302 {
304  while (!feof(file) && (pos & (align - 1))) {
305  fgetc(file);
306  pos++;
307  }
308  return pos;
309 }
310 
311 static const struct m0_trace_buf_header *read_trace_buf_header(FILE *trace_file)
312 {
313  const struct m0_trace_buf_header *tb_header;
314 
315  static char buf[M0_TRACE_BUF_HEADER_SIZE];
316  size_t n;
317 
318  n = fread(buf, 1, sizeof buf, trace_file);
319  if (n != sizeof buf) {
320  warnx("failed to read trace header (got %zu bytes instead of"
321  " %zu bytes)\n", n, sizeof buf);
322  return NULL;
323  }
324 
325  tb_header = (const struct m0_trace_buf_header *)buf;
326 
327  if (tb_header->tbh_magic != M0_TRACE_BUF_HEADER_MAGIC) {
328  warnx("invalid trace header MAGIC value\n");
329  return NULL;
330  }
331 
332  if (tb_header->tbh_header_size != M0_TRACE_BUF_HEADER_SIZE)
333  warnx("trace header has different size: expected=%u, actual=%u",
335 
336  return tb_header;
337 }
338 
339 static void print_trace_buf_header(FILE *ofile,
340  const struct m0_trace_buf_header *tbh)
341 {
342  int rc;
343  struct tm tm;
344  struct tm *ptm;
345  char time_str[512];
346  size_t time_str_len;
347  time_t time;
348  bool need_comma = false;
349 
350  fprintf(ofile, "header:\n");
351 
352  fprintf(ofile, " motr_version: %s\n", tbh->tbh_motr_version);
353  fprintf(ofile, " motr_git_describe: %s\n", tbh->tbh_motr_git_describe);
354  fprintf(ofile, " motr_kernel: %s\n", tbh->tbh_motr_kernel_ver);
355 
356  rc = putenv("TZ=UTC0");
357  if (rc != 0)
358  warn("failed to set timezone to UTC\n");
359 
360  time = m0_time_seconds(tbh->tbh_log_time);
361  ptm = localtime_r(&time, &tm);
362  if (ptm != NULL) {
363  time_str_len = strftime(time_str, sizeof time_str,
364  "%FT%T%z", &tm);
365  /*"%b %e %H:%M:%S %Z %Y", &tm);*/
366  if (time_str_len == 0)
367  fprintf(stderr, " failed to format trace file timestamp\n");
368  fprintf(ofile, " trace_time: %s\n", time_str);
369  } else {
370  fprintf(stderr, "incorrect timestamp value in trace header\n");
371  fprintf(ofile, " trace_time: ''\n");
372  }
373 
374  fprintf(ofile, " buffer_type: %s\n",
375  tbh->tbh_buf_type == M0_TRACE_BUF_KERNEL ? "KERNEL" :
376  tbh->tbh_buf_type == M0_TRACE_BUF_USER ? "USER" :
377  "UNKNOWN"
378  );
379  fprintf(ofile, " flags: [ ");
380  if (tbh->tbh_buf_flags & M0_TRACE_BUF_DIRTY) {
381  need_comma = true;
382  fprintf(ofile, "DIRTY");
383  }
384  if (tbh->tbh_buf_flags & M0_TRACE_BUF_MKFS) {
385  if (need_comma)
386  fprintf(ofile, ", ");
387  fprintf(ofile, "MKFS");
388  }
389  fprintf(ofile, " ]\n");
390 
391  fprintf(ofile, " header_addr: %p\n", tbh->tbh_header_addr);
392  fprintf(ofile, " header_size: %u\t\t# bytes\n", tbh->tbh_header_size);
393  fprintf(ofile, " buffer_addr: %p\n", tbh->tbh_buf_addr);
394  fprintf(ofile, " buffer_size: %" PRId64 "\t\t# bytes\n",
395  tbh->tbh_buf_size);
396 
397  if (tbh->tbh_buf_type == M0_TRACE_BUF_KERNEL) {
398  fprintf(ofile, " mod_struct_addr: %p\n",
399  tbh->tbh_module_struct);
400  fprintf(ofile, " mod_core_addr: %p\n",
401  tbh->tbh_module_core_addr);
402  fprintf(ofile, " mod_core_size: %u\t\t# bytes\n",
403  tbh->tbh_module_core_size);
404  }
405 
406  fprintf(ofile, " cli_args: '%s'\n", tbh->tbh_cli_args);
407 }
408 
409 static int mmap_m0tr_ko(const char *m0tr_ko_path, void **ko_addr)
410 {
411  int rc;
412  int kofd;
413  struct stat ko_stat;
414 
415  kofd = open(m0tr_ko_path, O_RDONLY);
416  if (kofd == -1) {
417  warn("failed to open '%s' file", m0tr_ko_path);
418  return EX_NOINPUT;
419  }
420 
421  rc = fstat(kofd, &ko_stat);
422  if (rc != 0) {
423  warn("failed to get stat info for '%s' file",
424  m0tr_ko_path);
425  return EX_OSERR;
426  }
427 
428  *ko_addr = mmap(NULL, ko_stat.st_size, PROT_READ, MAP_PRIVATE,
429  kofd, 0);
430  if (*ko_addr == MAP_FAILED) {
431  warn("failed to mmap '%s' file", m0tr_ko_path);
432  return EX_OSERR;
433  }
434 
435  return 0;
436 }
437 
438 static int calc_trace_descr_offset(const struct m0_trace_buf_header *tbh,
439  const char *m0tr_ko_path,
440  ptrdiff_t *td_offset)
441 {
442  if (tbh->tbh_buf_type == M0_TRACE_BUF_USER) {
443  *td_offset = (char*)m0_trace_magic_sym_addr_get() -
444  (char*)tbh->tbh_magic_sym_addr;
445  } else if (tbh->tbh_buf_type == M0_TRACE_BUF_KERNEL) {
446  int rc;
447  void *ko_addr;
448  off_t msym_file_offset;
449  uint64_t *msym;
450 
451  msym_file_offset = (char*)tbh->tbh_magic_sym_addr -
452  (char*)tbh->tbh_module_core_addr;
453 
454  rc = mmap_m0tr_ko(m0tr_ko_path, &ko_addr);
455  if (rc != 0)
456  return rc;
457 
458  msym = (uint64_t*)((char*)ko_addr + msym_file_offset);
459  if (*msym != M0_TRACE_MAGIC) {
460  warnx("invalid trace magic symbol value in '%s' file at"
461  " offset 0x%" PRIx64 ": 0x%"PRIx64
462  " (expected 0x%lx)",
463  m0tr_ko_path, msym_file_offset, *msym,
465  return EX_DATAERR;
466  }
467 
468  *td_offset = (char*)msym - (char*)tbh->tbh_magic_sym_addr;
469  } else {
470  return EX_DATAERR;
471  }
472 
473  return 0;
474 }
475 
477  const void *magic_symbols[],
478  size_t nr, ptrdiff_t td_offsets[])
479 {
480  int i;
481 
482  if (tbh->tbh_buf_type == M0_TRACE_BUF_USER) {
483  if (tbh->tbh_magic_sym_addresses_nr < nr) {
484  warnx("There are only %u additional magic symbols"
485  " stored in trace log, but %zu were provided to"
486  " m0_trace_parse()",
489  }
490  if (nr == 0)
491  return -ENODATA;
492  for (i = 0; i < nr; ++i)
493  td_offsets[i] = (char*)magic_symbols[i] -
494  (char*)tbh->tbh_magic_sym_addresses[i];
495  } else {
496  warnx("Cannot use additional magic symbols information with"
497  " kernel mode trace log");
498  return -EOPNOTSUPP;
499  }
500 
501  return 0;
502 }
503 
504 static void patch_trace_descr(struct m0_trace_descr *td, ptrdiff_t offset)
505 {
506  td->td_fmt = (char*)td->td_fmt + offset;
507  td->td_func = (char*)td->td_func + offset;
508  td->td_file = (char*)td->td_file + offset;
509  td->td_offset = (typeof (td->td_offset))((char*)td->td_offset + offset);
510  td->td_sizeof = (typeof (td->td_sizeof))((char*)td->td_sizeof + offset);
511  td->td_isstr = (typeof (td->td_isstr))((char*)td->td_isstr + offset);
512 }
513 
514 enum {
516  ((struct m0_trace_buf_header *)0)->tbh_magic_sym_addresses)
517 };
518 
527 M0_INTERNAL int m0_trace_parse(FILE *trace_file, FILE *output_file,
528  const char *m0tr_ko_path,
530  const void *magic_symbols[],
531  unsigned int magic_symbols_nr)
532 {
533  const struct m0_trace_buf_header *tbh;
534  struct m0_trace_rec_header trh;
535  struct m0_trace_descr *td;
536  struct m0_trace_descr patched_td;
537 
538  int rc;
539  int i;
540  size_t pos = 0;
541  size_t nr;
542  size_t n2r;
543  size_t size;
544  size_t invalid_td_count = 0;
545  bool td_is_sane;
546  char *buf;
547 
548  static char yaml_buf[256 * 1024]; /* 256 KB */
549  ptrdiff_t *td_offset;
550  ptrdiff_t td_offsets[MAGIC_SYM_OFFSETS_MAX + 1] = { 0 };
551  size_t td_offsets_nr =
552  (magic_symbols_nr < MAGIC_SYM_OFFSETS_MAX ?
553  magic_symbols_nr : MAGIC_SYM_OFFSETS_MAX) + 1;
554 
555  tbh = read_trace_buf_header(trace_file);
556  if (tbh == NULL)
557  return EX_DATAERR;
558 
559  print_trace_buf_header(output_file, tbh);
561  return 0;
562 
563  rc = calc_trace_descr_offset(tbh, m0tr_ko_path, &td_offsets[0]);
564  if (rc != 0)
565  return rc;
566 
567  if (magic_symbols != NULL) {
568  rc = calc_extra_trace_descr_offsets(tbh, magic_symbols,
569  td_offsets_nr - 1, &td_offsets[1]);
570  if (rc != 0)
571  /* something's not good with the additional magic
572  * symbols information, using only internal (libmotr)
573  * magic symbol */
574  td_offsets_nr = 1;
575  else if (magic_symbols_nr > MAGIC_SYM_OFFSETS_MAX)
576  warnx("Using only first %u magic symbol offsets"
577  " out of %u provided to m0_trace_parse()",
578  MAGIC_SYM_OFFSETS_MAX, magic_symbols_nr);
579  } else if (magic_symbols_nr > 0) {
580  warnx("Not using additional magic symbol addresses"
581  " - inconsistent parameters");
582  }
583 
585  fprintf(output_file, "trace_records:\n");
586 
587  while (!feof(trace_file)) {
588 
589  /* At the beginning of a record */
590  pos = align(trace_file, M0_TRACE_REC_ALIGN, pos);
591 
592  /* Find the complete record */
593  do {
594  nr = fread(&trh.trh_magic, 1,
595  sizeof trh.trh_magic, trace_file);
596 
597  if (nr != sizeof trh.trh_magic) {
598  if (!feof(trace_file)) {
599  warnx("Got %zu bytes of magic instead"
600  " of %zu", nr,
601  sizeof trh.trh_magic);
602  return EX_DATAERR;
603  }
604  if (invalid_td_count > 0)
605  warnx("Total number of unknown trace"
606  " records, that were skipped:"
607  " %zu", invalid_td_count);
608  return EX_OK;
609  }
610 
611  pos += nr;
612  } while (trh.trh_magic != M0_TRACE_MAGIC);
613 
614  /* Now we might have complete record */
615  n2r = sizeof trh - sizeof trh.trh_magic;
616  nr = fread(&trh.trh_sp, 1, n2r, trace_file);
617  if (nr != n2r) {
618  warnx("Got %zu bytes of record (need %zu)", nr, n2r);
619  return EX_DATAERR;
620  }
621  pos += nr;
622 
623  for (i = 0; i < td_offsets_nr; ++i) {
624  td_offset = &td_offsets[i];
625  td = (struct m0_trace_descr*)((char*)trh.trh_descr +
626  *td_offset);
627  td_is_sane =
628  m0_addr_is_sane_and_aligned((const uint64_t *)td);
629  if (td_is_sane && td->td_magic == M0_TRACE_DESCR_MAGIC)
630  break;
631 
632  }
633 
634  if (!td_is_sane) {
635  warnx("Skipping non-existing trace descriptor %p",
636  trh.trh_descr);
637  continue;
638  }
639 
640  if (td->td_magic != M0_TRACE_DESCR_MAGIC) {
641  if (invalid_td_count == 0)
642  warnx("Invalid trace descriptor - most probably"
643  "the trace file was produced by a"
644  "different version of Motr");
645  ++invalid_td_count;
646  continue;
647  }
648 
649  patched_td = *td;
650  if (tbh->tbh_buf_type == M0_TRACE_BUF_KERNEL)
651  patch_trace_descr(&patched_td, *td_offset);
652  trh.trh_descr = &patched_td;
655 
656  buf = m0_alloc(size);
657  if (buf == NULL) {
658  warn("Failed to allocate %zu bytes of memory, looks like"
659  " a corrupted trace descriptor, skipping...", size);
660  continue;
661  }
662 
663  nr = fread(buf, 1, size, trace_file);
664  if (nr != size) {
665  warnx("Got %zu bytes of data (need %zu)", nr, size);
666  return EX_DATAERR;
667  }
668  pos += nr;
669 
670  rc = m0_trace_record_print_yaml(yaml_buf, sizeof yaml_buf, &trh,
672  if (rc == 0)
673  fprintf(output_file, "%s", yaml_buf);
674  else if (rc == -ENOBUFS)
675  warnx("Internal buffer is too small to hold trace record");
676  else
677  warnx("Failed to process trace record data for %p"
678  " descriptor", trh.trh_descr);
679  m0_free(buf);
680  }
681  return EX_OK;
682 }
683 
684 M0_INTERNAL void m0_console_vprintf(const char *fmt, va_list args)
685 {
686  vprintf(fmt, args);
687 }
688 
689 void m0_console_flush(void)
690 {
691  fflush(stdout);
692 }
693 
694 void m0_error_printf(const char *fmt, ...)
695 {
696  va_list ap;
697 
698  va_start(ap, fmt);
699  vfprintf(stderr, fmt, ap);
700  va_end(ap);
701 }
702 
705 /*
706  * Local variables:
707  * c-indentation-style: "K&R"
708  * c-basic-offset: 8
709  * tab-width: 8
710  * fill-column: 80
711  * scroll-step: 1
712  * End:
713  */
M0_INTERNAL bool m0_trace_use_mmapped_buffer(void)
Definition: utrace.c:161
M0_INTERNAL void m0_trace_buf_header_init(struct m0_trace_buf_header *tbh, size_t buf_size)
Definition: trace.c:956
static void patch_trace_descr(struct m0_trace_descr *td, ptrdiff_t offset)
Definition: utrace.c:504
static size_t nr
Definition: dump.c:1505
#define M0_PRE(cond)
#define m0_strdup(s)
Definition: string.h:43
M0_INTERNAL uint32_t m0_trace_logbuf_size_get(void)
Definition: trace.c:624
int const char const void size_t int flags
Definition: dir.c:328
M0_INTERNAL int struct dentry struct kstat * stat
Definition: dir.c:1433
#define NULL
Definition: misc.h:38
static struct m0_addb2_mach * m
Definition: consumer.c:38
Definition: idx_mock.c:52
void m0_error_printf(const char *fmt,...)
Definition: ktrace.c:169
static unsigned align(FILE *file, uint64_t align, uint64_t pos)
Definition: utrace.c:301
struct m0_file file
Definition: di.c:36
M0_INTERNAL void m0_trace_logbuf_size_set(size_t size)
Definition: trace.c:630
uint64_t tbh_buf_size
Definition: trace.h:376
M0_INTERNAL const char * m0_trace_file_path_get(void)
Definition: ktrace.c:72
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)
Definition: trace.c:836
const bool * td_isstr
Definition: trace.h:516
static bool m0_is_po2(uint64_t val)
Definition: arith.h:153
const int * td_offset
Definition: trace.h:514
void * m0_logbuf
Definition: trace.c:86
const void * tbh_header_addr
Definition: trace.h:365
static int set_trace_dir(const char *path)
Definition: utrace.c:186
char tbh_motr_version[16]
Definition: trace.h:394
void m0_console_vprintf(const char *fmt, va_list args)
Definition: ktrace.c:160
uint16_t tbh_buf_flags
Definition: trace.h:380
static int void * buf
Definition: dir.c:1019
Definition: ub.c:49
uint16_t tbh_magic_sym_addresses_nr
Definition: trace.h:417
m0_trace_parse_flags
Definition: trace.h:41
struct m0_trace_buf_header ta_header
#define PRIx64
Definition: types.h:61
Definition: sock.c:887
uint64_t td_magic
Definition: trace.h:506
M0_INTERNAL int m0_pagesize_get(void)
Definition: memory.c:233
static void print_trace_buf_header(FILE *ofile, const struct m0_trace_buf_header *tbh)
Definition: utrace.c:339
char tbh_motr_kernel_ver[128]
Definition: trace.h:398
const char * td_func
Definition: trace.h:508
int i
Definition: dir.c:1033
M0_INTERNAL void m0_arch_trace_fini(void)
Definition: ktrace.c:225
unsigned int tbh_module_core_size
Definition: trace.h:409
const void * tbh_module_struct
Definition: trace.h:402
uint64_t trh_sp
Definition: trace.h:441
M0_INTERNAL int m0_trace_subsys_list_to_mask(char *subsys_names, unsigned long *ret_mask)
Definition: trace.c:414
uint32_t trh_string_data_size
Definition: trace.h:446
M0_INTERNAL void m0_trace_switch_to_static_logbuf(void)
Definition: trace.c:986
#define M0_ASSERT(cond)
static int mmap_m0tr_ko(const char *m0tr_ko_path, void **ko_addr)
Definition: utrace.c:409
M0_INTERNAL int m0_trace_set_print_context(const char *ctx_name)
Definition: trace.c:562
M0_INTERNAL void m0_trace_stats_update(uint32_t rec_size)
Definition: ktrace.c:119
char tbh_motr_git_describe[64]
Definition: trace.h:396
#define M0_TRACE_UBUF_SIZE
Definition: config.h:296
char * fmt(const char *format,...) __attribute__((format(printf
void * m0_alloc(size_t size)
Definition: memory.c:126
const void * tbh_magic_sym_addresses[128]
Definition: trace.h:419
static const struct m0_trace_buf_header * read_trace_buf_header(FILE *trace_file)
Definition: utrace.c:311
const char * td_fmt
Definition: trace.h:507
pid_t m0_pid_cached
Definition: utrace.c:55
static m0_bindex_t offset
Definition: dump.c:173
uint64_t tbh_magic
Definition: trace.h:363
char tbh_cli_args[1024]
Definition: trace.h:411
static size_t trace_buf_size
Definition: utrace.c:60
uint64_t m0_time_seconds(const m0_time_t time)
Definition: time.c:83
#define PRId64
Definition: types.h:57
const char * td_file
Definition: trace.h:509
static int calc_extra_trace_descr_offsets(const struct m0_trace_buf_header *tbh, const void *magic_symbols[], size_t nr, ptrdiff_t td_offsets[])
Definition: utrace.c:476
uint64_t n
Definition: fops.h:107
const void * tbh_buf_addr
Definition: trace.h:374
const void * tbh_module_core_addr
Definition: trace.h:407
void m0_console_flush(void)
Definition: ktrace.c:165
uint32_t tbh_header_size
Definition: trace.h:372
const void * tbh_magic_sym_addr
Definition: trace.h:392
int td_size
Definition: trace.h:512
static char trace_file_path[PATH_MAX]
Definition: utrace.c:59
M0_INTERNAL int m0_trace_set_immediate_mask(const char *mask_str)
Definition: ktrace.c:77
int m0_trace_set_buffer_size(size_t size)
Definition: utrace.c:166
m0_bcount_t size
Definition: di.c:39
static int logfd
Definition: utrace.c:57
const int * td_sizeof
Definition: trace.h:515
#define CMDLINE
M0_INTERNAL int m0_trace_parse(FILE *trace_file, FILE *output_file, const char *m0tr_ko_path, enum m0_trace_parse_flags flags, const void *magic_symbols[], unsigned int magic_symbols_nr)
Definition: utrace.c:527
const struct m0_trace_descr * trh_descr
Definition: trace.h:445
unsigned long m0_trace_immediate_mask
Definition: trace.c:91
M0_INTERNAL const void * m0_trace_magic_sym_addr_get(void)
Definition: trace.c:644
M0_INTERNAL int m0_arch_trace_init()
Definition: ktrace.c:178
M0_INTERNAL void m0_arch_trace_buf_header_init(struct m0_trace_buf_header *tbh)
Definition: ktrace.c:233
struct m0_trace_buf_header * m0_logbuf_header
Definition: trace.c:85
uint64_t trh_magic
Definition: trace.h:440
void m0_free(void *data)
Definition: memory.c:146
static struct m0_addb2_source * s
Definition: consumer.c:39
m0_time_t tbh_log_time
Definition: trace.h:400
static int calc_trace_descr_offset(const struct m0_trace_buf_header *tbh, const char *m0tr_ko_path, ptrdiff_t *td_offset)
Definition: utrace.c:438
int32_t rc
Definition: trigger_fop.h:47
M0_INTERNAL void m0_trace_set_mmapped_buffer(bool val)
Definition: utrace.c:156
#define ARRAY_SIZE(a)
Definition: misc.h:45
static uint64_t m0_align(uint64_t val, uint64_t alignment)
Definition: arith.h:170
uint16_t tbh_buf_type
Definition: trace.h:378
static bool use_mmaped_buffer
Definition: utrace.c:58
static int logbuf_map()
Definition: utrace.c:62
M0_INTERNAL int m0_trace_set_level(const char *level_str)
Definition: trace.c:581