return get_args(args, "context", NULL);
}
+#ifdef HAVE_LIBTRACEEVENT
static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
{
struct scripting_context *c = get_scripting_context(args);
return Py_BuildValue("i", common_lock_depth(c));
}
+#endif
static PyObject *perf_sample_insn(PyObject *obj, PyObject *args)
{
}
static PyMethodDef ContextMethods[] = {
+#ifdef HAVE_LIBTRACEEVENT
{ "common_pc", perf_trace_context_common_pc, METH_VARARGS,
"Get the common preempt count event field value."},
{ "common_flags", perf_trace_context_common_flags, METH_VARARGS,
"Get the common flags event field value."},
{ "common_lock_depth", perf_trace_context_common_lock_depth,
METH_VARARGS, "Get the common lock depth event field value."},
+#endif
{ "perf_sample_insn", perf_sample_insn,
METH_VARARGS, "Get the machine code instruction."},
{ "perf_set_itrace_options", perf_set_itrace_options,
#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)
{
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)
{
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",