eocanha

gstbuffer-leak-analyzer

Mar 5th, 2021
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. # Call the script like this:
  4. #
  5. # ../runtest.sh 2>&1 > /tmp/leak.txt
  6. # (browse some videos, then CTRL+c to terminate)
  7. # gstbuffer-leak-analyzer < /tmp/leak.txt
  8. #
  9. # This script expects a log like this in stdin:
  10. #
  11. # 0:00:21.500314002   402   0x99ca30 LOG               GST_BUFFER gstbuffer.c:715:gst_buffer_new: new 0x676a9990
  12. # 0:00:21.415772804   402   0x99ca30 LOG               GST_BUFFER gstbuffer.c:771:gst_buffer_new_allocate: new buffer 0x6762d538 of size 10526 from allocator (nil)
  13. # 0:00:21.502333117   402   0x99ca30 LOG               GST_BUFFER gstbuffer.c:641:_gst_buffer_free: finalize 0x676a9990
  14. #
  15. # 0:00:06.529541560   954  0x1d95ac0 DEBUG             GST_MEMORY gstmemory.c:138:gst_memory_init: new memory 0x1de31e8, maxsize:2063762 offset:0 size:2063762
  16. # 0:00:06.529866872   954  0x1d95ac0 DEBUG             GST_MEMORY gstmemory.c:87:_gst_memory_free: free memory 0x1aea078
  17. # ...
  18. #
  19. # and will report unbalanced object creation, like this:
  20. #
  21. # { 'gstbuffer:': 4 }
  22. #
  23. # To get the needed log, you need to enable the proper GStreamer logging when running the browser:
  24. #
  25. #   export GST_DEBUG="GST_BUFFER:LOG,GST_MEMORY:LOG"
  26.  
  27. import sys, pprint
  28.  
  29. # Default values
  30. data = {}
  31. creates = {}
  32. destroys = {}
  33.  
  34. data['stage'] = 0
  35.  
  36. # Input parsing
  37. for line in sys.stdin:
  38.   if line.find("gst_buffer_new:") != -1:
  39.     fields = line.split()
  40.     obj = "gstbuffer"
  41.     #ptr = fields[7].strip()
  42.     action = "CREATE"
  43.   elif line.find("gst_buffer_free:") != -1:
  44.     fields = line.split()
  45.     obj = "gstbuffer"
  46.     #ptr = fields[7].strip()
  47.     action = "DESTROY"
  48.   elif line.find("gst_memory_init:") != -1:
  49.     fields = line.split()
  50.     obj = "gstmemory"
  51.     #ptr = fields[8].strip();
  52.     action = "CREATE"
  53.   elif line.find("_gst_memory_free:") != -1:
  54.     fields = line.split()
  55.     obj = "gstmemory"
  56.     #ptr = fields[8].strip();
  57.     action = "DESTROY"
  58.   elif line.find("PAUSING VIDEO") != -1:
  59.     data["stage"] = 100;
  60.   elif line.find("DISPOSING SOURCEBUFFER") != -1:
  61.     data["stage"] = 200;
  62.   elif line.find("RESETTING WEBPAGE") != -1:
  63.     data["stage"] = 300;
  64.   else:
  65.     continue;
  66.  
  67.   if (action == "CREATE"):
  68.     if not(obj in data.keys()):
  69.       creates[obj] = 0
  70.       destroys[obj] = 0
  71.       data[obj] = 0
  72.     data[obj] = data[obj] + 1
  73.     creates[obj] = creates[obj] + 1
  74.   if (action == "DESTROY"):
  75.     data[obj] = data[obj] - 1
  76.     destroys[obj] = destroys[obj] + 1
  77.  
  78.   try:
  79.     print '"'+str(data["gstbuffer"])+'", "'+str(data["gstmemory"])+'", "'+str(data["stage"])+'"';
  80.   except:
  81.     pass
  82.  
  83. print("CREATIONS:")
  84. pprint.PrettyPrinter(indent=2).pprint(creates)
  85. print("DESTRUCTIONS:")
  86. pprint.PrettyPrinter(indent=2).pprint(destroys)
  87. print("BALANCE:")
  88. pprint.PrettyPrinter(indent=2).pprint(data)
RAW Paste Data