#include <linux/bitmap.h>
#include <linux/compiler.h>
#include <linux/time64.h>
+#ifdef HAVE_LIBTRACEEVENT
#include <traceevent/event-parse.h>
+#endif
#include "../build-id.h"
#include "../counts.h"
PyMODINIT_FUNC PyInit_perf_trace_context(void);
#endif
+#ifdef HAVE_LIBTRACEEVENT
#define TRACE_EVENT_TYPE_MAX \
((1 << (sizeof(unsigned short) * 8)) - 1)
static DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX);
-#define MAX_FIELDS 64
#define N_COMMON_FIELDS 7
-extern struct scripting_context *scripting_context;
-
static char *cur_field_name;
static int zero_flag_atom;
+#endif
+
+#define MAX_FIELDS 64
+
+extern struct scripting_context *scripting_context;
static PyObject *main_module, *main_dict;
return handler;
}
+static void call_object(PyObject *handler, PyObject *args, const char *die_msg)
+{
+ PyObject *retval;
+
+ retval = PyObject_CallObject(handler, args);
+ if (retval == NULL)
+ handler_call_die(die_msg);
+ Py_DECREF(retval);
+}
+
+static void try_call_object(const char *handler_name, PyObject *args)
+{
+ PyObject *handler;
+
+ handler = get_handler(handler_name);
+ if (handler)
+ call_object(handler, args, handler_name);
+}
+
+#ifdef HAVE_LIBTRACEEVENT
static int get_argument_count(PyObject *handler)
{
int arg_count = 0;
return arg_count;
}
-static void call_object(PyObject *handler, PyObject *args, const char *die_msg)
-{
- PyObject *retval;
-
- retval = PyObject_CallObject(handler, args);
- if (retval == NULL)
- handler_call_die(die_msg);
- Py_DECREF(retval);
-}
-
-static void try_call_object(const char *handler_name, PyObject *args)
-{
- PyObject *handler;
-
- handler = get_handler(handler_name);
- if (handler)
- call_object(handler, args, handler_name);
-}
-
static void define_value(enum tep_print_arg_type field_type,
const char *ev_name,
const char *field_name,
obj = list;
return obj;
}
+#endif
static const char *get_dsoname(struct map *map)
{
const char *dsoname = "[unknown]";
+ struct dso *dso = map ? map__dso(map) : NULL;
- if (map && map->dso) {
- if (symbol_conf.show_kernel_path && map->dso->long_name)
- dsoname = map->dso->long_name;
+ if (dso) {
+ if (symbol_conf.show_kernel_path && dso->long_name)
+ dsoname = dso->long_name;
else
- dsoname = map->dso->name;
+ dsoname = dso->name;
}
return dsoname;
if (al->addr < sym->end)
offset = al->addr - sym->start;
else
- offset = al->addr - al->map->start - sym->start;
+ offset = al->addr - map__start(al->map) - sym->start;
return offset;
}
struct addr_location node_al;
unsigned long offset;
- node_al.addr = map->map_ip(map, node->ip);
+ node_al.addr = map__map_ip(map, node->ip);
node_al.map = map;
offset = get_offset(node->ms.sym, &node_al);
char sbuild_id[SBUILD_ID_SIZE];
if (al->map) {
- pydict_set_item_string_decref(dict, dso_field,
- _PyUnicode_FromString(al->map->dso->name));
- build_id__sprintf(&al->map->dso->bid, sbuild_id);
+ struct dso *dso = map__dso(al->map);
+
+ pydict_set_item_string_decref(dict, dso_field, _PyUnicode_FromString(dso->name));
+ build_id__sprintf(&dso->bid, sbuild_id);
pydict_set_item_string_decref(dict, dso_bid_field,
_PyUnicode_FromString(sbuild_id));
pydict_set_item_string_decref(dict, dso_map_start,
- PyLong_FromUnsignedLong(al->map->start));
+ PyLong_FromUnsignedLong(map__start(al->map)));
pydict_set_item_string_decref(dict, dso_map_end,
- PyLong_FromUnsignedLong(al->map->end));
+ PyLong_FromUnsignedLong(map__end(al->map)));
}
if (al->sym) {
pydict_set_item_string_decref(dict, sym_field,
return dict;
}
+#ifdef HAVE_LIBTRACEEVENT
static void python_process_tracepoint(struct perf_sample *sample,
struct evsel *evsel,
struct addr_location *al,
Py_DECREF(t);
}
+#else
+static void python_process_tracepoint(struct perf_sample *sample __maybe_unused,
+ struct evsel *evsel __maybe_unused,
+ struct addr_location *al __maybe_unused,
+ struct addr_location *addr_al __maybe_unused)
+{
+ fprintf(stderr, "Tracepoint events are not supported because "
+ "perf is not linked with libtraceevent.\n");
+}
+#endif
static PyObject *tuple_new(unsigned int sz)
{
tuple_set_d64(t, 0, es->db_id);
tuple_set_d64(t, 1, es->evsel->db_id);
- tuple_set_d64(t, 2, es->al->maps->machine->db_id);
+ tuple_set_d64(t, 2, maps__machine(es->al->maps)->db_id);
tuple_set_d64(t, 3, es->al->thread->db_id);
tuple_set_d64(t, 4, es->comm_db_id);
tuple_set_d64(t, 5, es->dso_db_id);
return 0;
}
+#ifdef HAVE_LIBTRACEEVENT
static int python_generate_script(struct tep_handle *pevent, const char *outfile)
{
int i, not_first, count, nr_events;
return 0;
}
+#else
+static int python_generate_script(struct tep_handle *pevent __maybe_unused,
+ const char *outfile __maybe_unused)
+{
+ fprintf(stderr, "Generating Python perf-script is not supported."
+ " Install libtraceevent and rebuild perf to enable it.\n"
+ "For example:\n # apt install libtraceevent-dev (ubuntu)"
+ "\n # yum install libtraceevent-devel (Fedora)"
+ "\n etc.\n");
+ return -1;
+}
+#endif
struct scripting_ops python_scripting_ops = {
.name = "Python",