Linux Perf
data-convert-bt.c File Reference
#include <errno.h>
#include <inttypes.h>
#include <linux/compiler.h>
#include <linux/kernel.h>
#include <babeltrace/ctf-writer/writer.h>
#include <babeltrace/ctf-writer/clock.h>
#include <babeltrace/ctf-writer/stream.h>
#include <babeltrace/ctf-writer/event.h>
#include <babeltrace/ctf-writer/event-types.h>
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-ir/utils.h>
#include <babeltrace/ctf/events.h>
#include <traceevent/event-parse.h>
#include "asm/bug.h"
#include "data-convert-bt.h"
#include "session.h"
#include "util.h"
#include "debug.h"
#include "tool.h"
#include "evlist.h"
#include "evsel.h"
#include "machine.h"
#include "config.h"
#include "sane_ctype.h"
Include dependency graph for data-convert-bt.c:

Go to the source code of this file.

Classes

struct  evsel_priv
 
struct  ctf_stream
 
struct  ctf_writer
 
struct  convert
 

Macros

#define pr_N(n, fmt, ...)   eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
 
#define pr(fmt, ...)   pr_N(1, pr_fmt(fmt), ##__VA_ARGS__)
 
#define pr2(fmt, ...)   pr_N(2, pr_fmt(fmt), ##__VA_ARGS__)
 
#define pr_time2(t, fmt, ...)   pr_time_N(2, debug_data_convert, t, pr_fmt(fmt), ##__VA_ARGS__)
 
#define MAX_CPUS   4096
 
#define __FUNC_VALUE_SET(_name, _val_type)
 
#define FUNC_VALUE_SET(_name)   __FUNC_VALUE_SET(_name, _name)
 
#define STREAM_FLUSH_COUNT   100000
 
#define __NON_SAMPLE_SET_FIELD(_name, _type, _field)
 
#define __FUNC_PROCESS_NON_SAMPLE(_name, body)
 
#define ADD_FIELD(cl, t, n)
 
#define __NON_SAMPLE_ADD_FIELD(t, n)
 
#define __FUNC_ADD_NON_SAMPLE_EVENT_CLASS(_name, body)
 
#define ADD(__n, __v)
 
#define SET(__n, __v)
 
#define CREATE_INT_TYPE(type, size, sign, hex)
 

Functions

static int value_set (struct bt_ctf_field_type *type, struct bt_ctf_event *event, const char *name, u64 val)
 
static int string_set_value (struct bt_ctf_field *field, const char *string)
 
static __maybe_unused int value_set_string (struct ctf_writer *cw, struct bt_ctf_event *event, const char *name, const char *string)
 
static struct bt_ctf_field_type * get_tracepoint_field_type (struct ctf_writer *cw, struct format_field *field)
 
static unsigned long long adjust_signedness (unsigned long long value_int, int size)
 
static int add_tracepoint_field_value (struct ctf_writer *cw, struct bt_ctf_event_class *event_class, struct bt_ctf_event *event, struct perf_sample *sample, struct format_field *fmtf)
 
static int add_tracepoint_fields_values (struct ctf_writer *cw, struct bt_ctf_event_class *event_class, struct bt_ctf_event *event, struct format_field *fields, struct perf_sample *sample)
 
static int add_tracepoint_values (struct ctf_writer *cw, struct bt_ctf_event_class *event_class, struct bt_ctf_event *event, struct perf_evsel *evsel, struct perf_sample *sample)
 
static int add_bpf_output_values (struct bt_ctf_event_class *event_class, struct bt_ctf_event *event, struct perf_sample *sample)
 
static int add_callchain_output_values (struct bt_ctf_event_class *event_class, struct bt_ctf_event *event, struct ip_callchain *callchain)
 
static int add_generic_values (struct ctf_writer *cw, struct bt_ctf_event *event, struct perf_evsel *evsel, struct perf_sample *sample)
 
static int ctf_stream__flush (struct ctf_stream *cs)
 
static struct ctf_streamctf_stream__create (struct ctf_writer *cw, int cpu)
 
static void ctf_stream__delete (struct ctf_stream *cs)
 
static struct ctf_streamctf_stream (struct ctf_writer *cw, int cpu)
 
static int get_sample_cpu (struct ctf_writer *cw, struct perf_sample *sample, struct perf_evsel *evsel)
 
static bool is_flush_needed (struct ctf_stream *cs)
 
static int process_sample_event (struct perf_tool *tool, union perf_event *_event, struct perf_sample *sample, struct perf_evsel *evsel, struct machine *machine __maybe_unused)
 
 __FUNC_PROCESS_NON_SAMPLE (comm, __NON_SAMPLE_SET_FIELD(comm, u32, pid);__NON_SAMPLE_SET_FIELD(comm, u32, tid);__NON_SAMPLE_SET_FIELD(comm, string, comm);)
 
static int event_class_add_field (struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, struct format_field *field)
 
static int add_tracepoint_fields_types (struct ctf_writer *cw, struct format_field *fields, struct bt_ctf_event_class *event_class)
 
static int add_tracepoint_types (struct ctf_writer *cw, struct perf_evsel *evsel, struct bt_ctf_event_class *class)
 
static int add_bpf_output_types (struct ctf_writer *cw, struct bt_ctf_event_class *class)
 
static int add_generic_types (struct ctf_writer *cw, struct perf_evsel *evsel, struct bt_ctf_event_class *event_class)
 
static int add_event (struct ctf_writer *cw, struct perf_evsel *evsel)
 
static int setup_events (struct ctf_writer *cw, struct perf_session *session)
 
 __FUNC_ADD_NON_SAMPLE_EVENT_CLASS (comm, __NON_SAMPLE_ADD_FIELD(u32, pid);__NON_SAMPLE_ADD_FIELD(u32, tid);__NON_SAMPLE_ADD_FIELD(string, comm);)
 
static void cleanup_events (struct perf_session *session)
 
static int setup_streams (struct ctf_writer *cw, struct perf_session *session)
 
static void free_streams (struct ctf_writer *cw)
 
static int ctf_writer__setup_env (struct ctf_writer *cw, struct perf_session *session)
 
static int ctf_writer__setup_clock (struct ctf_writer *cw)
 
static struct bt_ctf_field_type * create_int_type (int size, bool sign, bool hex)
 
static void ctf_writer__cleanup_data (struct ctf_writer *cw)
 
static int ctf_writer__init_data (struct ctf_writer *cw)
 
static void ctf_writer__cleanup (struct ctf_writer *cw)
 
static int ctf_writer__init (struct ctf_writer *cw, const char *path)
 
static int ctf_writer__flush_streams (struct ctf_writer *cw)
 
static int convert__config (const char *var, const char *value, void *cb)
 
int bt_convert__perf2ctf (const char *input, const char *path, struct perf_data_convert_opts *opts)
 

Macro Definition Documentation

◆ __FUNC_ADD_NON_SAMPLE_EVENT_CLASS

#define __FUNC_ADD_NON_SAMPLE_EVENT_CLASS (   _name,
  body 
)
Value:
static int add_##_name##_event(struct ctf_writer *cw) \
{ \
struct bt_ctf_event_class *event_class; \
int ret; \
pr("Adding "#_name" event\n"); \
event_class = bt_ctf_event_class_create("perf_" #_name);\
if (!event_class) \
return -1; \
body \
\
ret = bt_ctf_stream_class_add_event_class(cw->stream_class, event_class);\
if (ret) { \
pr("Failed to add event class '"#_name"' into stream.\n");\
return ret; \
} \
\
cw->_name##_class = event_class; \
bt_ctf_event_class_put(event_class); \
return 0; \
}
#define pr(fmt,...)

Definition at line 1226 of file data-convert-bt.c.

◆ __FUNC_PROCESS_NON_SAMPLE

#define __FUNC_PROCESS_NON_SAMPLE (   _name,
  body 
)

Definition at line 864 of file data-convert-bt.c.

◆ __FUNC_VALUE_SET

#define __FUNC_VALUE_SET (   _name,
  _val_type 
)
Value:
static __maybe_unused int value_set_##_name(struct ctf_writer *cw, \
struct bt_ctf_event *event, \
const char *name, \
_val_type val) \
{ \
struct bt_ctf_field_type *type = cw->data._name; \
return value_set(type, event, name, (u64) val); \
}
const char * name
#define event
static int value_set(struct bt_ctf_field_type *type, struct bt_ctf_event *event, const char *name, u64 val)

Definition at line 136 of file data-convert-bt.c.

◆ __NON_SAMPLE_ADD_FIELD

#define __NON_SAMPLE_ADD_FIELD (   t,
 
)
Value:
do { \
pr2(" field '%s'\n", #n); \
if (bt_ctf_event_class_add_field(event_class, cw->data.t, #n)) {\
pr_err("Failed to add field '%s';\n", #n);\
return -1; \
} \
} while(0)

Definition at line 1217 of file data-convert-bt.c.

◆ __NON_SAMPLE_SET_FIELD

#define __NON_SAMPLE_SET_FIELD (   _name,
  _type,
  _field 
)
Value:
do { \
ret = value_set_##_type(cw, event, #_field, _event->_name._field);\
if (ret) \
return -1; \
} while(0)
#define event

Definition at line 857 of file data-convert-bt.c.

◆ ADD

#define ADD (   __n,
  __v 
)
Value:
do { \
if (bt_ctf_writer_add_environment_field(writer, __n, __v)) \
return -1; \
} while (0)

◆ ADD_FIELD

#define ADD_FIELD (   cl,
  t,
 
)
Value:
do { \
pr2(" field '%s'\n", n); \
if (bt_ctf_event_class_add_field(cl, t, n)) { \
pr_err("Failed to add field '%s';\n", n); \
return -1; \
} \
} while (0)

◆ CREATE_INT_TYPE

#define CREATE_INT_TYPE (   type,
  size,
  sign,
  hex 
)
Value:
do { \
(type) = create_int_type(size, sign, hex); \
if (!(type)) \
goto err; \
} while (0)
static unsigned int hex(char c)
Definition: code-reading.c:33
size_t size
Definition: evsel.c:60
int int err
Definition: 5sec.c:44
static struct bt_ctf_field_type * create_int_type(int size, bool sign, bool hex)

◆ FUNC_VALUE_SET

#define FUNC_VALUE_SET (   _name)    __FUNC_VALUE_SET(_name, _name)

Definition at line 146 of file data-convert-bt.c.

◆ MAX_CPUS

#define MAX_CPUS   4096

Definition at line 47 of file data-convert-bt.c.

◆ pr

#define pr (   fmt,
  ... 
)    pr_N(1, pr_fmt(fmt), ##__VA_ARGS__)

Definition at line 38 of file data-convert-bt.c.

◆ pr2

#define pr2 (   fmt,
  ... 
)    pr_N(2, pr_fmt(fmt), ##__VA_ARGS__)

Definition at line 39 of file data-convert-bt.c.

◆ pr_N

#define pr_N (   n,
  fmt,
  ... 
)    eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)

Definition at line 35 of file data-convert-bt.c.

◆ pr_time2

#define pr_time2 (   t,
  fmt,
  ... 
)    pr_time_N(2, debug_data_convert, t, pr_fmt(fmt), ##__VA_ARGS__)

Definition at line 41 of file data-convert-bt.c.

◆ SET

#define SET (   __n,
  __v 
)
Value:
do { \
if (bt_ctf_clock_set_##__n(clock, __v)) \
return -1; \
} while (0)

◆ STREAM_FLUSH_COUNT

#define STREAM_FLUSH_COUNT   100000

Definition at line 773 of file data-convert-bt.c.

Function Documentation

◆ __FUNC_ADD_NON_SAMPLE_EVENT_CLASS()

__FUNC_ADD_NON_SAMPLE_EVENT_CLASS ( comm  ,
__NON_SAMPLE_ADD_FIELD(u32, pid);__NON_SAMPLE_ADD_FIELD(u32, tid);__NON_SAMPLE_ADD_FIELD(string, comm);   
)

Definition at line 1249 of file data-convert-bt.c.

◆ __FUNC_PROCESS_NON_SAMPLE()

__FUNC_PROCESS_NON_SAMPLE ( comm  ,
__NON_SAMPLE_SET_FIELD(comm, u32, pid);__NON_SAMPLE_SET_FIELD(comm, u32, tid);__NON_SAMPLE_SET_FIELD(comm, string, comm);   
)

Definition at line 900 of file data-convert-bt.c.

◆ add_bpf_output_types()

static int add_bpf_output_types ( struct ctf_writer cw,
struct bt_ctf_event_class *  class 
)
static

Definition at line 1069 of file data-convert-bt.c.

◆ add_bpf_output_values()

static int add_bpf_output_values ( struct bt_ctf_event_class *  event_class,
struct bt_ctf_event *  event,
struct perf_sample sample 
)
static

Definition at line 434 of file data-convert-bt.c.

◆ add_callchain_output_values()

static int add_callchain_output_values ( struct bt_ctf_event_class *  event_class,
struct bt_ctf_event *  event,
struct ip_callchain callchain 
)
static

Definition at line 512 of file data-convert-bt.c.

◆ add_event()

static int add_event ( struct ctf_writer cw,
struct perf_evsel evsel 
)
static

Definition at line 1154 of file data-convert-bt.c.

Here is the call graph for this function:

◆ add_generic_types()

static int add_generic_types ( struct ctf_writer cw,
struct perf_evsel evsel,
struct bt_ctf_event_class *  event_class 
)
static

Definition at line 1088 of file data-convert-bt.c.

◆ add_generic_values()

static int add_generic_values ( struct ctf_writer cw,
struct bt_ctf_event *  event,
struct perf_evsel evsel,
struct perf_sample sample 
)
static

Definition at line 586 of file data-convert-bt.c.

◆ add_tracepoint_field_value()

static int add_tracepoint_field_value ( struct ctf_writer cw,
struct bt_ctf_event_class *  event_class,
struct bt_ctf_event *  event,
struct perf_sample sample,
struct format_field *  fmtf 
)
static

Definition at line 286 of file data-convert-bt.c.

Here is the call graph for this function:

◆ add_tracepoint_fields_types()

static int add_tracepoint_fields_types ( struct ctf_writer cw,
struct format_field *  fields,
struct bt_ctf_event_class *  event_class 
)
static

Definition at line 1011 of file data-convert-bt.c.

Here is the call graph for this function:

◆ add_tracepoint_fields_values()

static int add_tracepoint_fields_values ( struct ctf_writer cw,
struct bt_ctf_event_class *  event_class,
struct bt_ctf_event *  event,
struct format_field *  fields,
struct perf_sample sample 
)
static

Definition at line 396 of file data-convert-bt.c.

Here is the call graph for this function:

◆ add_tracepoint_types()

static int add_tracepoint_types ( struct ctf_writer cw,
struct perf_evsel evsel,
struct bt_ctf_event_class *  class 
)
static

Definition at line 1054 of file data-convert-bt.c.

Here is the call graph for this function:

◆ add_tracepoint_values()

static int add_tracepoint_values ( struct ctf_writer cw,
struct bt_ctf_event_class *  event_class,
struct bt_ctf_event *  event,
struct perf_evsel evsel,
struct perf_sample sample 
)
static

Definition at line 414 of file data-convert-bt.c.

Here is the call graph for this function:

◆ adjust_signedness()

static unsigned long long adjust_signedness ( unsigned long long  value_int,
int  size 
)
static

Definition at line 211 of file data-convert-bt.c.

◆ bt_convert__perf2ctf()

int bt_convert__perf2ctf ( const char *  input,
const char *  path,
struct perf_data_convert_opts opts 
)

Definition at line 1576 of file data-convert-bt.c.

Here is the call graph for this function:

◆ cleanup_events()

static void cleanup_events ( struct perf_session session)
static

Definition at line 1310 of file data-convert-bt.c.

Here is the call graph for this function:

◆ convert__config()

static int convert__config ( const char *  var,
const char *  value,
void *  cb 
)
static

Definition at line 1566 of file data-convert-bt.c.

Here is the call graph for this function:

◆ create_int_type()

static struct bt_ctf_field_type* create_int_type ( int  size,
bool  sign,
bool  hex 
)
static

Definition at line 1406 of file data-convert-bt.c.

◆ ctf_stream()

static struct ctf_stream* ctf_stream ( struct ctf_writer cw,
int  cpu 
)
static

Definition at line 744 of file data-convert-bt.c.

Here is the call graph for this function:

◆ ctf_stream__create()

static struct ctf_stream* ctf_stream__create ( struct ctf_writer cw,
int  cpu 
)
static

Definition at line 681 of file data-convert-bt.c.

Here is the call graph for this function:

◆ ctf_stream__delete()

static void ctf_stream__delete ( struct ctf_stream cs)
static

Definition at line 736 of file data-convert-bt.c.

Here is the call graph for this function:

◆ ctf_stream__flush()

static int ctf_stream__flush ( struct ctf_stream cs)
static

Definition at line 663 of file data-convert-bt.c.

◆ ctf_writer__cleanup()

static void ctf_writer__cleanup ( struct ctf_writer cw)
static

Definition at line 1471 of file data-convert-bt.c.

Here is the call graph for this function:

◆ ctf_writer__cleanup_data()

static void ctf_writer__cleanup_data ( struct ctf_writer cw)
static

Definition at line 1437 of file data-convert-bt.c.

◆ ctf_writer__flush_streams()

static int ctf_writer__flush_streams ( struct ctf_writer cw)
static

Definition at line 1556 of file data-convert-bt.c.

Here is the call graph for this function:

◆ ctf_writer__init()

static int ctf_writer__init ( struct ctf_writer cw,
const char *  path 
)
static

Definition at line 1484 of file data-convert-bt.c.

Here is the call graph for this function:

◆ ctf_writer__init_data()

static int ctf_writer__init_data ( struct ctf_writer cw)
static

Definition at line 1445 of file data-convert-bt.c.

Here is the call graph for this function:

◆ ctf_writer__setup_clock()

static int ctf_writer__setup_clock ( struct ctf_writer cw)
static

Definition at line 1384 of file data-convert-bt.c.

◆ ctf_writer__setup_env()

static int ctf_writer__setup_env ( struct ctf_writer cw,
struct perf_session session 
)
static

Definition at line 1360 of file data-convert-bt.c.

◆ event_class_add_field()

static int event_class_add_field ( struct bt_ctf_event_class *  event_class,
struct bt_ctf_field_type *  type,
struct format_field *  field 
)
static

Definition at line 971 of file data-convert-bt.c.

◆ free_streams()

static void free_streams ( struct ctf_writer cw)
static

Definition at line 1350 of file data-convert-bt.c.

Here is the call graph for this function:

◆ get_sample_cpu()

static int get_sample_cpu ( struct ctf_writer cw,
struct perf_sample sample,
struct perf_evsel evsel 
)
static

Definition at line 756 of file data-convert-bt.c.

◆ get_tracepoint_field_type()

static struct bt_ctf_field_type* get_tracepoint_field_type ( struct ctf_writer cw,
struct format_field *  field 
)
static

Definition at line 185 of file data-convert-bt.c.

◆ is_flush_needed()

static bool is_flush_needed ( struct ctf_stream cs)
static

Definition at line 781 of file data-convert-bt.c.

◆ process_sample_event()

static int process_sample_event ( struct perf_tool tool,
union perf_event _event,
struct perf_sample sample,
struct perf_evsel evsel,
struct machine *machine  __maybe_unused 
)
static

Definition at line 786 of file data-convert-bt.c.

Here is the call graph for this function:

◆ setup_events()

static int setup_events ( struct ctf_writer cw,
struct perf_session session 
)
static

Definition at line 1203 of file data-convert-bt.c.

Here is the call graph for this function:

◆ setup_streams()

static int setup_streams ( struct ctf_writer cw,
struct perf_session session 
)
static

Definition at line 1327 of file data-convert-bt.c.

Here is the call graph for this function:

◆ string_set_value()

static int string_set_value ( struct bt_ctf_field *  field,
const char *  string 
)
static

Definition at line 248 of file data-convert-bt.c.

Here is the call graph for this function:

◆ value_set()

static int value_set ( struct bt_ctf_field_type *  type,
struct bt_ctf_event *  event,
const char *  name,
u64  val 
)
static

Definition at line 95 of file data-convert-bt.c.

◆ value_set_string()

static __maybe_unused int value_set_string ( struct ctf_writer cw,
struct bt_ctf_event *  event,
const char *  name,
const char *  string 
)
static

Definition at line 156 of file data-convert-bt.c.

Here is the call graph for this function: