Bug 1168784 - Part 1: Fix the script merging profiles to handle new profiler JSON format. r=benwa
authorTing-Yu Chou <janus926@gmail.com>
Mon, 01 Jun 2015 18:09:29 +0800
changeset 269589 fcc5f6cc417af0558fabed8e8b19149234be832c
parent 269588 4398af421574b1fade89b7d1221debde192311c2
child 269590 daf2ce357d237ba0047d7defedfc790e6aefdd6d
push id2540
push userwcosta@mozilla.com
push dateWed, 03 Jun 2015 20:55:41 +0000
reviewersbenwa
bugs1168784
milestone41.0a1
Bug 1168784 - Part 1: Fix the script merging profiles to handle new profiler JSON format. r=benwa
tools/profiler/merge-profiles.py
--- a/tools/profiler/merge-profiles.py
+++ b/tools/profiler/merge-profiles.py
@@ -45,39 +45,55 @@ def MergeProfiles(files):
             thread['name'] = thread['name'] + " (" + pname + ":" + pid + ")"
             threads.append(thread)
 
             # Note that pid + sym, pid + location could be ambigious
             # if we had pid=11 sym=1 && pid=1 sym=11.
             pidStr = pid + ":"
 
             thread['startTime'] = fileData['profileJSON']['meta']['startTime']
-            samples = thread['samples']
-            for sample in thread['samples']:
-                for frame in sample['frames']:
-                    if "location" in frame and frame['location'][0:2] == '0x':
-                        oldLoc = frame['location']
-                        newLoc = pidStr + oldLoc
-                        frame['location'] = newLoc
-                        # Default to the unprefixed symbol if no translation is available
-                        symTable[newLoc] = oldLoc
+            if meta['version'] >= 3:
+                stringTable = thread['stringTable']
+                for i, str in enumerate(stringTable):
+                    if str[:2] == '0x':
+                        newLoc = pidStr + str
+                        stringTable[i] = newLoc
+                        symTable[newLoc] = str
+            else:
+                samples = thread['samples']
+                for sample in thread['samples']:
+                    for frame in sample['frames']:
+                        if "location" in frame and frame['location'][0:2] == '0x':
+                            oldLoc = frame['location']
+                            newLoc = pidStr + oldLoc
+                            frame['location'] = newLoc
+                            # Default to the unprefixed symbol if no translation is
+                            symTable[newLoc] = oldLoc
 
         filesyms = fileData['symbolicationTable']
         for sym in filesyms.keys():
             symTable[pidStr + sym] = filesyms[sym]
 
     # For each thread, make the time offsets line up based on the
     # earliest start
     for thread in threads:
         delta = thread['startTime'] - minStartTime
-        for sample in thread['samples']:
-            if "time" in sample:
-                sample['time'] += delta
-        for marker in thread['markers']:
-            marker['time'] += delta
+        if meta['version'] >= 3:
+            idxTime = thread['samples']['schema']['time']
+            for sample in thread['samples']['data']:
+                sample[idxTime] += delta
+            idxTime = thread['markers']['schema']['time']
+            for marker in thread['markers']['data']:
+                marker[idxTime] += delta
+        else:
+            for sample in thread['samples']:
+                if "time" in sample:
+                    sample['time'] += delta
+            for marker in thread['markers']:
+                marker['time'] += delta
 
     result = dict()
     result['profileJSON'] = dict()
     result['profileJSON']['meta'] = meta
     result['profileJSON']['libs'] = libs
     result['profileJSON']['threads'] = threads
     result['symbolicationTable'] = symTable
     result['format'] = "profileJSONWithSymbolicationTable,1"