Skip to content

Commit

Permalink
Allow animations with Oids
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jnidzwetzki committed Feb 27, 2024
1 parent 2107906 commit 623903c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/pg_lock_tracer/animate_lock_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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():
"""
Expand Down

0 comments on commit 623903c

Please sign in to comment.