summaryrefslogtreecommitdiffstats
path: root/third_party/npapi
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-15 20:12:24 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-15 20:12:24 +0000
commitd4de666a8ad7f5ba0321e11f317ed89f9dd16dd5 (patch)
treea98d06fdb4dad41dc729f616e10594412638ad9e /third_party/npapi
parent4c788a05b37b4e375c109d18bd280d8b500f415c (diff)
downloadchromium_src-d4de666a8ad7f5ba0321e11f317ed89f9dd16dd5.zip
chromium_src-d4de666a8ad7f5ba0321e11f317ed89f9dd16dd5.tar.gz
chromium_src-d4de666a8ad7f5ba0321e11f317ed89f9dd16dd5.tar.bz2
Add a Python script which analyzes information about steams from NPSPY's logs. I figured I'd commit it in case someone finds it useful in the future.
Review URL: http://codereview.chromium.org/491055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34592 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/npapi')
-rw-r--r--third_party/npapi/npspy/analyze_streams.py105
1 files changed, 105 insertions, 0 deletions
diff --git a/third_party/npapi/npspy/analyze_streams.py b/third_party/npapi/npspy/analyze_streams.py
new file mode 100644
index 0000000..0b2c8db
--- /dev/null
+++ b/third_party/npapi/npspy/analyze_streams.py
@@ -0,0 +1,105 @@
+# A script for analyzing the output of NPSPY and merging data about streams.
+
+import sys
+
+
+def ReadFile(filename, flags='rb'):
+ """Returns the contents of a file."""
+ file = open(filename, flags)
+ result = file.read()
+ file.close()
+ return result
+
+
+def WriteFile(filename, contents):
+ """Overwrites the file with the given contents."""
+ file = open(filename, 'w')
+ file.write(contents)
+ file.close()
+
+
+# sample line: 'NPP_NewStream(0x645c898, 0x56ba900("application/x-shockwave-flash"), 0x64bb3b0 (http://weeklyad.target.com/target/flash/target/target.swf?ver=090326), TRUE, NP_NORMAL)'
+class Stream:
+ def __init__(self, line):
+ split = line.split(', ')
+
+ self.mime_type = split[1].split('"')[1]
+ self.url = split[2].split(' ')[1].strip('()')
+ self.seekable = split[3]
+ self.type = split[4].strip(')')
+ self.size = 0
+ self.status = ''
+ try:
+ self.address = split[2].split(' ')[0]
+ except:
+ print 'parsing error on ' + line
+ self.address = ''
+
+ if self.type != 'NP_NORMAL':
+ print 'line got unexpected type: ' + line
+
+
+def main(argv=None):
+ if argv is None:
+ argv = sys.argv
+
+ streams = []
+
+ if len(argv) != 2:
+ print 'need filename'
+ return
+ file = ReadFile(argv[1])
+ for line in file.splitlines():
+ if line.startswith('NPP_NewStream('):
+ if line.count('(') < 3:
+ print 'unknown format for line: ' + line
+ continue
+
+ s = Stream(line)
+ streams.append(s)
+ elif line.startswith('NPP_Write('):
+ # sample: NPP_Write(0x645c898, 0x64bb3b0, 0, 16384, 0x56c1000("CW")))
+ split = line.split(', ')
+ address = split[1]
+ start = int(split[2])
+ size = int(split[3])
+ found = False
+ for stream in streams:
+ if stream.address == address:
+ if stream.size != start:
+ print 'error: starting at wrong place for write ' + stream.url + ' ' + str(stream.size) + ' ' + str(start)
+ stream.size += size
+ found = True
+ break
+
+ if not found:
+ print "couldn't find stream to match NPP_Write " + line
+ elif line.startswith('NPP_DestroyStream('):
+ # sample: NPP_DestroyStream(0x645c898, 0x64bb3b0, NPRES_DONE)
+ split = line.split(', ')
+ address = split[1]
+ status = split[2].strip(')')
+ found = False
+ for stream in streams:
+ if stream.address == address:
+ stream.status = status
+ stream.address = '' # address can be reused
+ found = True
+ break
+
+ if not found:
+ print "couldn't find stream to match NPP_DestroyStream " + line
+
+
+ output = []
+ for stream in streams:
+ if stream.status != 'NPRES_DONE':
+ print 'error: no NPP_DestroyStream with success for ' + stream.url + ' ' + stream.status + '.'
+ output.append(', '.join([stream.url, stream.mime_type, str(stream.size), stream.seekable]))
+ output_file = argv[1].replace('.', '_analyzed.')
+
+ WriteFile(output_file, '\n'.join(output))
+
+
+if __name__ == "__main__":
+ sys.exit(main())