Fix incorrect memory dump indexes update

I miss understood the new memory dump format and the indexes are not
updated correctly. It seems they are by process and not global.

[email protected]
[email protected], [email protected]
BUG=chromium:733056

Review-Url: https://codereview.chromium.org/2969533002
diff --git a/experimental/tracing/bin/diff_heap_profiler.py b/experimental/tracing/bin/diff_heap_profiler.py
index a979913..b2a462e 100644
--- a/experimental/tracing/bin/diff_heap_profiler.py
+++ b/experimental/tracing/bin/diff_heap_profiler.py
@@ -19,8 +19,9 @@
     self.pid = None
     self.name = None
     self.labels = None
-    self.types = None
-    self.stackframes = None
+    self.types = {}
+    self.strings = {}
+    self.stackframes = {}
     self.allocators = None
     self.version = None
 
@@ -53,11 +54,6 @@
   with gzip.open(filename, 'rb') as f:
     data = json.loads(f.read().decode('ascii'))
 
-    # Memory dump format V2 cumulated indexes.
-    nodes = {}
-    types = {}
-    strings = {}
-
     for event in data['traceEvents']:
       pid = event['pid']
       if pid not in processes:
@@ -103,22 +99,20 @@
       # See format: [chromium] src/base/trace_event/heap_profiler_event_writer.h
       if u'heaps_v2' in event['args']['dumps']:
         # Memory dump format V2 is dumping information incrementally. Update
-        # the cumulated indexes
+        # the cumulated indexes.
         maps = event['args']['dumps']['heaps_v2']['maps']
         for string in maps['strings']:
-          strings[string['id']] = string['string']
+          process.strings[string['id']] = string['string']
 
         for node in maps['nodes']:
           node_v1 = {}
-          node_v1['name'] = strings[node['name_sid']]
+          node_v1['name'] = process.strings[node['name_sid']]
           if 'parent' in node:
             node_v1['parent'] = node['parent']
-          nodes[node['id']] = node_v1
-        process.stackframes = nodes
+          process.stackframes[node['id']] = node_v1
 
         for t in maps['types']:
-          types[t['id']] = strings[t['name_sid']]
-        process.types = types
+          process.types[t['id']] = process.strings[t['name_sid']]
 
         # Get the first memory dump.
         if not process.allocators: