From 623903c5c788d41839964f3d9b5ee2703b9219f7 Mon Sep 17 00:00:00 2001 From: Jan Nidzwetzki Date: Tue, 27 Feb 2024 22:32:26 +0100 Subject: [PATCH] Allow animations with Oids So far, animations could be only generated if the Oids of the table names were resolved to actual table names. This patch removes this limitation and also allows animations using OIDs. --- README.md | 9 +++++++-- src/pg_lock_tracer/animate_lock_graph.py | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 92f0d37..a472d71 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,13 @@ pg_lock_tracer -x /home/jan/postgresql-sandbox/bin/REL_15_1_DEBUG/bin/postgres - # Show statistics about locks pg_lock_tracer -x /home/jan/postgresql-sandbox/bin/REL_15_1_DEBUG/bin/postgres -p 1234 --statistics -# Create an animated lock graph -animate_lock_graph -i create_table_trace.json -o create_table_trace.html +# Create an animated lock graph (with Oids) +pg_lock_tracer -x /home/jan/postgresql-sandbox/bin/REL_15_1_DEBUG/bin/postgres -p 1234 -j -o locks.json +animate_lock_graph -i lock -o locks.html + +# Create an animated lock graph (with table names) +pg_lock_tracer -x /home/jan/postgresql-sandbox/bin/REL_15_1_DEBUG/bin/postgres -p 1234 -j -r 1234:psql://jan@localhost/test2 -o locks.json +animate_lock_graph -i lock -o locks.html ``` ## Example Output diff --git a/src/pg_lock_tracer/animate_lock_graph.py b/src/pg_lock_tracer/animate_lock_graph.py index cc1036e..f701f57 100755 --- a/src/pg_lock_tracer/animate_lock_graph.py +++ b/src/pg_lock_tracer/animate_lock_graph.py @@ -207,7 +207,7 @@ def handle_json(self, event): if self.verbose: print(f"Processing {event}") - tablename = event["table"] + tablename = StringHelper.get_tablename(event) lock_type = event["lock_type"] if not self.graph.vs.select(label_eq=tablename): @@ -244,7 +244,7 @@ def handle_json(self, event): if self.verbose: print(f"Processing {event}") - tablename = event["table"] + tablename = StringHelper.get_tablename(event) lock_type = event["lock_type"] lock_numeric_value = PostgreSQLLockHelper.lock_type_to_int(lock_type) @@ -383,6 +383,16 @@ def split_string(mystring, max_length): return result + @staticmethod + def get_tablename(event): + """ + Get the tablename or the Oid of the event. + """ + if "table" in event: + return event["table"] + + return f"Oid {event['oid']}" + def main(): """