perf db-export: Comm tidy-up and export switch events
Adrian Hunter
reviewercover perf db-export: Comm tidy-up and export switch events
Hi
Here are some patches that tidy up the export of comms and then add the export of switch information. Switch information provides a simple way to get an overview of activity.
The first 7 patches are tidy-up:
perf db-export: Get rid of db_export__deferred()
perf db-export: Rename db_export__comm() to db_export__exec_comm() perf db-export: Pass main_thread to db_export__thread() perf db-export: Export main_thread in db_export__sample() perf db-export: Export comm before exporting thread perf db-export: Move export__comm_thread into db_export__sample() perf db-export: Fix a white space issue in db_export__sample()
Then there are 3 to export more comm details:
perf db-export: Export comm details
perf scripts python: export-to-sqlite.py: Export comm details perf scripts python: export-to-postgresql.py: Export comm details
Then there are 6 relating to exporting a thread's current comm:
perf db-export: Factor out db_export__comm()
perf db-export: Also export thread's current comm
perf scripts python: export-to-sqlite.py: Add has_calls column to comms table perf scripts python: export-to-postgresql.py: Add has_calls column to comms table perf scripts python: exported-sql-viewer.py: Remove redundant semi-colons perf scripts python: exported-sql-viewer.py: Use new 'has_calls' column
Finally there are 5 to export switch events:
perf script: Add scripting operation process_switch() perf db-export: Factor out db_export__threads()
perf db-export: Export switch events
perf scripts python: export-to-sqlite.py: Export switch events perf scripts python: export-to-postgresql.py: Export switch events
Adrian Hunter (21):
perf db-export: Get rid of db_export__deferred()
perf db-export: Rename db_export__comm() to db_export__exec_comm() perf db-export: Pass main_thread to db_export__thread()
perf db-export: Export main_thread in db_export__sample()
perf db-export: Export comm before exporting thread
perf db-export: Move export__comm_thread into db_export__sample() perf db-export: Fix a white space issue in db_export__sample()
perf db-export: Export comm details
perf scripts python: export-to-sqlite.py: Export comm details
perf scripts python: export-to-postgresql.py: Export comm details perf db-export: Factor out db_export__comm()
perf db-export: Also export thread's current comm
perf scripts python: export-to-sqlite.py: Add has_calls column to comms table perf scripts python: export-to-postgresql.py: Add has_calls column to comms table perf scripts python: exported-sql-viewer.py: Remove redundant semi-colons perf scripts python: exported-sql-viewer.py: Use new 'has_calls' column perf script: Add scripting operation process_switch()
perf db-export: Factor out db_export__threads()
perf db-export: Export switch events
perf scripts python: export-to-sqlite.py: Export switch events
perf scripts python: export-to-postgresql.py: Export switch events
tools/perf/builtin-script.c | 8 +- tools/perf/scripts/python/export-to-postgresql.py | 68 ++++- tools/perf/scripts/python/export-to-sqlite.py | 54 +++- tools/perf/scripts/python/exported-sql-viewer.py | 34 ++- tools/perf/util/db-export.c | 291 +++++++++++++-------- tools/perf/util/db-export.h | 19 +- .../util/scripting-engines/trace-event-python.c | 53 +++- tools/perf/util/trace-event.h | 3 + 8 files changed, 392 insertions(+), 138 deletions(-)
Regards
Adrian
Adrian Hunter
reviewerPATCH 1/21 perf db-export: Get rid of db_export__deferred()
db_export__deferred() deferred the export of comms if the comm string had not been "set" (changed from :<pid>) however that problem was fixed a long time ago by commit e803cf97a4f9 ("perf record: Synthesize COMM event for a command line workload"), so get rid of db_export__deferred().
--- tools/perf/util/db-export.c | 61 +------------------ tools/perf/util/db-export.h | 2 - .../scripting-engines/trace-event-python.c | 4 +- 3 files changed, 2 insertions(+), 65 deletions(-)
tools/perf/util/db-export.c +1 -60
@@ -19,70 +19,14 @@#include "call-path.h" #include "db-export.h" -struct deferred_export { -struct list_head node; -struct comm *comm; -}; - -static int db_export__deferred (struct db_export *dbe) -{ -struct deferred_export *de; -int err; - -while (!list_empty (&dbe->deferred)) { - de = list_entry(dbe->deferred.next, struct deferred_export, - node); - err = dbe->export_comm (dbe, de->comm); -list_del (&de->node); -free (de); -if (err) -return err; - } - -return 0 ; -} - -static void db_export__free_deferred (struct db_export *dbe) -{ -struct deferred_export *de; - -while (!list_empty (&dbe->deferred)) { - de = list_entry(dbe->deferred.next, struct deferred_export, - node); -list_del (&de->node); -free (de); - } -} - -static int db_export__defer_comm (struct db_export *dbe,struct comm *comm) -{ -struct deferred_export *de; - - de =zalloc (sizeof (struct deferred_export )); -if (!de) -return -ENOMEM ; - - de->comm = comm; -list_add_tail (&de->node, &dbe->deferred); - -return 0 ; -} -int db_export__init (struct db_export *dbe) {memset (dbe,0 ,sizeof (struct db_export )); -INIT_LIST_HEAD (&dbe->deferred);return 0 ; } -int db_export__flush (struct db_export *dbe) -{ -return db_export__deferred (dbe); -} -void db_export__exit (struct db_export *dbe) { -db_export__free_deferred (dbe);call_return_processor__free (dbe->crp); dbe->crp =NULL ; }
@@ -171,10 +115,7 @@ int db_export__comm(struct db_export *dbe, struct comm *comm, comm->db_id = ++dbe->comm_last_db_id;if (dbe->export_comm) { -if (main_thread->comm_set) - err = dbe->export_comm (dbe, comm); -else - err =db_export__defer_comm (dbe, comm); + err = dbe->export_comm (dbe, comm);if (err)return err; }
tools/perf/util/db-export.h +0 -2
@@ -68,11 +68,9 @@ struct db_export {u64 sample_last_db_id;u64 call_path_last_db_id;u64 call_return_last_db_id; -struct list_head deferred; };int db_export__init (struct db_export *dbe); -int db_export__flush (struct db_export *dbe);void db_export__exit (struct db_export *dbe);int db_export__evsel (struct db_export *dbe,struct perf_evsel *evsel);int db_export__machine (struct db_export *dbe,struct machine *machine);
tools/perf/util/scripting-engines/trace-event-python.c +1 -3
@@ -1620,9 +1620,7 @@ static int python_start_script(const char *script, int argc, const char **argv)static int python_flush_script (void ) { -struct tables *tables = &tables_global; - -return db_export__flush (&tables->dbe); +return 0 ; }/*
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Get rid of db_export__deferred()
perf db-export: Get rid of db_export__deferred()
Commit-ID: fead24e52383c3f8eb25b5426d52b430b84a8194 Gitweb: https://git.kernel.org/tip/fead24e52383c3f8eb25b5426d52b430b84a8194 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:57:50 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:07:40 -0300
perf db-export: Get rid of db_export__deferred()
db_export__deferred() deferred the export of comms if the comm string had not been "set" (changed from :<pid>) however that problem was fixed a long time ago by commit e803cf97a4f9 ("perf record: Synthesize COMM event for a command line workload"), so get rid of db_export__deferred().
--- tools/perf/util/db-export.c | 61 +--------------------- tools/perf/util/db-export.h | 2 - .../util/scripting-engines/trace-event-python.c | 4 +- 3 files changed, 2 insertions(+), 65 deletions(-)
tools/perf/util/db-export.c +1 -60
@@ -20,70 +20,14 @@#include "db-export.h" #include <linux/zalloc.h> -struct deferred_export { -struct list_head node; -struct comm *comm; -}; - -static int db_export__deferred (struct db_export *dbe) -{ -struct deferred_export *de; -int err; - -while (!list_empty (&dbe->deferred)) { - de = list_entry(dbe->deferred.next, struct deferred_export, - node); - err = dbe->export_comm (dbe, de->comm); -list_del_init (&de->node); -free (de); -if (err) -return err; - } - -return 0 ; -} - -static void db_export__free_deferred (struct db_export *dbe) -{ -struct deferred_export *de; - -while (!list_empty (&dbe->deferred)) { - de = list_entry(dbe->deferred.next, struct deferred_export, - node); -list_del_init (&de->node); -free (de); - } -} - -static int db_export__defer_comm (struct db_export *dbe,struct comm *comm) -{ -struct deferred_export *de; - - de =zalloc (sizeof (struct deferred_export )); -if (!de) -return -ENOMEM ; - - de->comm = comm; -list_add_tail (&de->node, &dbe->deferred); - -return 0 ; -} -int db_export__init (struct db_export *dbe) {memset (dbe,0 ,sizeof (struct db_export )); -INIT_LIST_HEAD (&dbe->deferred);return 0 ; } -int db_export__flush (struct db_export *dbe) -{ -return db_export__deferred (dbe); -} -void db_export__exit (struct db_export *dbe) { -db_export__free_deferred (dbe);call_return_processor__free (dbe->crp); dbe->crp =NULL ; }
@@ -172,10 +116,7 @@ int db_export__comm(struct db_export *dbe, struct comm *comm, comm->db_id = ++dbe->comm_last_db_id;if (dbe->export_comm) { -if (main_thread->comm_set) - err = dbe->export_comm (dbe, comm); -else - err =db_export__defer_comm (dbe, comm); + err = dbe->export_comm (dbe, comm);if (err)return err; }
tools/perf/util/db-export.h +0 -2
@@ -68,11 +68,9 @@ struct db_export {u64 sample_last_db_id;u64 call_path_last_db_id;u64 call_return_last_db_id; -struct list_head deferred; };int db_export__init (struct db_export *dbe); -int db_export__flush (struct db_export *dbe);void db_export__exit (struct db_export *dbe);int db_export__evsel (struct db_export *dbe,struct perf_evsel *evsel);int db_export__machine (struct db_export *dbe,struct machine *machine);
tools/perf/util/scripting-engines/trace-event-python.c +1 -3
@@ -1620,9 +1620,7 @@ error:static int python_flush_script (void ) { -struct tables *tables = &tables_global; - -return db_export__flush (&tables->dbe); +return 0 ; }/*
Adrian Hunter
reviewerPATCH 2/21 perf db-export: Rename db_export__comm() to db_export__exec_comm()
In reply to Adrian HunterRename db_export__comm() to db_export__exec_comm() to better reflect what it does and add explanatory comments.
--- tools/perf/util/db-export.c | 22 +++++++++++++++++++--- tools/perf/util/db-export.h | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-)
tools/perf/util/db-export.c +19 -3
@@ -104,8 +104,14 @@ int db_export__thread(struct db_export *dbe, struct thread *thread,return err; } -int db_export__comm (struct db_export *dbe,struct comm *comm, -struct thread *main_thread) +/* +* Export the "exec" comm. The "exec" comm is the program / application command +* name at the time it first executes. It is used to group threads for the same +* program. Note that the main thread pid (or thread group id tgid) cannot be +* used because it does not change when a new program is exec'ed. +*/ +int db_export__exec_comm (struct db_export *dbe,struct comm *comm, +struct thread *main_thread) {int err;
@@ -120,6 +126,16 @@ int db_export__comm(struct db_export *dbe, struct comm *comm,return err; } +/* +* Record the main thread for this comm. Note that the main thread can +* have many "exec" comms because there will be a new one every time it +* exec's. An "exec" comm however will only ever have 1 main thread. +* That is different to any other threads for that same program because +* exec() will effectively kill them, so the relationship between the +* "exec" comm and non-main threads is 1-to-1. That is why +* db_export__comm_thread() is called here for the main thread, but it +* is called for non-main threads when they are exported. +*/ return db_export__comm_thread (dbe, comm, main_thread); }
@@ -312,7 +328,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, goto out_put;if (comm) { - err =db_export__comm (dbe, comm, main_thread); + err =db_export__exec_comm (dbe, comm, main_thread);if (err) goto out_put; es.comm_db_id = comm->db_id;
tools/perf/util/db-export.h +2 -2
@@ -76,8 +76,8 @@ int db_export__evsel(struct db_export *dbe, struct perf_evsel *evsel);int db_export__machine (struct db_export *dbe,struct machine *machine);int db_export__thread (struct db_export *dbe,struct thread *thread,struct machine *machine,struct comm *comm); -int db_export__comm (struct db_export *dbe,struct comm *comm, -struct thread *main_thread); +int db_export__exec_comm (struct db_export *dbe,struct comm *comm, +struct thread *main_thread);int db_export__comm_thread (struct db_export *dbe,struct comm *comm,struct thread *thread); int db_export__dso(struct db_export *dbe, struct dso *dso,
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Rename db_export__comm() to db_export__exec_comm()
perf db-export: Rename db_export__comm() to db_export__exec_comm()
Commit-ID: 208032fef13b68cf1eefc945dafb82efc88c6b8f Gitweb: https://git.kernel.org/tip/208032fef13b68cf1eefc945dafb82efc88c6b8f Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:57:51 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:10:27 -0300
perf db-export: Rename db_export__comm() to db_export__exec_comm()
Rename db_export__comm() to db_export__exec_comm() to better reflect what it does and add explanatory comments.
--- tools/perf/util/db-export.c | 22 +++++++++++++++++++--- tools/perf/util/db-export.h | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-)
tools/perf/util/db-export.c +19 -3
@@ -105,8 +105,14 @@ out_put:return err; } -int db_export__comm (struct db_export *dbe,struct comm *comm, -struct thread *main_thread) +/* +* Export the "exec" comm. The "exec" comm is the program / application command +* name at the time it first executes. It is used to group threads for the same +* program. Note that the main thread pid (or thread group id tgid) cannot be +* used because it does not change when a new program is exec'ed. +*/ +int db_export__exec_comm (struct db_export *dbe,struct comm *comm, +struct thread *main_thread) {int err;
@@ -121,6 +127,16 @@ int db_export__comm(struct db_export *dbe, struct comm *comm,return err; } +/* +* Record the main thread for this comm. Note that the main thread can +* have many "exec" comms because there will be a new one every time it +* exec's. An "exec" comm however will only ever have 1 main thread. +* That is different to any other threads for that same program because +* exec() will effectively kill them, so the relationship between the +* "exec" comm and non-main threads is 1-to-1. That is why +* db_export__comm_thread() is called here for the main thread, but it +* is called for non-main threads when they are exported. +*/ return db_export__comm_thread (dbe, comm, main_thread); }
@@ -313,7 +329,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, goto out_put;if (comm) { - err =db_export__comm (dbe, comm, main_thread); + err =db_export__exec_comm (dbe, comm, main_thread);if (err) goto out_put; es.comm_db_id = comm->db_id;
tools/perf/util/db-export.h +2 -2
@@ -76,8 +76,8 @@ int db_export__evsel(struct db_export *dbe, struct perf_evsel *evsel);int db_export__machine (struct db_export *dbe,struct machine *machine);int db_export__thread (struct db_export *dbe,struct thread *thread,struct machine *machine,struct comm *comm); -int db_export__comm (struct db_export *dbe,struct comm *comm, -struct thread *main_thread); +int db_export__exec_comm (struct db_export *dbe,struct comm *comm, +struct thread *main_thread);int db_export__comm_thread (struct db_export *dbe,struct comm *comm,struct thread *thread); int db_export__dso(struct db_export *dbe, struct dso *dso,
Adrian Hunter
reviewerPATCH 3/21 perf db-export: Pass main_thread to db_export__thread()
In reply to Adrian HunterCalls to db_export__thread() already have main_thread so there is no reason to get it again, instead pass it as a parameter. Note that one difference in this approach is that the main thread is not created if it does not exist. It is better if it is not created because:
- If main_thread is being traced it will have been created already.
- If it is not being traced, there will be no other information about
it, and it will never get deleted because there will be no EXIT event.
--- tools/perf/util/db-export.c | 29 ++++++++--------------------- tools/perf/util/db-export.h | 3 ++- 2 files changed, 10 insertions(+), 22 deletions(-)
tools/perf/util/db-export.c +8 -21
@@ -58,9 +58,9 @@ int db_export__machine(struct db_export *dbe, struct machine *machine) }int db_export__thread (struct db_export *dbe,struct thread *thread, -struct machine *machine,struct comm *comm) +struct machine *machine,struct comm *comm, +struct thread *main_thread) { -struct thread *main_thread;u64 main_thread_db_id =0 ;int err;
@@ -69,28 +69,19 @@ int db_export__thread(struct db_export *dbe, struct thread *thread, thread->db_id = ++dbe->thread_last_db_id; -if (thread->pid_ !=-1 ) { -if (thread->pid_ == thread->tid) { - main_thread = thread; - }else { - main_thread =machine__findnew_thread (machine, - thread->pid_, - thread->pid_); -if (!main_thread) -return -ENOMEM ; +if (main_thread) { +if (main_thread != thread) { err =db_export__thread (dbe, main_thread, machine, - comm); + comm, main_thread);if (err) - goto out_put; +return err;if (comm) { err =db_export__comm_thread (dbe, comm, thread);if (err) - goto out_put; +return err; } } main_thread_db_id = main_thread->db_id; -if (main_thread != thread) -thread__put (main_thread); }if (dbe->export_thread)
@@ -98,10 +89,6 @@ int db_export__thread(struct db_export *dbe, struct thread *thread, machine);return 0 ; - -out_put: -thread__put (main_thread); -return err; }/*
@@ -323,7 +310,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,if (main_thread) comm =machine__thread_exec_comm (al->machine, main_thread); - err =db_export__thread (dbe, thread, al->machine, comm); + err =db_export__thread (dbe, thread, al->machine, comm, main_thread);if (err) goto out_put;
tools/perf/util/db-export.h +2 -1
@@ -75,7 +75,8 @@ void db_export__exit(struct db_export *dbe);int db_export__evsel (struct db_export *dbe,struct perf_evsel *evsel);int db_export__machine (struct db_export *dbe,struct machine *machine);int db_export__thread (struct db_export *dbe,struct thread *thread, -struct machine *machine,struct comm *comm); +struct machine *machine,struct comm *comm, +struct thread *main_thread);int db_export__exec_comm (struct db_export *dbe,struct comm *comm,struct thread *main_thread); int db_export__comm_thread(struct db_export *dbe, struct comm *comm,
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Pass main_thread to db_export__thread()
perf db-export: Pass main_thread to db_export__thread()
Commit-ID: ed5c0a16feb9f1a4347f109d5e9607f6f38688a0 Gitweb: https://git.kernel.org/tip/ed5c0a16feb9f1a4347f109d5e9607f6f38688a0 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:57:52 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:11:04 -0300
perf db-export: Pass main_thread to db_export__thread()
Calls to db_export__thread() already have main_thread so there is no reason to get it again, instead pass it as a parameter. Note that one difference in this approach is that the main thread is not created if it does not exist. It is better if it is not created because:
- If main_thread is being traced it will have been created already.
- If it is not being traced, there will be no other information about it, and it will never get deleted because there will be no EXIT event.
--- tools/perf/util/db-export.c | 29 ++++++++--------------------- tools/perf/util/db-export.h | 3 ++- 2 files changed, 10 insertions(+), 22 deletions(-)
tools/perf/util/db-export.c +8 -21
@@ -59,9 +59,9 @@ int db_export__machine(struct db_export *dbe, struct machine *machine) }int db_export__thread (struct db_export *dbe,struct thread *thread, -struct machine *machine,struct comm *comm) +struct machine *machine,struct comm *comm, +struct thread *main_thread) { -struct thread *main_thread;u64 main_thread_db_id =0 ;int err;
@@ -70,28 +70,19 @@ int db_export__thread(struct db_export *dbe, struct thread *thread, thread->db_id = ++dbe->thread_last_db_id; -if (thread->pid_ !=-1 ) { -if (thread->pid_ == thread->tid) { - main_thread = thread; - }else { - main_thread =machine__findnew_thread (machine, - thread->pid_, - thread->pid_); -if (!main_thread) -return -ENOMEM ; +if (main_thread) { +if (main_thread != thread) { err =db_export__thread (dbe, main_thread, machine, - comm); + comm, main_thread);if (err) - goto out_put; +return err;if (comm) { err =db_export__comm_thread (dbe, comm, thread);if (err) - goto out_put; +return err; } } main_thread_db_id = main_thread->db_id; -if (main_thread != thread) -thread__put (main_thread); }if (dbe->export_thread)
@@ -99,10 +90,6 @@ int db_export__thread(struct db_export *dbe, struct thread *thread, machine);return 0 ; - -out_put: -thread__put (main_thread); -return err; }/*
@@ -324,7 +311,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,if (main_thread) comm =machine__thread_exec_comm (al->machine, main_thread); - err =db_export__thread (dbe, thread, al->machine, comm); + err =db_export__thread (dbe, thread, al->machine, comm, main_thread);if (err) goto out_put;
tools/perf/util/db-export.h +2 -1
@@ -75,7 +75,8 @@ void db_export__exit(struct db_export *dbe);int db_export__evsel (struct db_export *dbe,struct perf_evsel *evsel);int db_export__machine (struct db_export *dbe,struct machine *machine);int db_export__thread (struct db_export *dbe,struct thread *thread, -struct machine *machine,struct comm *comm); +struct machine *machine,struct comm *comm, +struct thread *main_thread);int db_export__exec_comm (struct db_export *dbe,struct comm *comm,struct thread *main_thread); int db_export__comm_thread(struct db_export *dbe, struct comm *comm,
Adrian Hunter
reviewerPATCH 4/21 perf db-export: Export main_thread in db_export__sample()
In reply to Adrian HunterExport main_thread in db_export__sample() because it makes the code easier to understand, and prepares db_export__thread() for further simplification.
--- tools/perf/util/db-export.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
tools/perf/util/db-export.c +18 -12
@@ -70,16 +70,10 @@ int db_export__thread(struct db_export *dbe, struct thread *thread, thread->db_id = ++dbe->thread_last_db_id;if (main_thread) { -if (main_thread != thread) { - err =db_export__thread (dbe, main_thread, machine, - comm, main_thread); +if (main_thread != thread && comm) { + err =db_export__comm_thread (dbe, comm, thread);if (err)return err; -if (comm) { - err =db_export__comm_thread (dbe, comm, thread); -if (err) -return err; - } } main_thread_db_id = main_thread->db_id; }
@@ -307,12 +301,24 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,return err; main_thread =thread__main_thread (al->machine, thread); -if (main_thread) +if (main_thread) { comm =machine__thread_exec_comm (al->machine, main_thread); +/* +* A thread has a reference to the main thread, so export the +* main thread first. +*/ + err =db_export__thread (dbe, main_thread, al->machine, comm, + main_thread); +if (err) + goto out_put; + } - err =db_export__thread (dbe, thread, al->machine, comm, main_thread); -if (err) - goto out_put; +if (thread != main_thread) { + err =db_export__thread (dbe, thread, al->machine, comm, + main_thread); +if (err) + goto out_put; + }if (comm) { err =db_export__exec_comm (dbe, comm, main_thread);
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Export main_thread in db_export__sample()
perf db-export: Export main_thread in db_export__sample()
Commit-ID: 19207d86940db9dad5f2e0a270a2490f7da451e3 Gitweb: https://git.kernel.org/tip/19207d86940db9dad5f2e0a270a2490f7da451e3 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:57:53 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:12:05 -0300
perf db-export: Export main_thread in db_export__sample()
Export main_thread in db_export__sample() because it makes the code easier to understand, and prepares db_export__thread() for further simplification.
--- tools/perf/util/db-export.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
tools/perf/util/db-export.c +18 -12
@@ -71,16 +71,10 @@ int db_export__thread(struct db_export *dbe, struct thread *thread, thread->db_id = ++dbe->thread_last_db_id;if (main_thread) { -if (main_thread != thread) { - err =db_export__thread (dbe, main_thread, machine, - comm, main_thread); +if (main_thread != thread && comm) { + err =db_export__comm_thread (dbe, comm, thread);if (err)return err; -if (comm) { - err =db_export__comm_thread (dbe, comm, thread); -if (err) -return err; - } } main_thread_db_id = main_thread->db_id; }
@@ -308,12 +302,24 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,return err; main_thread =thread__main_thread (al->machine, thread); -if (main_thread) +if (main_thread) { comm =machine__thread_exec_comm (al->machine, main_thread); +/* +* A thread has a reference to the main thread, so export the +* main thread first. +*/ + err =db_export__thread (dbe, main_thread, al->machine, comm, + main_thread); +if (err) + goto out_put; + } - err =db_export__thread (dbe, thread, al->machine, comm, main_thread); -if (err) - goto out_put; +if (thread != main_thread) { + err =db_export__thread (dbe, thread, al->machine, comm, + main_thread); +if (err) + goto out_put; + }if (comm) { err =db_export__exec_comm (dbe, comm, main_thread);
Adrian Hunter
reviewerPATCH 5/21 perf db-export: Export comm before exporting thread
In reply to Adrian HunterExport comm before exporting the non-main thread because db_export__thread() also exports the comm_thread.
--- tools/perf/util/db-export.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
tools/perf/util/db-export.c +6 -7
@@ -311,6 +311,12 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, main_thread);if (err) goto out_put; +if (comm) { + err =db_export__exec_comm (dbe, comm, main_thread); +if (err) + goto out_put; + es.comm_db_id = comm->db_id; + } }if (thread != main_thread) {
@@ -320,13 +326,6 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, goto out_put; } -if (comm) { - err =db_export__exec_comm (dbe, comm, main_thread); -if (err) - goto out_put; - es.comm_db_id = comm->db_id; - } - es.db_id = ++dbe->sample_last_db_id; err =db_ids_from_al (dbe, al, &es.dso_db_id, &es.sym_db_id, &es.offset);
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Export comm before exporting thread
perf db-export: Export comm before exporting thread
Commit-ID: 6319790bcf825bcc4cd9bf01f01ae404a2fb7da8 Gitweb: https://git.kernel.org/tip/6319790bcf825bcc4cd9bf01f01ae404a2fb7da8 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:57:54 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:12:25 -0300
perf db-export: Export comm before exporting thread
Export comm before exporting the non-main thread because db_export__thread() also exports the comm_thread.
--- tools/perf/util/db-export.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
tools/perf/util/db-export.c +6 -7
@@ -312,6 +312,12 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, main_thread);if (err) goto out_put; +if (comm) { + err =db_export__exec_comm (dbe, comm, main_thread); +if (err) + goto out_put; + es.comm_db_id = comm->db_id; + } }if (thread != main_thread) {
@@ -321,13 +327,6 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, goto out_put; } -if (comm) { - err =db_export__exec_comm (dbe, comm, main_thread); -if (err) - goto out_put; - es.comm_db_id = comm->db_id; - } - es.db_id = ++dbe->sample_last_db_id; err =db_ids_from_al (dbe, al, &es.dso_db_id, &es.sym_db_id, &es.offset);
Adrian Hunter
reviewerPATCH 6/21 perf db-export: Move export__comm_thread into db_export__sample()
In reply to Adrian HunterMove call to db_export__comm_thread() from db_export__thread() into db_export__sample() because it makes the code easier to understand, and add explanatory comments.
--- tools/perf/util/db-export.c | 35 +++++++++++++++++++++-------------- tools/perf/util/db-export.h | 3 +-- 2 files changed, 22 insertions(+), 16 deletions(-)
tools/perf/util/db-export.c +21 -14
@@ -58,25 +58,17 @@ int db_export__machine(struct db_export *dbe, struct machine *machine) }int db_export__thread (struct db_export *dbe,struct thread *thread, -struct machine *machine,struct comm *comm, -struct thread *main_thread) +struct machine *machine,struct thread *main_thread) {u64 main_thread_db_id =0 ; -int err;if (thread->db_id)return 0 ; thread->db_id = ++dbe->thread_last_db_id; -if (main_thread) { -if (main_thread != thread && comm) { - err =db_export__comm_thread (dbe, comm, thread); -if (err) -return err; - } +if (main_thread) main_thread_db_id = main_thread->db_id; - }if (dbe->export_thread) return dbe->export_thread(dbe, thread, main_thread_db_id,
@@ -302,15 +294,19 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, main_thread =thread__main_thread (al->machine, thread);if (main_thread) { - comm =machine__thread_exec_comm (al->machine, main_thread);/* * A thread has a reference to the main thread, so export the * main thread first. */ - err =db_export__thread (dbe, main_thread, al->machine, comm, + err =db_export__thread (dbe, main_thread, al->machine, main_thread);if (err) goto out_put; +/* +* Export comm before exporting the non-main thread because +* db_export__comm_thread() can be called further below. +*/ + comm =machine__thread_exec_comm (al->machine, main_thread);if (comm) { err =db_export__exec_comm (dbe, comm, main_thread);if (err)
@@ -320,10 +316,21 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, }if (thread != main_thread) { - err =db_export__thread (dbe, thread, al->machine, comm, - main_thread); +/* +* For a non-main thread, db_export__comm_thread() must be +* called only if thread has not previously been exported. +*/ +bool export_comm_thread = comm && !thread->db_id; + + err =db_export__thread (dbe, thread, al->machine, main_thread);if (err) goto out_put; + +if (export_comm_thread) { + err =db_export__comm_thread (dbe, comm, thread); +if (err) + goto out_put; + } } es.db_id = ++dbe->sample_last_db_id;
tools/perf/util/db-export.h +1 -2
@@ -75,8 +75,7 @@ void db_export__exit(struct db_export *dbe);int db_export__evsel (struct db_export *dbe,struct perf_evsel *evsel);int db_export__machine (struct db_export *dbe,struct machine *machine);int db_export__thread (struct db_export *dbe,struct thread *thread, -struct machine *machine,struct comm *comm, -struct thread *main_thread); +struct machine *machine,struct thread *main_thread);int db_export__exec_comm (struct db_export *dbe,struct comm *comm,struct thread *main_thread); int db_export__comm_thread(struct db_export *dbe, struct comm *comm,
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Move export__comm_thread into db_export__sample()
perf db-export: Move export__comm_thread into db_export__sample()
Commit-ID: 1ed119589834e25c130fdaa911ca8b0e3fd1cddf Gitweb: https://git.kernel.org/tip/1ed119589834e25c130fdaa911ca8b0e3fd1cddf Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:57:55 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:12:45 -0300
perf db-export: Move export__comm_thread into db_export__sample()
Move call to db_export__comm_thread() from db_export__thread() into db_export__sample() because it makes the code easier to understand, and add explanatory comments.
--- tools/perf/util/db-export.c | 35 +++++++++++++++++++++-------------- tools/perf/util/db-export.h | 3 +-- 2 files changed, 22 insertions(+), 16 deletions(-)
tools/perf/util/db-export.c +21 -14
@@ -59,25 +59,17 @@ int db_export__machine(struct db_export *dbe, struct machine *machine) }int db_export__thread (struct db_export *dbe,struct thread *thread, -struct machine *machine,struct comm *comm, -struct thread *main_thread) +struct machine *machine,struct thread *main_thread) {u64 main_thread_db_id =0 ; -int err;if (thread->db_id)return 0 ; thread->db_id = ++dbe->thread_last_db_id; -if (main_thread) { -if (main_thread != thread && comm) { - err =db_export__comm_thread (dbe, comm, thread); -if (err) -return err; - } +if (main_thread) main_thread_db_id = main_thread->db_id; - }if (dbe->export_thread) return dbe->export_thread(dbe, thread, main_thread_db_id,
@@ -303,15 +295,19 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, main_thread =thread__main_thread (al->machine, thread);if (main_thread) { - comm =machine__thread_exec_comm (al->machine, main_thread);/* * A thread has a reference to the main thread, so export the * main thread first. */ - err =db_export__thread (dbe, main_thread, al->machine, comm, + err =db_export__thread (dbe, main_thread, al->machine, main_thread);if (err) goto out_put; +/* +* Export comm before exporting the non-main thread because +* db_export__comm_thread() can be called further below. +*/ + comm =machine__thread_exec_comm (al->machine, main_thread);if (comm) { err =db_export__exec_comm (dbe, comm, main_thread);if (err)
@@ -321,10 +317,21 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, }if (thread != main_thread) { - err =db_export__thread (dbe, thread, al->machine, comm, - main_thread); +/* +* For a non-main thread, db_export__comm_thread() must be +* called only if thread has not previously been exported. +*/ +bool export_comm_thread = comm && !thread->db_id; + + err =db_export__thread (dbe, thread, al->machine, main_thread);if (err) goto out_put; + +if (export_comm_thread) { + err =db_export__comm_thread (dbe, comm, thread); +if (err) + goto out_put; + } } es.db_id = ++dbe->sample_last_db_id;
tools/perf/util/db-export.h +1 -2
@@ -75,8 +75,7 @@ void db_export__exit(struct db_export *dbe);int db_export__evsel (struct db_export *dbe,struct perf_evsel *evsel);int db_export__machine (struct db_export *dbe,struct machine *machine);int db_export__thread (struct db_export *dbe,struct thread *thread, -struct machine *machine,struct comm *comm, -struct thread *main_thread); +struct machine *machine,struct thread *main_thread);int db_export__exec_comm (struct db_export *dbe,struct comm *comm,struct thread *main_thread); int db_export__comm_thread(struct db_export *dbe, struct comm *comm,
Adrian Hunter
reviewerPATCH 7/21 perf db-export: Fix a white space issue in db_export__sample()
In reply to Adrian HunterFix a white space issue in db_export__sample()
--- tools/perf/util/db-export.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/db-export.c +1 -1
@@ -273,7 +273,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al) { - struct thread* thread = al->thread; + struct thread *thread = al->thread; struct export_sample es = { .event = event, .sample = sample,
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Fix a white space issue in db_export__sample()
perf db-export: Fix a white space issue in db_export__sample()
Commit-ID: a5defb2f3984e0f056e4113b54c461782796c7be Gitweb: https://git.kernel.org/tip/a5defb2f3984e0f056e4113b54c461782796c7be Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:57:56 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:12:56 -0300
perf db-export: Fix a white space issue in db_export__sample()
Fix a white space issue in db_export__sample()
--- tools/perf/util/db-export.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/db-export.c +1 -1
@@ -274,7 +274,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al) { - struct thread* thread = al->thread; + struct thread *thread = al->thread; struct export_sample es = { .event = event, .sample = sample,
Adrian Hunter
reviewerPATCH 8/21 perf db-export: Export comm details
In reply to Adrian HunterIn preparation for exporting the current comm for a thread, export comm thread id, start time and exec flag.
--- tools/perf/util/db-export.c | 2 +- tools/perf/util/db-export.h | 3 ++- tools/perf/util/scripting-engines/trace-event-python.c | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-)
tools/perf/util/db-export.c +1 -1
@@ -94,7 +94,7 @@ int db_export__exec_comm(struct db_export *dbe, struct comm *comm, comm->db_id = ++dbe->comm_last_db_id;if (dbe->export_comm) { - err = dbe->export_comm (dbe, comm); + err = dbe->export_comm (dbe, comm, main_thread);if (err)return err; }
tools/perf/util/db-export.h +2 -1
@@ -43,7 +43,8 @@ struct db_export {int (*export_machine)(struct db_export *dbe,struct machine *machine);int (*export_thread)(struct db_export *dbe,struct thread *thread,u64 main_thread_db_id,struct machine *machine); -int (*export_comm)(struct db_export *dbe,struct comm *comm); +int (*export_comm)(struct db_export *dbe,struct comm *comm, +struct thread *thread);int (*export_comm_thread)(struct db_export *dbe,u64 db_id,struct comm *comm,struct thread *thread); int (*export_dso)(struct db_export *dbe, struct dso *dso,
tools/perf/util/scripting-engines/trace-event-python.c +6 -2
@@ -1011,15 +1011,19 @@ static int python_export_thread(struct db_export *dbe, struct thread *thread,return 0 ; } -static int python_export_comm (struct db_export *dbe,struct comm *comm) +static int python_export_comm (struct db_export *dbe,struct comm *comm, +struct thread *thread) { struct tables *tables = container_of(dbe, struct tables, dbe);PyObject *t; - t =tuple_new (2 ); + t =tuple_new (5 );tuple_set_u64 (t,0 , comm->db_id);tuple_set_string (t,1 ,comm__str (comm)); +tuple_set_u64 (t,2 , thread->db_id); +tuple_set_u64 (t,3 , comm->start); +tuple_set_s32 (t,4 , comm->exec);call_object (tables->comm_handler, t,"comm_table" );
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Export comm details
perf db-export: Export comm details
Commit-ID: 8ebf5cc0f6ce469d65ba2e8ce519dae34f0b3f50 Gitweb: https://git.kernel.org/tip/8ebf5cc0f6ce469d65ba2e8ce519dae34f0b3f50 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:57:57 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:13:08 -0300
perf db-export: Export comm details
In preparation for exporting the current comm for a thread, export comm thread id, start time and exec flag.
--- tools/perf/util/db-export.c | 2 +- tools/perf/util/db-export.h | 3 ++- tools/perf/util/scripting-engines/trace-event-python.c | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-)
tools/perf/util/db-export.c +1 -1
@@ -95,7 +95,7 @@ int db_export__exec_comm(struct db_export *dbe, struct comm *comm, comm->db_id = ++dbe->comm_last_db_id;if (dbe->export_comm) { - err = dbe->export_comm (dbe, comm); + err = dbe->export_comm (dbe, comm, main_thread);if (err)return err; }
tools/perf/util/db-export.h +2 -1
@@ -43,7 +43,8 @@ struct db_export {int (*export_machine)(struct db_export *dbe,struct machine *machine);int (*export_thread)(struct db_export *dbe,struct thread *thread,u64 main_thread_db_id,struct machine *machine); -int (*export_comm)(struct db_export *dbe,struct comm *comm); +int (*export_comm)(struct db_export *dbe,struct comm *comm, +struct thread *thread);int (*export_comm_thread)(struct db_export *dbe,u64 db_id,struct comm *comm,struct thread *thread); int (*export_dso)(struct db_export *dbe, struct dso *dso,
tools/perf/util/scripting-engines/trace-event-python.c +6 -2
@@ -1011,15 +1011,19 @@ static int python_export_thread(struct db_export *dbe, struct thread *thread,return 0 ; } -static int python_export_comm (struct db_export *dbe,struct comm *comm) +static int python_export_comm (struct db_export *dbe,struct comm *comm, +struct thread *thread) { struct tables *tables = container_of(dbe, struct tables, dbe);PyObject *t; - t =tuple_new (2 ); + t =tuple_new (5 );tuple_set_u64 (t,0 , comm->db_id);tuple_set_string (t,1 ,comm__str (comm)); +tuple_set_u64 (t,2 , thread->db_id); +tuple_set_u64 (t,3 , comm->start); +tuple_set_s32 (t,4 , comm->exec);call_object (tables->comm_handler, t,"comm_table" );
Adrian Hunter
reviewerPATCH 9/21 perf scripts python: export-to-sqlite.py: Export comm details
In reply to Adrian HunterAdd table columns for thread id, comm start time and exec flag.
--- tools/perf/scripts/python/export-to-sqlite.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
tools/perf/scripts/python/export-to-sqlite.py +7 -4
@@ -177,7 +177,10 @@ do_query(query, 'CREATE TABLE threads (' 'tid integer)') do_query(query, 'CREATE TABLE comms (' 'id integer NOT NULL PRIMARY KEY,' - 'comm varchar(16))') + 'comm varchar(16),' + 'c_thread_id bigint,' + 'c_time bigint,' + 'exec_flag boolean)') do_query(query, 'CREATE TABLE comm_threads (' 'id integer NOT NULL PRIMARY KEY,' 'comm_id bigint,'
@@ -536,7 +539,7 @@ machine_query.prepare("INSERT INTO machines VALUES (?, ?, ?)") thread_query = QSqlQuery(db) thread_query.prepare("INSERT INTO threads VALUES (?, ?, ?, ?, ?)") comm_query = QSqlQuery(db) -comm_query.prepare("INSERT INTO comms VALUES (?, ?)") +comm_query.prepare("INSERT INTO comms VALUES (?, ?, ?, ?, ?)") comm_thread_query = QSqlQuery(db) comm_thread_query.prepare("INSERT INTO comm_threads VALUES (?, ?, ?)") dso_query = QSqlQuery(db)
@@ -576,7 +579,7 @@ def trace_begin(): evsel_table(0, "unknown") machine_table(0, 0, "unknown") thread_table(0, 0, 0, -1, -1) - comm_table(0, "unknown") + comm_table(0, "unknown", 0, 0, 0) dso_table(0, 0, "unknown", "unknown", "") symbol_table(0, 0, 0, 0, 0, "unknown") sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
@@ -642,7 +645,7 @@ def thread_table(*x): bind_exec(thread_query, 5, x) def comm_table(*x): - bind_exec(comm_query, 2, x) + bind_exec(comm_query, 5, x) def comm_thread_table(*x): bind_exec(comm_thread_query, 3, x)
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf scripts python: export-to-sqlite.py: Export comm details
perf scripts python: export-to-sqlite.py: Export comm details
Commit-ID: 41085f2bdd5882632e7dd88d1e5b59b7eac2a2a9 Gitweb: https://git.kernel.org/tip/41085f2bdd5882632e7dd88d1e5b59b7eac2a2a9 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:57:58 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:13:26 -0300
perf scripts python: export-to-sqlite.py: Export comm details
Add table columns for thread id, comm start time and exec flag.
--- tools/perf/scripts/python/export-to-sqlite.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
tools/perf/scripts/python/export-to-sqlite.py +7 -4
@@ -177,7 +177,10 @@ do_query(query, 'CREATE TABLE threads (' 'tid integer)') do_query(query, 'CREATE TABLE comms (' 'id integer NOT NULL PRIMARY KEY,' - 'comm varchar(16))') + 'comm varchar(16),' + 'c_thread_id bigint,' + 'c_time bigint,' + 'exec_flag boolean)') do_query(query, 'CREATE TABLE comm_threads (' 'id integer NOT NULL PRIMARY KEY,' 'comm_id bigint,'
@@ -536,7 +539,7 @@ machine_query.prepare("INSERT INTO machines VALUES (?, ?, ?)") thread_query = QSqlQuery(db) thread_query.prepare("INSERT INTO threads VALUES (?, ?, ?, ?, ?)") comm_query = QSqlQuery(db) -comm_query.prepare("INSERT INTO comms VALUES (?, ?)") +comm_query.prepare("INSERT INTO comms VALUES (?, ?, ?, ?, ?)") comm_thread_query = QSqlQuery(db) comm_thread_query.prepare("INSERT INTO comm_threads VALUES (?, ?, ?)") dso_query = QSqlQuery(db)
@@ -576,7 +579,7 @@ def trace_begin(): evsel_table(0, "unknown") machine_table(0, 0, "unknown") thread_table(0, 0, 0, -1, -1) - comm_table(0, "unknown") + comm_table(0, "unknown", 0, 0, 0) dso_table(0, 0, "unknown", "unknown", "") symbol_table(0, 0, 0, 0, 0, "unknown") sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
@@ -642,7 +645,7 @@ def thread_table(*x): bind_exec(thread_query, 5, x) def comm_table(*x): - bind_exec(comm_query, 2, x) + bind_exec(comm_query, 5, x) def comm_thread_table(*x): bind_exec(comm_thread_query, 3, x)
Adrian Hunter
reviewerPATCH 10/21 perf scripts python: export-to-postgresql.py: Export comm details
In reply to Adrian HunterAdd table columns for thread id, comm start time and exec flag.
--- tools/perf/scripts/python/export-to-postgresql.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
tools/perf/scripts/python/export-to-postgresql.py +10 -5
@@ -353,7 +353,10 @@ do_query(query, 'CREATE TABLE threads (' 'tid integer)') do_query(query, 'CREATE TABLE comms (' 'id bigint NOT NULL,' - 'comm varchar(16))') + 'comm varchar(16),' + 'c_thread_id bigint,' + 'c_time bigint,' + 'exec_flag boolean)') do_query(query, 'CREATE TABLE comm_threads (' 'id bigint NOT NULL,' 'comm_id bigint,'
@@ -763,7 +766,7 @@ def trace_begin(): evsel_table(0, "unknown") machine_table(0, 0, "unknown") thread_table(0, 0, 0, -1, -1) - comm_table(0, "unknown") + comm_table(0, "unknown", 0, 0, 0) dso_table(0, 0, "unknown", "unknown", "") symbol_table(0, 0, 0, 0, 0, "unknown") sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
@@ -851,6 +854,8 @@ def trace_end(): do_query(query, 'ALTER TABLE threads ' 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads (id)') + do_query(query, 'ALTER TABLE comms ' + 'ADD CONSTRAINT threadfk FOREIGN KEY (c_thread_id) REFERENCES threads (id)') do_query(query, 'ALTER TABLE comm_threads ' 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),' 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id)')
@@ -935,11 +940,11 @@ def thread_table(thread_id, machine_id, process_id, pid, tid, *x): value = struct.pack("!hiqiqiqiiii", 5, 8, thread_id, 8, machine_id, 8, process_id, 4, pid, 4, tid) thread_file.write(value) -def comm_table(comm_id, comm_str, *x): +def comm_table(comm_id, comm_str, thread_id, time, exec_flag, *x): comm_str = toserverstr(comm_str) n = len(comm_str) - fmt = "!hiqi" + str(n) + "s" - value = struct.pack(fmt, 2, 8, comm_id, n, comm_str) + fmt = "!hiqi" + str(n) + "s" + "iqiqiB" + value = struct.pack(fmt, 5, 8, comm_id, n, comm_str, 8, thread_id, 8, time, 1, exec_flag) comm_file.write(value) def comm_thread_table(comm_thread_id, comm_id, thread_id, *x):
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf scripts python: export-to-postgresql.py: Export comm details
perf scripts python: export-to-postgresql.py: Export comm details
Commit-ID: 8534b5de81802a82b13fe05acc3e749e3baf980e Gitweb: https://git.kernel.org/tip/8534b5de81802a82b13fe05acc3e749e3baf980e Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:57:59 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:13:36 -0300
perf scripts python: export-to-postgresql.py: Export comm details
Add table columns for thread id, comm start time and exec flag.
--- tools/perf/scripts/python/export-to-postgresql.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
tools/perf/scripts/python/export-to-postgresql.py +10 -5
@@ -353,7 +353,10 @@ do_query(query, 'CREATE TABLE threads (' 'tid integer)') do_query(query, 'CREATE TABLE comms (' 'id bigint NOT NULL,' - 'comm varchar(16))') + 'comm varchar(16),' + 'c_thread_id bigint,' + 'c_time bigint,' + 'exec_flag boolean)') do_query(query, 'CREATE TABLE comm_threads (' 'id bigint NOT NULL,' 'comm_id bigint,'
@@ -763,7 +766,7 @@ def trace_begin(): evsel_table(0, "unknown") machine_table(0, 0, "unknown") thread_table(0, 0, 0, -1, -1) - comm_table(0, "unknown") + comm_table(0, "unknown", 0, 0, 0) dso_table(0, 0, "unknown", "unknown", "") symbol_table(0, 0, 0, 0, 0, "unknown") sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
@@ -851,6 +854,8 @@ def trace_end(): do_query(query, 'ALTER TABLE threads ' 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads (id)') + do_query(query, 'ALTER TABLE comms ' + 'ADD CONSTRAINT threadfk FOREIGN KEY (c_thread_id) REFERENCES threads (id)') do_query(query, 'ALTER TABLE comm_threads ' 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),' 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id)')
@@ -935,11 +940,11 @@ def thread_table(thread_id, machine_id, process_id, pid, tid, *x): value = struct.pack("!hiqiqiqiiii", 5, 8, thread_id, 8, machine_id, 8, process_id, 4, pid, 4, tid) thread_file.write(value) -def comm_table(comm_id, comm_str, *x): +def comm_table(comm_id, comm_str, thread_id, time, exec_flag, *x): comm_str = toserverstr(comm_str) n = len(comm_str) - fmt = "!hiqi" + str(n) + "s" - value = struct.pack(fmt, 2, 8, comm_id, n, comm_str) + fmt = "!hiqi" + str(n) + "s" + "iqiqiB" + value = struct.pack(fmt, 5, 8, comm_id, n, comm_str, 8, thread_id, 8, time, 1, exec_flag) comm_file.write(value) def comm_thread_table(comm_thread_id, comm_id, thread_id, *x):
Adrian Hunter
reviewerPATCH 11/21 perf db-export: Factor out db_export__comm()
In reply to Adrian HunterIn preparation for exporting the current comm for a thread, factor out db_export__comm().
--- tools/perf/util/db-export.c | 30 +++++++++++++++++++++++------- tools/perf/util/db-export.h | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-)
tools/perf/util/db-export.c +23 -7
@@ -77,6 +77,26 @@ int db_export__thread(struct db_export *dbe, struct thread *thread,return 0 ; } +static int __db_export__comm (struct db_export *dbe,struct comm *comm, +struct thread *thread) +{ + comm->db_id = ++dbe->comm_last_db_id; + +if (dbe->export_comm) +return dbe->export_comm (dbe, comm, thread); + +return 0 ; +} + +int db_export__comm (struct db_export *dbe,struct comm *comm, +struct thread *thread) +{ +if (comm->db_id) +return 0 ; + +return __db_export__comm (dbe, comm, thread); +} +/* * Export the "exec" comm. The "exec" comm is the program / application command * name at the time it first executes. It is used to group threads for the same
@@ -91,13 +111,9 @@ int db_export__exec_comm(struct db_export *dbe, struct comm *comm,if (comm->db_id)return 0 ; - comm->db_id = ++dbe->comm_last_db_id; - -if (dbe->export_comm) { - err = dbe->export_comm (dbe, comm, main_thread); -if (err) -return err; - } + err =__db_export__comm (dbe, comm, main_thread); +if (err) +return err;/* * Record the main thread for this comm. Note that the main thread can
tools/perf/util/db-export.h +2 -0
@@ -77,6 +77,8 @@ int db_export__evsel(struct db_export *dbe, struct perf_evsel *evsel);int db_export__machine (struct db_export *dbe,struct machine *machine);int db_export__thread (struct db_export *dbe,struct thread *thread,struct machine *machine,struct thread *main_thread); +int db_export__comm (struct db_export *dbe,struct comm *comm, +struct thread *thread);int db_export__exec_comm (struct db_export *dbe,struct comm *comm,struct thread *main_thread); int db_export__comm_thread(struct db_export *dbe, struct comm *comm,
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Factor out db_export__comm()
perf db-export: Factor out db_export__comm()
Commit-ID: 80859c947a1eb170927d03e713abf7550a3d8766 Gitweb: https://git.kernel.org/tip/80859c947a1eb170927d03e713abf7550a3d8766 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:00 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:13:51 -0300
perf db-export: Factor out db_export__comm()
In preparation for exporting the current comm for a thread, factor out db_export__comm().
--- tools/perf/util/db-export.c | 30 +++++++++++++++++++++++------- tools/perf/util/db-export.h | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-)
tools/perf/util/db-export.c +23 -7
@@ -78,6 +78,26 @@ int db_export__thread(struct db_export *dbe, struct thread *thread,return 0 ; } +static int __db_export__comm (struct db_export *dbe,struct comm *comm, +struct thread *thread) +{ + comm->db_id = ++dbe->comm_last_db_id; + +if (dbe->export_comm) +return dbe->export_comm (dbe, comm, thread); + +return 0 ; +} + +int db_export__comm (struct db_export *dbe,struct comm *comm, +struct thread *thread) +{ +if (comm->db_id) +return 0 ; + +return __db_export__comm (dbe, comm, thread); +} +/* * Export the "exec" comm. The "exec" comm is the program / application command * name at the time it first executes. It is used to group threads for the same
@@ -92,13 +112,9 @@ int db_export__exec_comm(struct db_export *dbe, struct comm *comm,if (comm->db_id)return 0 ; - comm->db_id = ++dbe->comm_last_db_id; - -if (dbe->export_comm) { - err = dbe->export_comm (dbe, comm, main_thread); -if (err) -return err; - } + err =__db_export__comm (dbe, comm, main_thread); +if (err) +return err;/* * Record the main thread for this comm. Note that the main thread can
tools/perf/util/db-export.h +2 -0
@@ -77,6 +77,8 @@ int db_export__evsel(struct db_export *dbe, struct perf_evsel *evsel);int db_export__machine (struct db_export *dbe,struct machine *machine);int db_export__thread (struct db_export *dbe,struct thread *thread,struct machine *machine,struct thread *main_thread); +int db_export__comm (struct db_export *dbe,struct comm *comm, +struct thread *thread);int db_export__exec_comm (struct db_export *dbe,struct comm *comm,struct thread *main_thread); int db_export__comm_thread(struct db_export *dbe, struct comm *comm,
Adrian Hunter
reviewerPATCH 12/21 perf db-export: Also export thread's current comm
In reply to Adrian HunterCurrently, the initial comm of the main thread is exported. Export also a thread's current comm. That better supports the tracing of multi-threaded applications that set different comms for different threads to make it easier to distinguish them.
--- tools/perf/util/db-export.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/util/db-export.c +8 -0
@@ -298,6 +298,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, };struct thread *main_thread;struct comm *comm =NULL ; +struct comm *curr_comm;int err; err =db_export__evsel (dbe, evsel);
@@ -349,6 +350,13 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, } } + curr_comm =thread__comm (thread); +if (curr_comm) { + err =db_export__comm (dbe, curr_comm, thread); +if (err) + goto out_put; + } + es.db_id = ++dbe->sample_last_db_id; err =db_ids_from_al (dbe, al, &es.dso_db_id, &es.sym_db_id, &es.offset);
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Also export thread's current comm
perf db-export: Also export thread's current comm
Commit-ID: 4650c7bed79582c74452d284e45d5b76987c0ef3 Gitweb: https://git.kernel.org/tip/4650c7bed79582c74452d284e45d5b76987c0ef3 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:01 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:14:07 -0300
perf db-export: Also export thread's current comm
Currently, the initial comm of the main thread is exported. Export also a thread's current comm. That better supports the tracing of multi-threaded applications that set different comms for different threads to make it easier to distinguish them.
--- tools/perf/util/db-export.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/util/db-export.c +8 -0
@@ -299,6 +299,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, };struct thread *main_thread;struct comm *comm =NULL ; +struct comm *curr_comm;int err; err =db_export__evsel (dbe, evsel);
@@ -350,6 +351,13 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, } } + curr_comm =thread__comm (thread); +if (curr_comm) { + err =db_export__comm (dbe, curr_comm, thread); +if (err) + goto out_put; + } + es.db_id = ++dbe->sample_last_db_id; err =db_ids_from_al (dbe, al, &es.dso_db_id, &es.sym_db_id, &es.offset);
Adrian Hunter
reviewerPATCH 13/21 perf scripts python: export-to-sqlite.py: Add has_calls column to comms table
In reply to Adrian HunterNow that a thread's current comm is exported, it shows up in the call graph and call tree even if it has no calls. That can happen because the calls are recorded against the main thread's initial comm.
Add a table column to make it easy for the exported-sql-viewer.py script to select only comms with calls.
--- tools/perf/scripts/python/export-to-sqlite.py | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/scripts/python/export-to-sqlite.py +2 -0
@@ -606,6 +606,8 @@ def trace_end(): if perf_db_export_calls: do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') + do_query(query, 'ALTER TABLE comms ADD has_calls boolean') + do_query(query, 'UPDATE comms SET has_calls = 1 WHERE comms.id IN (SELECT DISTINCT comm_id FROM calls)') printdate("Dropping unused tables") if is_table_empty("ptwrite"):
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf scripts python: export-to-sqlite.py: Add has_calls column to comms table
perf scripts python: export-to-sqlite.py: Add has_calls column to comms table
Commit-ID: ecc8c9984dae9812a10936cb9c74957b68075e07 Gitweb: https://git.kernel.org/tip/ecc8c9984dae9812a10936cb9c74957b68075e07 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:02 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:23:55 -0300
perf scripts python: export-to-sqlite.py: Add has_calls column to comms table
Now that a thread's current comm is exported, it shows up in the call graph and call tree even if it has no calls. That can happen because the calls are recorded against the main thread's initial comm.
Add a table column to make it easy for the exported-sql-viewer.py script to select only comms with calls.
Committer notes:
Running the export-to-sqlite.py worked without warnings and using the exported-sql-viewer.py worked as before.
--- tools/perf/scripts/python/export-to-sqlite.py | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/scripts/python/export-to-sqlite.py +2 -0
@@ -606,6 +606,8 @@ def trace_end(): if perf_db_export_calls: do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') + do_query(query, 'ALTER TABLE comms ADD has_calls boolean') + do_query(query, 'UPDATE comms SET has_calls = 1 WHERE comms.id IN (SELECT DISTINCT comm_id FROM calls)') printdate("Dropping unused tables") if is_table_empty("ptwrite"):
Adrian Hunter
reviewerPATCH 14/21 perf scripts python: export-to-postgresql.py: Add has_calls column to comms table
In reply to Adrian HunterNow that a thread's current comm is exported, it shows up in the call graph and call tree even if it has no calls. That can happen because the calls are recorded against the main thread's initial comm.
Add a table column to make it easy for the exported-sql-viewer.py script to select only comms with calls.
--- tools/perf/scripts/python/export-to-postgresql.py | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/scripts/python/export-to-postgresql.py +2 -0
@@ -886,6 +886,8 @@ def trace_end(): 'ADD CONSTRAINT parent_call_pathfk FOREIGN KEY (parent_call_path_id) REFERENCES call_paths (id)') do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') + do_query(query, 'ALTER TABLE comms ADD has_calls boolean') + do_query(query, 'UPDATE comms SET has_calls = TRUE WHERE comms.id IN (SELECT DISTINCT comm_id FROM calls)') do_query(query, 'ALTER TABLE ptwrite ' 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') do_query(query, 'ALTER TABLE cbr '
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf scripts python: export-to-postgresql.py: Add has_calls column to comms table
perf scripts python: export-to-postgresql.py: Add has_calls column to comms table
Commit-ID: d9efc1d25214da500d6592095b542b32c15459df Gitweb: https://git.kernel.org/tip/d9efc1d25214da500d6592095b542b32c15459df Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:03 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:25:05 -0300
perf scripts python: export-to-postgresql.py: Add has_calls column to comms table
Now that a thread's current comm is exported, it shows up in the call graph and call tree even if it has no calls. That can happen because the calls are recorded against the main thread's initial comm.
Add a table column to make it easy for the exported-sql-viewer.py script to select only comms with calls.
Committer testing:
$ rm -f simple-retpoline.db $ sudo ~acme/bin/perf script -i simple-retpoline.perf.data --itrace=be -s ~/libexec/perf-core/scripts/python/export-to-sqlite.py simple-retpoline.db branches calls 2019-07-10 12:25:33.200529 Creating database ... 2019-07-10 12:25:33.211548 Writing records... 2019-07-10 12:25:33.549630 Adding indexes 2019-07-10 12:25:33.560715 Dropping unused tables 2019-07-10 12:25:33.580201 Done $ sha256sum tools/perf/scripts/python/export-to-sqlite.py ~/libexec/perf-core/scripts/python/export-to-sqlite.py 2922b642c392004dffa1d8789296478c85904623f5895bcb9b6cbf33e3ca999f tools/perf/scripts/python/export-to-sqlite.py 2922b642c392004dffa1d8789296478c85904623f5895bcb9b6cbf33e3ca999f /home/acme/libexec/perf-core/scripts/python/export-to-sqlite.py $ $ sqlite3 simple-retpoline.db SQLite version 3.26.0 2018-12-01 12:34:55 Enter ".help" for usage hints. sqlite> .schema comms CREATE TABLE comms (id integer NOT NULL PRIMARY KEY,comm varchar(16),c_thread_id bigint,c_time bigint,exec_flag boolean, has_calls boolean); sqlite> select id,has_calls from comms; 0|1 1|1 sqlite> select distinct comm_id from calls; 0 1 sqlite>
--- tools/perf/scripts/python/export-to-postgresql.py | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/scripts/python/export-to-postgresql.py +2 -0
@@ -886,6 +886,8 @@ def trace_end(): 'ADD CONSTRAINT parent_call_pathfk FOREIGN KEY (parent_call_path_id) REFERENCES call_paths (id)') do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') + do_query(query, 'ALTER TABLE comms ADD has_calls boolean') + do_query(query, 'UPDATE comms SET has_calls = TRUE WHERE comms.id IN (SELECT DISTINCT comm_id FROM calls)') do_query(query, 'ALTER TABLE ptwrite ' 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') do_query(query, 'ALTER TABLE cbr '
Adrian Hunter
reviewerPATCH 15/21 perf scripts python: exported-sql-viewer.py: Remove redundant semi-colons
In reply to Adrian HunterRemove redundant semi-colons added inadvertently.
--- .../scripts/python/exported-sql-viewer.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-)
tools/perf/scripts/python/exported-sql-viewer.py +12 -12
@@ -392,7 +392,7 @@ class FindBar(): self.hbox.addWidget(self.close_button) self.bar = QWidget() - self.bar.setLayout(self.hbox); + self.bar.setLayout(self.hbox) self.bar.hide() def Widget(self):
@@ -470,7 +470,7 @@ class CallGraphLevelItemBase(object): self.params = params self.row = row self.parent_item = parent_item - self.query_done = False; + self.query_done = False self.child_count = 0 self.child_items = [] if parent_item:
@@ -517,7 +517,7 @@ class CallGraphLevelTwoPlusItemBase(CallGraphLevelItemBase): self.time = time def Select(self): - self.query_done = True; + self.query_done = True query = QSqlQuery(self.glb.db) if self.params.have_ipc: ipc_str = ", SUM(insn_count), SUM(cyc_count)"
@@ -604,7 +604,7 @@ class CallGraphLevelOneItem(CallGraphLevelItemBase): self.dbid = comm_id def Select(self): - self.query_done = True; + self.query_done = True query = QSqlQuery(self.glb.db) QueryExec(query, "SELECT thread_id, pid, tid" " FROM comm_threads"
@@ -622,7 +622,7 @@ class CallGraphRootItem(CallGraphLevelItemBase): def __init__(self, glb, params): super(CallGraphRootItem, self).__init__(glb, params, 0, None) self.dbid = 0 - self.query_done = True; + self.query_done = True query = QSqlQuery(glb.db) QueryExec(query, "SELECT id, comm FROM comms") while query.next():
@@ -793,7 +793,7 @@ class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase): self.time = time def Select(self): - self.query_done = True; + self.query_done = True if self.calls_id == 0: comm_thread = " AND comm_id = " + str(self.comm_id) + " AND thread_id = " + str(self.thread_id) else:
@@ -881,7 +881,7 @@ class CallTreeLevelOneItem(CallGraphLevelItemBase): self.dbid = comm_id def Select(self): - self.query_done = True; + self.query_done = True query = QSqlQuery(self.glb.db) QueryExec(query, "SELECT thread_id, pid, tid" " FROM comm_threads"
@@ -899,7 +899,7 @@ class CallTreeRootItem(CallGraphLevelItemBase): def __init__(self, glb, params): super(CallTreeRootItem, self).__init__(glb, params, 0, None) self.dbid = 0 - self.query_done = True; + self.query_done = True query = QSqlQuery(glb.db) QueryExec(query, "SELECT id, comm FROM comms") while query.next():
@@ -971,7 +971,7 @@ class VBox(): def __init__(self, w1, w2, w3=None): self.vbox = QWidget() - self.vbox.setLayout(QVBoxLayout()); + self.vbox.setLayout(QVBoxLayout()) self.vbox.layout().setContentsMargins(0, 0, 0, 0)
@@ -1391,7 +1391,7 @@ class FetchMoreRecordsBar(): self.hbox.addWidget(self.close_button) self.bar = QWidget() - self.bar.setLayout(self.hbox); + self.bar.setLayout(self.hbox) self.bar.show() self.in_progress = False
@@ -2206,7 +2206,7 @@ class ReportDialogBase(QDialog): self.vbox.addLayout(self.grid) self.vbox.addLayout(self.hbox) - self.setLayout(self.vbox); + self.setLayout(self.vbox) def Ok(self): vars = self.report_vars
@@ -3139,7 +3139,7 @@ class AboutDialog(QDialog): self.vbox = QVBoxLayout() self.vbox.addWidget(self.text) - self.setLayout(self.vbox); + self.setLayout(self.vbox) # Font resize
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf scripts python: exported-sql-viewer.py: Remove redundant semi-colons
perf scripts python: exported-sql-viewer.py: Remove redundant semi-colons
Commit-ID: 266887291cac7f4020b5c83d2af9a13aece44a74 Gitweb: https://git.kernel.org/tip/266887291cac7f4020b5c83d2af9a13aece44a74 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:04 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:31:01 -0300
perf scripts python: exported-sql-viewer.py: Remove redundant semi-colons
Remove redundant semi-colons added inadvertently.
--- tools/perf/scripts/python/exported-sql-viewer.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
tools/perf/scripts/python/exported-sql-viewer.py +12 -12
@@ -392,7 +392,7 @@ class FindBar(): self.hbox.addWidget(self.close_button) self.bar = QWidget() - self.bar.setLayout(self.hbox); + self.bar.setLayout(self.hbox) self.bar.hide() def Widget(self):
@@ -470,7 +470,7 @@ class CallGraphLevelItemBase(object): self.params = params self.row = row self.parent_item = parent_item - self.query_done = False; + self.query_done = False self.child_count = 0 self.child_items = [] if parent_item:
@@ -517,7 +517,7 @@ class CallGraphLevelTwoPlusItemBase(CallGraphLevelItemBase): self.time = time def Select(self): - self.query_done = True; + self.query_done = True query = QSqlQuery(self.glb.db) if self.params.have_ipc: ipc_str = ", SUM(insn_count), SUM(cyc_count)"
@@ -604,7 +604,7 @@ class CallGraphLevelOneItem(CallGraphLevelItemBase): self.dbid = comm_id def Select(self): - self.query_done = True; + self.query_done = True query = QSqlQuery(self.glb.db) QueryExec(query, "SELECT thread_id, pid, tid" " FROM comm_threads"
@@ -622,7 +622,7 @@ class CallGraphRootItem(CallGraphLevelItemBase): def __init__(self, glb, params): super(CallGraphRootItem, self).__init__(glb, params, 0, None) self.dbid = 0 - self.query_done = True; + self.query_done = True query = QSqlQuery(glb.db) QueryExec(query, "SELECT id, comm FROM comms") while query.next():
@@ -793,7 +793,7 @@ class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase): self.time = time def Select(self): - self.query_done = True; + self.query_done = True if self.calls_id == 0: comm_thread = " AND comm_id = " + str(self.comm_id) + " AND thread_id = " + str(self.thread_id) else:
@@ -881,7 +881,7 @@ class CallTreeLevelOneItem(CallGraphLevelItemBase): self.dbid = comm_id def Select(self): - self.query_done = True; + self.query_done = True query = QSqlQuery(self.glb.db) QueryExec(query, "SELECT thread_id, pid, tid" " FROM comm_threads"
@@ -899,7 +899,7 @@ class CallTreeRootItem(CallGraphLevelItemBase): def __init__(self, glb, params): super(CallTreeRootItem, self).__init__(glb, params, 0, None) self.dbid = 0 - self.query_done = True; + self.query_done = True query = QSqlQuery(glb.db) QueryExec(query, "SELECT id, comm FROM comms") while query.next():
@@ -971,7 +971,7 @@ class VBox(): def __init__(self, w1, w2, w3=None): self.vbox = QWidget() - self.vbox.setLayout(QVBoxLayout()); + self.vbox.setLayout(QVBoxLayout()) self.vbox.layout().setContentsMargins(0, 0, 0, 0)
@@ -1391,7 +1391,7 @@ class FetchMoreRecordsBar(): self.hbox.addWidget(self.close_button) self.bar = QWidget() - self.bar.setLayout(self.hbox); + self.bar.setLayout(self.hbox) self.bar.show() self.in_progress = False
@@ -2206,7 +2206,7 @@ class ReportDialogBase(QDialog): self.vbox.addLayout(self.grid) self.vbox.addLayout(self.hbox) - self.setLayout(self.vbox); + self.setLayout(self.vbox) def Ok(self): vars = self.report_vars
@@ -3139,7 +3139,7 @@ class AboutDialog(QDialog): self.vbox = QVBoxLayout() self.vbox.addWidget(self.text) - self.setLayout(self.vbox); + self.setLayout(self.vbox) # Font resize
Adrian Hunter
reviewerPATCH 16/21 perf scripts python: exported-sql-viewer.py: Use new 'has_calls' column
In reply to Adrian HunterIf the new 'has_calls' column is present, use it with the call graph and call tree to select only comms that have calls.
--- tools/perf/scripts/python/exported-sql-viewer.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/scripts/python/exported-sql-viewer.py +8 -2
@@ -623,8 +623,11 @@ class CallGraphRootItem(CallGraphLevelItemBase): super(CallGraphRootItem, self).__init__(glb, params, 0, None) self.dbid = 0 self.query_done = True + if_has_calls = "" + if IsSelectable(glb.db, "comms", columns = "has_calls"): + if_has_calls = " WHERE has_calls = TRUE" query = QSqlQuery(glb.db) - QueryExec(query, "SELECT id, comm FROM comms") + QueryExec(query, "SELECT id, comm FROM comms" + if_has_calls) while query.next(): if not query.value(0): continue
@@ -900,8 +903,11 @@ class CallTreeRootItem(CallGraphLevelItemBase): super(CallTreeRootItem, self).__init__(glb, params, 0, None) self.dbid = 0 self.query_done = True + if_has_calls = "" + if IsSelectable(glb.db, "comms", columns = "has_calls"): + if_has_calls = " WHERE has_calls = TRUE" query = QSqlQuery(glb.db) - QueryExec(query, "SELECT id, comm FROM comms") + QueryExec(query, "SELECT id, comm FROM comms" + if_has_calls) while query.next(): if not query.value(0): continue
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf scripts python: exported-sql-viewer.py: Use new 'has_calls' column
perf scripts python: exported-sql-viewer.py: Use new 'has_calls' column
Commit-ID: 26c11206f433ea507a7541f48cb472b85870577e Gitweb: https://git.kernel.org/tip/26c11206f433ea507a7541f48cb472b85870577e Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:05 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:31:25 -0300
perf scripts python: exported-sql-viewer.py: Use new 'has_calls' column
If the new 'has_calls' column is present, use it with the call graph and call tree to select only comms that have calls.
Committer testing:
Just started the exported-sql-view.py and accessed all the reports, no backtraces.
--- tools/perf/scripts/python/exported-sql-viewer.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/scripts/python/exported-sql-viewer.py +8 -2
@@ -623,8 +623,11 @@ class CallGraphRootItem(CallGraphLevelItemBase): super(CallGraphRootItem, self).__init__(glb, params, 0, None) self.dbid = 0 self.query_done = True + if_has_calls = "" + if IsSelectable(glb.db, "comms", columns = "has_calls"): + if_has_calls = " WHERE has_calls = TRUE" query = QSqlQuery(glb.db) - QueryExec(query, "SELECT id, comm FROM comms") + QueryExec(query, "SELECT id, comm FROM comms" + if_has_calls) while query.next(): if not query.value(0): continue
@@ -900,8 +903,11 @@ class CallTreeRootItem(CallGraphLevelItemBase): super(CallTreeRootItem, self).__init__(glb, params, 0, None) self.dbid = 0 self.query_done = True + if_has_calls = "" + if IsSelectable(glb.db, "comms", columns = "has_calls"): + if_has_calls = " WHERE has_calls = TRUE" query = QSqlQuery(glb.db) - QueryExec(query, "SELECT id, comm FROM comms") + QueryExec(query, "SELECT id, comm FROM comms" + if_has_calls) while query.next(): if not query.value(0): continue
Adrian Hunter
reviewerPATCH 17/21 perf script: Add scripting operation process_switch()
In reply to Adrian HunterAdd scripting operation process_switch() to process switch events.
--- tools/perf/builtin-script.c | 8 +++++++- tools/perf/util/trace-event.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +7 -1
@@ -2289,6 +2289,12 @@ static int process_switch_event(struct perf_tool *tool,if (perf_event__process_switch (tool, event, sample, machine) <0 )return -1 ; +if (scripting_ops && scripting_ops->process_switch) + scripting_ops->process_switch (event, sample, machine); + +if (!script->show_switch_events) +return 0 ; + thread =machine__findnew_thread (machine, sample->pid, sample->tid);if (thread ==NULL ) {
@@ -2467,7 +2473,7 @@ static int __cmd_script(struct perf_script *script) script->tool.mmap = process_mmap_event; script->tool.mmap2 = process_mmap2_event; } -if (script->show_switch_events) +if (script->show_switch_events || (scripting_ops && scripting_ops->process_switch)) script->tool.context_switch = process_switch_event;if (script->show_namespace_events) script->tool.namespaces = process_namespaces_event;
tools/perf/util/trace-event.h +3 -0
@@ -81,6 +81,9 @@ struct scripting_ops {struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al); +void (*process_switch)(union perf_event *event, +struct perf_sample *sample, +struct machine *machine);void (*process_stat)(struct perf_stat_config *config,struct perf_evsel *evsel,u64 tstamp);void (*process_stat_interval)(u64 tstamp);
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf script: Add scripting operation process_switch()
perf script: Add scripting operation process_switch()
Commit-ID: 5bf83c29a0ad2e78683c318b607539dbadbf7a3b Gitweb: https://git.kernel.org/tip/5bf83c29a0ad2e78683c318b607539dbadbf7a3b Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:06 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:34:09 -0300
perf script: Add scripting operation process_switch()
Add scripting operation process_switch() to process switch events.
--- tools/perf/builtin-script.c | 8 +++++++- tools/perf/util/trace-event.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +7 -1
@@ -2289,6 +2289,12 @@ static int process_switch_event(struct perf_tool *tool,if (perf_event__process_switch (tool, event, sample, machine) <0 )return -1 ; +if (scripting_ops && scripting_ops->process_switch) + scripting_ops->process_switch (event, sample, machine); + +if (!script->show_switch_events) +return 0 ; + thread =machine__findnew_thread (machine, sample->pid, sample->tid);if (thread ==NULL ) {
@@ -2467,7 +2473,7 @@ static int __cmd_script(struct perf_script *script) script->tool.mmap = process_mmap_event; script->tool.mmap2 = process_mmap2_event; } -if (script->show_switch_events) +if (script->show_switch_events || (scripting_ops && scripting_ops->process_switch)) script->tool.context_switch = process_switch_event;if (script->show_namespace_events) script->tool.namespaces = process_namespaces_event;
tools/perf/util/trace-event.h +3 -0
@@ -81,6 +81,9 @@ struct scripting_ops {struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al); +void (*process_switch)(union perf_event *event, +struct perf_sample *sample, +struct machine *machine);void (*process_stat)(struct perf_stat_config *config,struct perf_evsel *evsel,u64 tstamp);void (*process_stat_interval)(u64 tstamp);
Adrian Hunter
reviewerPATCH 18/21 perf db-export: Factor out db_export__threads()
In reply to Adrian HunterIn preparation for exporting switch events, factor out db_export__threads().
--- tools/perf/util/db-export.c | 82 ++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 34 deletions(-)
tools/perf/util/db-export.c +48 -34
@@ -285,50 +285,32 @@ int db_export__branch_type(struct db_export *dbe, u32 branch_type,return 0 ; } -int db_export__sample (struct db_export *dbe,union perf_event *event, -struct perf_sample *sample,struct perf_evsel *evsel, -struct addr_location *al) +static int db_export__threads (struct db_export *dbe,struct thread *thread, +struct thread *main_thread, +struct machine *machine,struct comm **comm_ptr) { -struct thread *thread = al->thread; -struct export_sample es = { - .event = event, - .sample = sample, - .evsel = evsel, - .al = al, - }; -struct thread *main_thread;struct comm *comm =NULL ;struct comm *curr_comm;int err; - err =db_export__evsel (dbe, evsel); -if (err) -return err; - - err =db_export__machine (dbe, al->machine); -if (err) -return err; - - main_thread =thread__main_thread (al->machine, thread);if (main_thread) {/* * A thread has a reference to the main thread, so export the * main thread first. */ - err =db_export__thread (dbe, main_thread, al->machine, - main_thread); + err =db_export__thread (dbe, main_thread, machine, main_thread);if (err) - goto out_put; +return err;/* * Export comm before exporting the non-main thread because * db_export__comm_thread() can be called further below. */ - comm =machine__thread_exec_comm (al->machine, main_thread); + comm =machine__thread_exec_comm (machine, main_thread);if (comm) { err =db_export__exec_comm (dbe, comm, main_thread);if (err) - goto out_put; - es.comm_db_id = comm->db_id; +return err; + *comm_ptr = comm; } }
@@ -339,23 +321,55 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,*/ bool export_comm_thread = comm && !thread->db_id; - err =db_export__thread (dbe, thread, al->machine, main_thread); + err =db_export__thread (dbe, thread, machine, main_thread);if (err) - goto out_put; +return err;if (export_comm_thread) { err =db_export__comm_thread (dbe, comm, thread);if (err) - goto out_put; +return err; } } curr_comm =thread__comm (thread); -if (curr_comm) { - err =db_export__comm (dbe, curr_comm, thread); -if (err) - goto out_put; - } +if (curr_comm) +return db_export__comm (dbe, curr_comm, thread); + +return 0 ; +} + +int db_export__sample (struct db_export *dbe,union perf_event *event, +struct perf_sample *sample,struct perf_evsel *evsel, +struct addr_location *al) +{ +struct thread *thread = al->thread; +struct export_sample es = { + .event = event, + .sample = sample, + .evsel = evsel, + .al = al, + }; +struct thread *main_thread; +struct comm *comm =NULL ; +int err; + + err =db_export__evsel (dbe, evsel); +if (err) +return err; + + err =db_export__machine (dbe, al->machine); +if (err) +return err; + + main_thread =thread__main_thread (al->machine, thread); + + err =db_export__threads (dbe, thread, main_thread, al->machine, &comm); +if (err) + goto out_put; + +if (comm) + es.comm_db_id = comm->db_id; es.db_id = ++dbe->sample_last_db_id;
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Factor out db_export__threads()
perf db-export: Factor out db_export__threads()
Commit-ID: b3694e6c0a05383891546c6e3cdef8659d50b653 Gitweb: https://git.kernel.org/tip/b3694e6c0a05383891546c6e3cdef8659d50b653 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:07 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:35:18 -0300
perf db-export: Factor out db_export__threads()
In preparation for exporting switch events, factor out db_export__threads().
--- tools/perf/util/db-export.c | 82 ++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 34 deletions(-)
tools/perf/util/db-export.c +48 -34
@@ -286,50 +286,32 @@ int db_export__branch_type(struct db_export *dbe, u32 branch_type,return 0 ; } -int db_export__sample (struct db_export *dbe,union perf_event *event, -struct perf_sample *sample,struct perf_evsel *evsel, -struct addr_location *al) +static int db_export__threads (struct db_export *dbe,struct thread *thread, +struct thread *main_thread, +struct machine *machine,struct comm **comm_ptr) { -struct thread *thread = al->thread; -struct export_sample es = { - .event = event, - .sample = sample, - .evsel = evsel, - .al = al, - }; -struct thread *main_thread;struct comm *comm =NULL ;struct comm *curr_comm;int err; - err =db_export__evsel (dbe, evsel); -if (err) -return err; - - err =db_export__machine (dbe, al->machine); -if (err) -return err; - - main_thread =thread__main_thread (al->machine, thread);if (main_thread) {/* * A thread has a reference to the main thread, so export the * main thread first. */ - err =db_export__thread (dbe, main_thread, al->machine, - main_thread); + err =db_export__thread (dbe, main_thread, machine, main_thread);if (err) - goto out_put; +return err;/* * Export comm before exporting the non-main thread because * db_export__comm_thread() can be called further below. */ - comm =machine__thread_exec_comm (al->machine, main_thread); + comm =machine__thread_exec_comm (machine, main_thread);if (comm) { err =db_export__exec_comm (dbe, comm, main_thread);if (err) - goto out_put; - es.comm_db_id = comm->db_id; +return err; + *comm_ptr = comm; } }
@@ -340,23 +322,55 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,*/ bool export_comm_thread = comm && !thread->db_id; - err =db_export__thread (dbe, thread, al->machine, main_thread); + err =db_export__thread (dbe, thread, machine, main_thread);if (err) - goto out_put; +return err;if (export_comm_thread) { err =db_export__comm_thread (dbe, comm, thread);if (err) - goto out_put; +return err; } } curr_comm =thread__comm (thread); -if (curr_comm) { - err =db_export__comm (dbe, curr_comm, thread); -if (err) - goto out_put; - } +if (curr_comm) +return db_export__comm (dbe, curr_comm, thread); + +return 0 ; +} + +int db_export__sample (struct db_export *dbe,union perf_event *event, +struct perf_sample *sample,struct perf_evsel *evsel, +struct addr_location *al) +{ +struct thread *thread = al->thread; +struct export_sample es = { + .event = event, + .sample = sample, + .evsel = evsel, + .al = al, + }; +struct thread *main_thread; +struct comm *comm =NULL ; +int err; + + err =db_export__evsel (dbe, evsel); +if (err) +return err; + + err =db_export__machine (dbe, al->machine); +if (err) +return err; + + main_thread =thread__main_thread (al->machine, thread); + + err =db_export__threads (dbe, thread, main_thread, al->machine, &comm); +if (err) + goto out_put; + +if (comm) + es.comm_db_id = comm->db_id; es.db_id = ++dbe->sample_last_db_id;
Adrian Hunter
reviewerPATCH 19/21 perf db-export: Export switch events
In reply to Adrian HunterExport details of switch events including the threads and their current comms.
--- tools/perf/util/db-export.c | 89 +++++++++++++++++++ tools/perf/util/db-export.h | 8 ++ .../scripting-engines/trace-event-python.c | 41 +++++++++ 3 files changed, 138 insertions(+)
tools/perf/util/db-export.c +89 -0
@@ -518,3 +518,92 @@ int db_export__call_return(struct db_export *dbe, struct call_return *cr,return 0 ; } + +static int db_export__pid_tid (struct db_export *dbe,struct machine *machine, +pid_t pid,pid_t tid,u64 *db_id, +struct comm **comm_ptr,bool *is_idle) +{ +struct thread *thread =machine__find_thread (machine, pid, tid); +struct thread *main_thread; +int err =0 ; + +if (!thread || !thread->comm_set) + goto out_put; + + *is_idle = !thread->pid_ && !thread->tid; + + main_thread =thread__main_thread (machine, thread); + + err =db_export__threads (dbe, thread, main_thread, machine, comm_ptr); + + *db_id = thread->db_id; + +thread__put (main_thread); +out_put: +thread__put (thread); + +return err; +} + +int db_export__switch (struct db_export *dbe,union perf_event *event, +struct perf_sample *sample,struct machine *machine) +{ +bool out = event->header.misc &PERF_RECORD_MISC_SWITCH_OUT ; +bool out_preempt = out && + (event->header.misc &PERF_RECORD_MISC_SWITCH_OUT_PREEMPT ); +int flags = out | (out_preempt <<1 ); +bool is_idle_a = false, is_idle_b = false; +u64 th_a_id =0 , th_b_id =0 ; +u64 comm_out_id, comm_in_id; +struct comm *comm_a =NULL ; +struct comm *comm_b =NULL ; +u64 th_out_id, th_in_id; +u64 db_id; +int err; + + err =db_export__machine (dbe, machine); +if (err) +return err; + + err =db_export__pid_tid (dbe, machine, sample->pid, sample->tid, + &th_a_id, &comm_a, &is_idle_a); +if (err) +return err; + +if (event->header.type ==PERF_RECORD_SWITCH_CPU_WIDE ) { +pid_t pid = event->context_switch.next_prev_pid; +pid_t tid = event->context_switch.next_prev_tid; + + err =db_export__pid_tid (dbe, machine, pid, tid, &th_b_id, + &comm_b, &is_idle_b); +if (err) +return err; + } + +/* +* Do not export if both threads are unknown (i.e. not being traced), +* or one is unknown and the other is the idle task. +*/ +if ((!th_a_id || is_idle_a) && (!th_b_id || is_idle_b)) +return 0 ; + + db_id = ++dbe->context_switch_last_db_id; + +if (out) { + th_out_id = th_a_id; + th_in_id = th_b_id; + comm_out_id = comm_a ? comm_a->db_id :0 ; + comm_in_id = comm_b ? comm_b->db_id :0 ; + }else { + th_out_id = th_b_id; + th_in_id = th_a_id; + comm_out_id = comm_b ? comm_b->db_id :0 ; + comm_in_id = comm_a ? comm_a->db_id :0 ; + } + +if (dbe->export_context_switch) +return dbe->export_context_switch (dbe, db_id, machine, sample, + th_out_id, comm_out_id, + th_in_id, comm_in_id, flags); +return 0 ; +}
tools/perf/util/db-export.h +8 -0
@@ -57,6 +57,11 @@ struct db_export {int (*export_call_path)(struct db_export *dbe,struct call_path *cp);int (*export_call_return)(struct db_export *dbe,struct call_return *cr); +int (*export_context_switch)(struct db_export *dbe,u64 db_id, +struct machine *machine, +struct perf_sample *sample, +u64 th_out_id,u64 comm_out_id, +u64 th_in_id,u64 comm_in_id,int flags);struct call_return_processor *crp;struct call_path_root *cpr;u64 evsel_last_db_id;
@@ -69,6 +74,7 @@ struct db_export {u64 sample_last_db_id;u64 call_path_last_db_id;u64 call_return_last_db_id; +u64 context_switch_last_db_id; };int db_export__init (struct db_export *dbe);
@@ -98,5 +104,7 @@ int db_export__branch_types(struct db_export *dbe);int db_export__call_path (struct db_export *dbe,struct call_path *cp);int db_export__call_return (struct db_export *dbe,struct call_return *cr,u64 *parent_db_id); +int db_export__switch (struct db_export *dbe,union perf_event *event, +struct perf_sample *sample,struct machine *machine);#endif
tools/perf/util/scripting-engines/trace-event-python.c +41 -0
71 lines not on this page · raw message
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf db-export: Export switch events
perf db-export: Export switch events
Commit-ID: abde8722d9b0a317935506d9824e26f1aef6c24a Gitweb: https://git.kernel.org/tip/abde8722d9b0a317935506d9824e26f1aef6c24a Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:08 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:35:38 -0300
perf db-export: Export switch events
Export details of switch events including the threads and their current comms.
--- tools/perf/util/db-export.c | 89 ++++++++++++++++++++++ tools/perf/util/db-export.h | 8 ++ .../util/scripting-engines/trace-event-python.c | 41 ++++++++++ 3 files changed, 138 insertions(+)
tools/perf/util/db-export.c +89 -0
@@ -519,3 +519,92 @@ int db_export__call_return(struct db_export *dbe, struct call_return *cr,return 0 ; } + +static int db_export__pid_tid (struct db_export *dbe,struct machine *machine, +pid_t pid,pid_t tid,u64 *db_id, +struct comm **comm_ptr,bool *is_idle) +{ +struct thread *thread =machine__find_thread (machine, pid, tid); +struct thread *main_thread; +int err =0 ; + +if (!thread || !thread->comm_set) + goto out_put; + + *is_idle = !thread->pid_ && !thread->tid; + + main_thread =thread__main_thread (machine, thread); + + err =db_export__threads (dbe, thread, main_thread, machine, comm_ptr); + + *db_id = thread->db_id; + +thread__put (main_thread); +out_put: +thread__put (thread); + +return err; +} + +int db_export__switch (struct db_export *dbe,union perf_event *event, +struct perf_sample *sample,struct machine *machine) +{ +bool out = event->header.misc &PERF_RECORD_MISC_SWITCH_OUT ; +bool out_preempt = out && + (event->header.misc &PERF_RECORD_MISC_SWITCH_OUT_PREEMPT ); +int flags = out | (out_preempt <<1 ); +bool is_idle_a = false, is_idle_b = false; +u64 th_a_id =0 , th_b_id =0 ; +u64 comm_out_id, comm_in_id; +struct comm *comm_a =NULL ; +struct comm *comm_b =NULL ; +u64 th_out_id, th_in_id; +u64 db_id; +int err; + + err =db_export__machine (dbe, machine); +if (err) +return err; + + err =db_export__pid_tid (dbe, machine, sample->pid, sample->tid, + &th_a_id, &comm_a, &is_idle_a); +if (err) +return err; + +if (event->header.type ==PERF_RECORD_SWITCH_CPU_WIDE ) { +pid_t pid = event->context_switch.next_prev_pid; +pid_t tid = event->context_switch.next_prev_tid; + + err =db_export__pid_tid (dbe, machine, pid, tid, &th_b_id, + &comm_b, &is_idle_b); +if (err) +return err; + } + +/* +* Do not export if both threads are unknown (i.e. not being traced), +* or one is unknown and the other is the idle task. +*/ +if ((!th_a_id || is_idle_a) && (!th_b_id || is_idle_b)) +return 0 ; + + db_id = ++dbe->context_switch_last_db_id; + +if (out) { + th_out_id = th_a_id; + th_in_id = th_b_id; + comm_out_id = comm_a ? comm_a->db_id :0 ; + comm_in_id = comm_b ? comm_b->db_id :0 ; + }else { + th_out_id = th_b_id; + th_in_id = th_a_id; + comm_out_id = comm_b ? comm_b->db_id :0 ; + comm_in_id = comm_a ? comm_a->db_id :0 ; + } + +if (dbe->export_context_switch) +return dbe->export_context_switch (dbe, db_id, machine, sample, + th_out_id, comm_out_id, + th_in_id, comm_in_id, flags); +return 0 ; +}
tools/perf/util/db-export.h +8 -0
@@ -57,6 +57,11 @@ struct db_export {int (*export_call_path)(struct db_export *dbe,struct call_path *cp);int (*export_call_return)(struct db_export *dbe,struct call_return *cr); +int (*export_context_switch)(struct db_export *dbe,u64 db_id, +struct machine *machine, +struct perf_sample *sample, +u64 th_out_id,u64 comm_out_id, +u64 th_in_id,u64 comm_in_id,int flags);struct call_return_processor *crp;struct call_path_root *cpr;u64 evsel_last_db_id;
@@ -69,6 +74,7 @@ struct db_export {u64 sample_last_db_id;u64 call_path_last_db_id;u64 call_return_last_db_id; +u64 context_switch_last_db_id; };int db_export__init (struct db_export *dbe);
@@ -98,5 +104,7 @@ int db_export__branch_types(struct db_export *dbe);int db_export__call_path (struct db_export *dbe,struct call_path *cp);int db_export__call_return (struct db_export *dbe,struct call_return *cr,u64 *parent_db_id); +int db_export__switch (struct db_export *dbe,union perf_event *event, +struct perf_sample *sample,struct machine *machine);#endif
tools/perf/util/scripting-engines/trace-event-python.c +41 -0
71 lines not on this page · raw message
Adrian Hunter
reviewerPATCH 20/21 perf scripts python: export-to-sqlite.py: Export switch events
In reply to Adrian HunterExport switch events to a new table 'context_switches' and create a view 'context_switches_view'. The table and view will show automatically in the exported-sql-viewer.py script.
If the table ends up empty, then it and the view are dropped.
--- tools/perf/scripts/python/export-to-sqlite.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+)
tools/perf/scripts/python/export-to-sqlite.py +41 -0
@@ -306,6 +306,17 @@ do_query(query, 'CREATE TABLE pwrx (' 'last_cstate integer,' 'wake_reason integer)') +do_query(query, 'CREATE TABLE context_switches (' + 'id integer NOT NULL PRIMARY KEY,' + 'machine_id bigint,' + 'time bigint,' + 'cpu integer,' + 'thread_out_id bigint,' + 'comm_out_id bigint,' + 'thread_in_id bigint,' + 'comm_in_id bigint,' + 'flags integer)') + # printf was added to sqlite in version 3.8.3 sqlite_has_printf = False try:
@@ -530,6 +541,29 @@ do_query(query, 'CREATE VIEW power_events_view AS ' ' INNER JOIN selected_events ON selected_events.id = evsel_id' ' WHERE selected_events.name IN (\'cbr\',\'mwait\',\'exstop\',\'pwre\',\'pwrx\')') +do_query(query, 'CREATE VIEW context_switches_view AS ' + 'SELECT ' + 'context_switches.id,' + 'context_switches.machine_id,' + 'context_switches.time,' + 'context_switches.cpu,' + 'th_out.pid AS pid_out,' + 'th_out.tid AS tid_out,' + 'comm_out.comm AS comm_out,' + 'th_in.pid AS pid_in,' + 'th_in.tid AS tid_in,' + 'comm_in.comm AS comm_in,' + 'CASE WHEN context_switches.flags = 0 THEN \'in\'' + ' WHEN context_switches.flags = 1 THEN \'out\'' + ' WHEN context_switches.flags = 3 THEN \'out preempt\'' + ' ELSE context_switches.flags ' + 'END AS flags' + ' FROM context_switches' + ' INNER JOIN threads AS th_out ON th_out.id = context_switches.thread_out_id' + ' INNER JOIN threads AS th_in ON th_in.id = context_switches.thread_in_id' + ' INNER JOIN comms AS comm_out ON comm_out.id = context_switches.comm_out_id' + ' INNER JOIN comms AS comm_in ON comm_in.id = context_switches.comm_in_id') + do_query(query, 'END TRANSACTION') evsel_query = QSqlQuery(db)
@@ -571,6 +605,8 @@ exstop_query = QSqlQuery(db) exstop_query.prepare("INSERT INTO exstop VALUES (?, ?)") pwrx_query = QSqlQuery(db) pwrx_query.prepare("INSERT INTO pwrx VALUES (?, ?, ?, ?)") +context_switch_query = QSqlQuery(db) +context_switch_query.prepare("INSERT INTO context_switches VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)") def trace_begin(): printdate("Writing records...")
@@ -620,6 +656,8 @@ def trace_end(): drop("pwrx") if is_table_empty("cbr"): drop("cbr") + if is_table_empty("context_switches"): + drop("context_switches") if (unhandled_count): printdate("Warning: ", unhandled_count, " unhandled events")
@@ -753,3 +791,6 @@ def synth_data(id, config, raw_buf, *x): pwrx(id, raw_buf) elif config == 5: cbr(id, raw_buf) + +def context_switch_table(*x): + bind_exec(context_switch_query, 9, x)
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf scripts python: export-to-sqlite.py: Export switch events
perf scripts python: export-to-sqlite.py: Export switch events
Commit-ID: 37c1f991b1bcdbe268b99b22e265738f4209f4f4 Gitweb: https://git.kernel.org/tip/37c1f991b1bcdbe268b99b22e265738f4209f4f4 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:09 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 12:37:35 -0300
perf scripts python: export-to-sqlite.py: Export switch events
Export switch events to a new table 'context_switches' and create a view 'context_switches_view'. The table and view will show automatically in the exported-sql-viewer.py script.
If the table ends up empty, then it and the view are dropped.
Committer testing:
Use the exported-sql-viewer.py and look at "Tables" -> "context_switches":
id machine_id time cpu thread_out_id comm_out_id thread_in_id comm_in_id flags 1 1 187836111885918 7 1 1 2 2 3 2 1 187836111889369 7 1 1 2 2 0 3 1 187836112464618 7 2 3 1 1 1 4 1 187836112465511 7 2 3 1 1 0
--- tools/perf/scripts/python/export-to-sqlite.py | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
tools/perf/scripts/python/export-to-sqlite.py +41 -0
@@ -306,6 +306,17 @@ do_query(query, 'CREATE TABLE pwrx (' 'last_cstate integer,' 'wake_reason integer)') +do_query(query, 'CREATE TABLE context_switches (' + 'id integer NOT NULL PRIMARY KEY,' + 'machine_id bigint,' + 'time bigint,' + 'cpu integer,' + 'thread_out_id bigint,' + 'comm_out_id bigint,' + 'thread_in_id bigint,' + 'comm_in_id bigint,' + 'flags integer)') + # printf was added to sqlite in version 3.8.3 sqlite_has_printf = False try:
@@ -530,6 +541,29 @@ do_query(query, 'CREATE VIEW power_events_view AS ' ' INNER JOIN selected_events ON selected_events.id = evsel_id' ' WHERE selected_events.name IN (\'cbr\',\'mwait\',\'exstop\',\'pwre\',\'pwrx\')') +do_query(query, 'CREATE VIEW context_switches_view AS ' + 'SELECT ' + 'context_switches.id,' + 'context_switches.machine_id,' + 'context_switches.time,' + 'context_switches.cpu,' + 'th_out.pid AS pid_out,' + 'th_out.tid AS tid_out,' + 'comm_out.comm AS comm_out,' + 'th_in.pid AS pid_in,' + 'th_in.tid AS tid_in,' + 'comm_in.comm AS comm_in,' + 'CASE WHEN context_switches.flags = 0 THEN \'in\'' + ' WHEN context_switches.flags = 1 THEN \'out\'' + ' WHEN context_switches.flags = 3 THEN \'out preempt\'' + ' ELSE context_switches.flags ' + 'END AS flags' + ' FROM context_switches' + ' INNER JOIN threads AS th_out ON th_out.id = context_switches.thread_out_id' + ' INNER JOIN threads AS th_in ON th_in.id = context_switches.thread_in_id' + ' INNER JOIN comms AS comm_out ON comm_out.id = context_switches.comm_out_id' + ' INNER JOIN comms AS comm_in ON comm_in.id = context_switches.comm_in_id') + do_query(query, 'END TRANSACTION') evsel_query = QSqlQuery(db)
@@ -571,6 +605,8 @@ exstop_query = QSqlQuery(db) exstop_query.prepare("INSERT INTO exstop VALUES (?, ?)") pwrx_query = QSqlQuery(db) pwrx_query.prepare("INSERT INTO pwrx VALUES (?, ?, ?, ?)") +context_switch_query = QSqlQuery(db) +context_switch_query.prepare("INSERT INTO context_switches VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)") def trace_begin(): printdate("Writing records...")
@@ -620,6 +656,8 @@ def trace_end(): drop("pwrx") if is_table_empty("cbr"): drop("cbr") + if is_table_empty("context_switches"): + drop("context_switches") if (unhandled_count): printdate("Warning: ", unhandled_count, " unhandled events")
@@ -753,3 +791,6 @@ def synth_data(id, config, raw_buf, *x): pwrx(id, raw_buf) elif config == 5: cbr(id, raw_buf) + +def context_switch_table(*x): + bind_exec(context_switch_query, 9, x)
Adrian Hunter
reviewerPATCH 21/21 perf scripts python: export-to-postgresql.py: Export switch events
In reply to Adrian HunterExport switch events to a new table 'context_switches' and create a view 'context_switches_view'. The table and view will show automatically in the exported-sql-viewer.py script.
If the table ends up empty, then it and the view are dropped.
--- .../scripts/python/export-to-postgresql.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+)
tools/perf/scripts/python/export-to-postgresql.py +51 -0
@@ -482,6 +482,17 @@ do_query(query, 'CREATE TABLE pwrx (' 'last_cstate integer,' 'wake_reason integer)') +do_query(query, 'CREATE TABLE context_switches (' + 'id bigint NOT NULL,' + 'machine_id bigint,' + 'time bigint,' + 'cpu integer,' + 'thread_out_id bigint,' + 'comm_out_id bigint,' + 'thread_in_id bigint,' + 'comm_in_id bigint,' + 'flags integer)') + do_query(query, 'CREATE VIEW machines_view AS ' 'SELECT ' 'id,'
@@ -695,6 +706,29 @@ do_query(query, 'CREATE VIEW power_events_view AS ' ' INNER JOIN selected_events ON selected_events.id = samples.evsel_id' ' ORDER BY samples.id') +do_query(query, 'CREATE VIEW context_switches_view AS ' + 'SELECT ' + 'context_switches.id,' + 'context_switches.machine_id,' + 'context_switches.time,' + 'context_switches.cpu,' + 'th_out.pid AS pid_out,' + 'th_out.tid AS tid_out,' + 'comm_out.comm AS comm_out,' + 'th_in.pid AS pid_in,' + 'th_in.tid AS tid_in,' + 'comm_in.comm AS comm_in,' + 'CASE WHEN context_switches.flags = 0 THEN \'in\'' + ' WHEN context_switches.flags = 1 THEN \'out\'' + ' WHEN context_switches.flags = 3 THEN \'out preempt\'' + ' ELSE CAST ( context_switches.flags AS VARCHAR(11) )' + 'END AS flags' + ' FROM context_switches' + ' INNER JOIN threads AS th_out ON th_out.id = context_switches.thread_out_id' + ' INNER JOIN threads AS th_in ON th_in.id = context_switches.thread_in_id' + ' INNER JOIN comms AS comm_out ON comm_out.id = context_switches.comm_out_id' + ' INNER JOIN comms AS comm_in ON comm_in.id = context_switches.comm_in_id') + file_header = struct.pack("!11sii", b"PGCOPY\n\377\r\n\0", 0, 0) file_trailer = b"\377\377"
@@ -759,6 +793,7 @@ mwait_file = open_output_file("mwait_table.bin") pwre_file = open_output_file("pwre_table.bin") exstop_file = open_output_file("exstop_table.bin") pwrx_file = open_output_file("pwrx_table.bin") +context_switches_file = open_output_file("context_switches_table.bin") def trace_begin(): printdate("Writing to intermediate files...")
@@ -807,6 +842,7 @@ def trace_end(): copy_output_file(pwre_file, "pwre") copy_output_file(exstop_file, "exstop") copy_output_file(pwrx_file, "pwrx") + copy_output_file(context_switches_file, "context_switches") printdate("Removing intermediate files...") remove_output_file(evsel_file)
@@ -828,6 +864,7 @@ def trace_end(): remove_output_file(pwre_file) remove_output_file(exstop_file) remove_output_file(pwrx_file) + remove_output_file(context_switches_file) os.rmdir(output_dir_name) printdate("Adding primary keys") do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
@@ -849,6 +886,7 @@ def trace_end(): do_query(query, 'ALTER TABLE pwre ADD PRIMARY KEY (id)') do_query(query, 'ALTER TABLE exstop ADD PRIMARY KEY (id)') do_query(query, 'ALTER TABLE pwrx ADD PRIMARY KEY (id)') + do_query(query, 'ALTER TABLE context_switches ADD PRIMARY KEY (id)') printdate("Adding foreign keys") do_query(query, 'ALTER TABLE threads '
@@ -900,6 +938,12 @@ def trace_end(): 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') do_query(query, 'ALTER TABLE pwrx ' 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') + do_query(query, 'ALTER TABLE context_switches ' + 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' + 'ADD CONSTRAINT toutfk FOREIGN KEY (thread_out_id) REFERENCES threads (id),' + 'ADD CONSTRAINT tinfk FOREIGN KEY (thread_in_id) REFERENCES threads (id),' + 'ADD CONSTRAINT coutfk FOREIGN KEY (comm_out_id) REFERENCES comms (id),' + 'ADD CONSTRAINT cinfk FOREIGN KEY (comm_in_id) REFERENCES comms (id)') printdate("Dropping unused tables") if is_table_empty("ptwrite"):
@@ -912,6 +956,8 @@ def trace_end(): drop("pwrx") if is_table_empty("cbr"): drop("cbr") + if is_table_empty("context_switches"): + drop("context_switches") if (unhandled_count): printdate("Warning: ", unhandled_count, " unhandled events")
@@ -1058,3 +1104,8 @@ def synth_data(id, config, raw_buf, *x): pwrx(id, raw_buf) elif config == 5: cbr(id, raw_buf) + +def context_switch_table(id, machine_id, time, cpu, thread_out_id, comm_out_id, thread_in_id, comm_in_id, flags, *x): + fmt = "!hiqiqiqiiiqiqiqiqii" + value = struct.pack(fmt, 9, 8, id, 8, machine_id, 8, time, 4, cpu, 8, thread_out_id, 8, comm_out_id, 8, thread_in_id, 8, comm_in_id, 4, flags) + context_switches_file.write(value)
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf scripts python: export-to-postgresql.py: Export switch events
perf scripts python: export-to-postgresql.py: Export switch events
Commit-ID: 56789f3dc127d4f8c07ce2bb48629ba75e8ef16c Gitweb: https://git.kernel.org/tip/56789f3dc127d4f8c07ce2bb48629ba75e8ef16c Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 10 Jul 2019 11:58:10 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 10 Jul 2019 13:05:12 -0300
perf scripts python: export-to-postgresql.py: Export switch events
Export switch events to a new table 'context_switches' and create a view 'context_switches_view'. The table and view will show automatically in the exported-sql-viewer.py script.
If the table ends up empty, then it and the view are dropped.
--- tools/perf/scripts/python/export-to-postgresql.py | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+)
tools/perf/scripts/python/export-to-postgresql.py +51 -0
@@ -482,6 +482,17 @@ do_query(query, 'CREATE TABLE pwrx (' 'last_cstate integer,' 'wake_reason integer)') +do_query(query, 'CREATE TABLE context_switches (' + 'id bigint NOT NULL,' + 'machine_id bigint,' + 'time bigint,' + 'cpu integer,' + 'thread_out_id bigint,' + 'comm_out_id bigint,' + 'thread_in_id bigint,' + 'comm_in_id bigint,' + 'flags integer)') + do_query(query, 'CREATE VIEW machines_view AS ' 'SELECT ' 'id,'
@@ -695,6 +706,29 @@ do_query(query, 'CREATE VIEW power_events_view AS ' ' INNER JOIN selected_events ON selected_events.id = samples.evsel_id' ' ORDER BY samples.id') +do_query(query, 'CREATE VIEW context_switches_view AS ' + 'SELECT ' + 'context_switches.id,' + 'context_switches.machine_id,' + 'context_switches.time,' + 'context_switches.cpu,' + 'th_out.pid AS pid_out,' + 'th_out.tid AS tid_out,' + 'comm_out.comm AS comm_out,' + 'th_in.pid AS pid_in,' + 'th_in.tid AS tid_in,' + 'comm_in.comm AS comm_in,' + 'CASE WHEN context_switches.flags = 0 THEN \'in\'' + ' WHEN context_switches.flags = 1 THEN \'out\'' + ' WHEN context_switches.flags = 3 THEN \'out preempt\'' + ' ELSE CAST ( context_switches.flags AS VARCHAR(11) )' + 'END AS flags' + ' FROM context_switches' + ' INNER JOIN threads AS th_out ON th_out.id = context_switches.thread_out_id' + ' INNER JOIN threads AS th_in ON th_in.id = context_switches.thread_in_id' + ' INNER JOIN comms AS comm_out ON comm_out.id = context_switches.comm_out_id' + ' INNER JOIN comms AS comm_in ON comm_in.id = context_switches.comm_in_id') + file_header = struct.pack("!11sii", b"PGCOPY\n\377\r\n\0", 0, 0) file_trailer = b"\377\377"
@@ -759,6 +793,7 @@ mwait_file = open_output_file("mwait_table.bin") pwre_file = open_output_file("pwre_table.bin") exstop_file = open_output_file("exstop_table.bin") pwrx_file = open_output_file("pwrx_table.bin") +context_switches_file = open_output_file("context_switches_table.bin") def trace_begin(): printdate("Writing to intermediate files...")
@@ -807,6 +842,7 @@ def trace_end(): copy_output_file(pwre_file, "pwre") copy_output_file(exstop_file, "exstop") copy_output_file(pwrx_file, "pwrx") + copy_output_file(context_switches_file, "context_switches") printdate("Removing intermediate files...") remove_output_file(evsel_file)
@@ -828,6 +864,7 @@ def trace_end(): remove_output_file(pwre_file) remove_output_file(exstop_file) remove_output_file(pwrx_file) + remove_output_file(context_switches_file) os.rmdir(output_dir_name) printdate("Adding primary keys") do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
@@ -849,6 +886,7 @@ def trace_end(): do_query(query, 'ALTER TABLE pwre ADD PRIMARY KEY (id)') do_query(query, 'ALTER TABLE exstop ADD PRIMARY KEY (id)') do_query(query, 'ALTER TABLE pwrx ADD PRIMARY KEY (id)') + do_query(query, 'ALTER TABLE context_switches ADD PRIMARY KEY (id)') printdate("Adding foreign keys") do_query(query, 'ALTER TABLE threads '
@@ -900,6 +938,12 @@ def trace_end(): 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') do_query(query, 'ALTER TABLE pwrx ' 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') + do_query(query, 'ALTER TABLE context_switches ' + 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' + 'ADD CONSTRAINT toutfk FOREIGN KEY (thread_out_id) REFERENCES threads (id),' + 'ADD CONSTRAINT tinfk FOREIGN KEY (thread_in_id) REFERENCES threads (id),' + 'ADD CONSTRAINT coutfk FOREIGN KEY (comm_out_id) REFERENCES comms (id),' + 'ADD CONSTRAINT cinfk FOREIGN KEY (comm_in_id) REFERENCES comms (id)') printdate("Dropping unused tables") if is_table_empty("ptwrite"):
@@ -912,6 +956,8 @@ def trace_end(): drop("pwrx") if is_table_empty("cbr"): drop("cbr") + if is_table_empty("context_switches"): + drop("context_switches") if (unhandled_count): printdate("Warning: ", unhandled_count, " unhandled events")
@@ -1058,3 +1104,8 @@ def synth_data(id, config, raw_buf, *x): pwrx(id, raw_buf) elif config == 5: cbr(id, raw_buf) + +def context_switch_table(id, machine_id, time, cpu, thread_out_id, comm_out_id, thread_in_id, comm_in_id, flags, *x): + fmt = "!hiqiqiqiiiqiqiqiqii" + value = struct.pack(fmt, 9, 8, id, 8, machine_id, 8, time, 4, cpu, 8, thread_out_id, 8, comm_out_id, 8, thread_in_id, 8, comm_in_id, 4, flags) + context_switches_file.write(value)