aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/scripting-engines/trace-event-python.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/scripting-engines/trace-event-python.c')
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c84
1 files changed, 83 insertions, 1 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index f3ca7798b3d0..cb1d9602f418 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -37,6 +37,7 @@
37#include "../comm.h" 37#include "../comm.h"
38#include "../machine.h" 38#include "../machine.h"
39#include "../db-export.h" 39#include "../db-export.h"
40#include "../thread-stack.h"
40#include "../trace-event.h" 41#include "../trace-event.h"
41#include "../machine.h" 42#include "../machine.h"
42 43
@@ -68,6 +69,8 @@ struct tables {
68 PyObject *symbol_handler; 69 PyObject *symbol_handler;
69 PyObject *branch_type_handler; 70 PyObject *branch_type_handler;
70 PyObject *sample_handler; 71 PyObject *sample_handler;
72 PyObject *call_path_handler;
73 PyObject *call_return_handler;
71 bool db_export_mode; 74 bool db_export_mode;
72}; 75};
73 76
@@ -720,6 +723,64 @@ static int python_export_sample(struct db_export *dbe,
720 return 0; 723 return 0;
721} 724}
722 725
726static int python_export_call_path(struct db_export *dbe, struct call_path *cp)
727{
728 struct tables *tables = container_of(dbe, struct tables, dbe);
729 PyObject *t;
730 u64 parent_db_id, sym_db_id;
731
732 parent_db_id = cp->parent ? cp->parent->db_id : 0;
733 sym_db_id = cp->sym ? *(u64 *)symbol__priv(cp->sym) : 0;
734
735 t = tuple_new(4);
736
737 tuple_set_u64(t, 0, cp->db_id);
738 tuple_set_u64(t, 1, parent_db_id);
739 tuple_set_u64(t, 2, sym_db_id);
740 tuple_set_u64(t, 3, cp->ip);
741
742 call_object(tables->call_path_handler, t, "call_path_table");
743
744 Py_DECREF(t);
745
746 return 0;
747}
748
749static int python_export_call_return(struct db_export *dbe,
750 struct call_return *cr)
751{
752 struct tables *tables = container_of(dbe, struct tables, dbe);
753 u64 comm_db_id = cr->comm ? cr->comm->db_id : 0;
754 PyObject *t;
755
756 t = tuple_new(11);
757
758 tuple_set_u64(t, 0, cr->db_id);
759 tuple_set_u64(t, 1, cr->thread->db_id);
760 tuple_set_u64(t, 2, comm_db_id);
761 tuple_set_u64(t, 3, cr->cp->db_id);
762 tuple_set_u64(t, 4, cr->call_time);
763 tuple_set_u64(t, 5, cr->return_time);
764 tuple_set_u64(t, 6, cr->branch_count);
765 tuple_set_u64(t, 7, cr->call_ref);
766 tuple_set_u64(t, 8, cr->return_ref);
767 tuple_set_u64(t, 9, cr->cp->parent->db_id);
768 tuple_set_s32(t, 10, cr->flags);
769
770 call_object(tables->call_return_handler, t, "call_return_table");
771
772 Py_DECREF(t);
773
774 return 0;
775}
776
777static int python_process_call_return(struct call_return *cr, void *data)
778{
779 struct db_export *dbe = data;
780
781 return db_export__call_return(dbe, cr);
782}
783
723static void python_process_general_event(struct perf_sample *sample, 784static void python_process_general_event(struct perf_sample *sample,
724 struct perf_evsel *evsel, 785 struct perf_evsel *evsel,
725 struct thread *thread, 786 struct thread *thread,
@@ -852,7 +913,9 @@ error:
852static void set_table_handlers(struct tables *tables) 913static void set_table_handlers(struct tables *tables)
853{ 914{
854 const char *perf_db_export_mode = "perf_db_export_mode"; 915 const char *perf_db_export_mode = "perf_db_export_mode";
855 PyObject *db_export_mode; 916 const char *perf_db_export_calls = "perf_db_export_calls";
917 PyObject *db_export_mode, *db_export_calls;
918 bool export_calls = false;
856 int ret; 919 int ret;
857 920
858 memset(tables, 0, sizeof(struct tables)); 921 memset(tables, 0, sizeof(struct tables));
@@ -869,6 +932,23 @@ static void set_table_handlers(struct tables *tables)
869 if (!ret) 932 if (!ret)
870 return; 933 return;
871 934
935 tables->dbe.crp = NULL;
936 db_export_calls = PyDict_GetItemString(main_dict, perf_db_export_calls);
937 if (db_export_calls) {
938 ret = PyObject_IsTrue(db_export_calls);
939 if (ret == -1)
940 handler_call_die(perf_db_export_calls);
941 export_calls = !!ret;
942 }
943
944 if (export_calls) {
945 tables->dbe.crp =
946 call_return_processor__new(python_process_call_return,
947 &tables->dbe);
948 if (!tables->dbe.crp)
949 Py_FatalError("failed to create calls processor");
950 }
951
872 tables->db_export_mode = true; 952 tables->db_export_mode = true;
873 /* 953 /*
874 * Reserve per symbol space for symbol->db_id via symbol__priv() 954 * Reserve per symbol space for symbol->db_id via symbol__priv()
@@ -884,6 +964,8 @@ static void set_table_handlers(struct tables *tables)
884 SET_TABLE_HANDLER(symbol); 964 SET_TABLE_HANDLER(symbol);
885 SET_TABLE_HANDLER(branch_type); 965 SET_TABLE_HANDLER(branch_type);
886 SET_TABLE_HANDLER(sample); 966 SET_TABLE_HANDLER(sample);
967 SET_TABLE_HANDLER(call_path);
968 SET_TABLE_HANDLER(call_return);
887} 969}
888 970
889/* 971/*