Created
April 20, 2018 18:22
-
-
Save tomrittervg/90329fea97486bfc9e4e8a4c8d51cc06 to your computer and use it in GitHub Desktop.
Script to parse the output of MOZ_LOG="nsStandardURL:5"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import re | |
import sys | |
class URL: | |
def __init__(self, ptr): | |
self.ptr = ptr | |
self.count = 0 | |
self.url = "" | |
self.url_set = False | |
self.trackB = False | |
def setURL(self, url): | |
if self.url_set: | |
raise Exception("Trying to re-set a url that's already have a value. Current: " + self.url + " Attempted: " + url) | |
self.url = url | |
self.url_set = True | |
def track(self): | |
if self.trackB: | |
raise Exception("Can't retrack something that's already tracked" + self.ptr) | |
self.trackB = True | |
def untrack(self): | |
if not self.trackB: | |
raise Exception("Can't untrack something that's not tracked? " + self.ptr) | |
self.trackB = False | |
def increment(self): | |
self.count += 1 | |
def decrement(self): | |
if self.count == 0: | |
raise Exception("Can't decrement from 0") | |
self.count -= 1 | |
if self.count == 0: | |
self.url_set = False | |
def __str__(self): | |
return "%s, %s, %s, %s" % (self.ptr, self.count, self.trackB, self.url) | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print "Usage:", sys.argv[0], "filename" | |
sys.exit(1) | |
createLine = "D/nsStandardURL Creating nsStandardURL @" | |
destroyLine = "D/nsStandardURL Destroying nsStandardURL @" | |
setSpecLine = "D/nsStandardURL nsStandardURL::SetSpec [this=" | |
trackLine = "And Tracking URL nsStandardURL @" | |
untrackLine = "And Un-tracking URL nsStandardURL @" | |
line = 0 | |
activeUrls = {} | |
f = open(sys.argv[1]) | |
for l in f: | |
l = l.strip() | |
try: | |
if setSpecLine in l: | |
trimmed = l[l.index(setSpecLine) + len(setSpecLine):].strip() | |
parts = trimmed.split(" ") | |
ptr = parts[0].strip() | |
spec = parts[1][5:-1] | |
activeUrls[ptr].setURL(spec) | |
elif trackLine in l: | |
ptr = l[l.index(trackLine) + len(trackLine):].strip() | |
activeUrls[ptr].track() | |
elif untrackLine in l: | |
ptr = l[l.index(untrackLine) + len(untrackLine):].strip() | |
activeUrls[ptr].untrack() | |
elif createLine in l: | |
ptr = l[l.index(createLine) + len(createLine):].strip() | |
if ptr not in activeUrls: | |
activeUrls[ptr] = URL(ptr) | |
activeUrls[ptr].increment() | |
elif destroyLine in l: | |
ptr = l[l.index(destroyLine) + len(destroyLine):].strip() | |
if ptr not in activeUrls: | |
raise Exception("We destroyed a URL we hadn't seen created! " + ptr) | |
activeUrls[ptr].decrement() | |
except Exception as e: | |
print "Line", line, l | |
print " ", activeUrls[ptr] | |
print " ", e | |
line += 1 | |
print "URLs we never destroyed:" | |
for k in activeUrls: | |
if activeUrls[k].count > 0: | |
print activeUrls[k] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment