Merge "ui: Fix nesting of slice argument table"
diff --git a/src/trace_processor/importers/ftrace/ftrace_descriptors.cc b/src/trace_processor/importers/ftrace/ftrace_descriptors.cc
index ec65058..9aae8c0 100644
--- a/src/trace_processor/importers/ftrace/ftrace_descriptors.cc
+++ b/src/trace_processor/importers/ftrace/ftrace_descriptors.cc
@@ -24,7 +24,7 @@
 namespace trace_processor {
 namespace {
 
-std::array<MessageDescriptor, 335> descriptors{{
+std::array<MessageDescriptor, 336> descriptors{{
     {nullptr, 0, {}},
     {nullptr, 0, {}},
     {nullptr, 0, {}},
@@ -3575,6 +3575,16 @@
             {"pid", ProtoSchemaType::kInt32},
         },
     },
+    {
+        "ion_stat",
+        3,
+        {
+            {},
+            {"buffer_id", ProtoSchemaType::kUint32},
+            {"len", ProtoSchemaType::kInt64},
+            {"total_allocated", ProtoSchemaType::kUint64},
+        },
+    },
 }};
 
 }  // namespace
diff --git a/src/trace_processor/metrics/android/android_ion.sql b/src/trace_processor/metrics/android/android_ion.sql
index 98a6fc9..b2a72fe 100644
--- a/src/trace_processor/metrics/android/android_ion.sql
+++ b/src/trace_processor/metrics/android/android_ion.sql
@@ -19,12 +19,15 @@
   ts,
   LEAD(ts, 1, (SELECT end_ts FROM trace_bounds))
     OVER(PARTITION BY track_id ORDER BY ts) - ts AS dur,
-  SUBSTR(name, 9) AS heap_name,
+  CASE name
+    WHEN 'mem.ion' THEN 'all'
+    ELSE SUBSTR(name, 9)
+  END AS heap_name,
   track_id,
   value
 FROM counter JOIN counter_track
   ON counter.track_id = counter_track.id
-WHERE name LIKE 'mem.ion.%';
+WHERE (name LIKE 'mem.ion.%' OR name = 'mem.ion');
 
 CREATE VIEW IF NOT EXISTS ion_heap_stats AS
 SELECT
@@ -37,14 +40,17 @@
 
 CREATE VIEW IF NOT EXISTS ion_raw_allocs AS
 SELECT
-  SUBSTR(name, 16) AS heap_name,
+  CASE name
+    WHEN 'mem.ion_change' THEN 'all'
+    ELSE SUBSTR(name, 16)
+  END AS heap_name,
   ts,
   value AS instant_value,
   SUM(value) OVER win AS value
 FROM counter c JOIN thread_counter_track t ON c.track_id = t.id
-WHERE name LIKE 'mem.ion_change.%' AND value > 0
+WHERE (name LIKE 'mem.ion_change.%' OR name = 'mem.ion_change') AND value > 0
 WINDOW win AS (
-  PARTITION BY SUBSTR(name, 16) ORDER BY ts
+  PARTITION BY name ORDER BY ts
   ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
 );
 
diff --git a/test/metrics/android_ion_stat.out b/test/metrics/android_ion_stat.out
new file mode 100644
index 0000000..f9ac727
--- /dev/null
+++ b/test/metrics/android_ion_stat.out
@@ -0,0 +1,9 @@
+android_ion {
+  buffer {
+    name: "all"
+    avg_size_bytes: 2000.0
+    min_size_bytes: 1000.0
+    max_size_bytes: 2000.0
+    total_alloc_size_bytes: 1000.0
+  }
+}
\ No newline at end of file
diff --git a/test/metrics/android_ion_stat.textproto b/test/metrics/android_ion_stat.textproto
new file mode 100644
index 0000000..e573712
--- /dev/null
+++ b/test/metrics/android_ion_stat.textproto
@@ -0,0 +1,28 @@
+packet {
+  ftrace_events {
+    cpu: 0
+    event {
+      timestamp: 100
+      pid: 1
+      ion_stat {
+        buffer_id: 123
+        len: 1000
+        total_allocated: 2000
+      }
+    }
+  }
+}
+packet {
+  ftrace_events {
+    cpu: 0
+    event {
+      timestamp: 200
+      pid: 1
+      ion_stat {
+        buffer_id: 123
+        len: -1000
+        total_allocated: 1000
+      }
+    }
+  }
+}
diff --git a/test/metrics/index b/test/metrics/index
index 5483ba4..3dcc53f 100644
--- a/test/metrics/index
+++ b/test/metrics/index
@@ -9,6 +9,7 @@
 ../trace_processor/oom_kill.textproto android_lmk android_lmk_oom.out
 
 android_ion.py android_ion android_ion.out
+android_ion_stat.textproto android_ion android_ion_stat.out
 
 android_startup.py android_startup android_startup.out
 android_startup_breakdown.py android_startup android_startup_breakdown.out
diff --git a/tools/heap_profile b/tools/heap_profile
index f2aaf0f..a969de4 100755
--- a/tools/heap_profile
+++ b/tools/heap_profile
@@ -30,12 +30,6 @@
 import time
 import uuid
 
-try:
-    # Python 2.x
-    from urllib import urlretrieve
-except ImportError:
-    # Python 3.x
-    from urllib.request import urlretrieve
 
 TRACE_TO_TEXT_SHAS = {
     'linux': 'aba0e660818bfc249992ebbceb13a2e4c9a62c3a',
@@ -71,7 +65,7 @@
       return local_file
 
   url = TRACE_TO_TEXT_BASE_URL + file_name
-  urlretrieve(url, local_file)
+  subprocess.check_call(['curl', '-#', '-o', local_file, url])
   if not check_hash(local_file, sha_value):
     os.remove(local_file)
     raise ValueError("Invalid signature.")
diff --git a/tools/install-build-deps b/tools/install-build-deps
index b189463..7bd693c 100755
--- a/tools/install-build-deps
+++ b/tools/install-build-deps
@@ -26,7 +26,6 @@
 from collections import namedtuple
 from platform import system
 
-from compat import urlretrieve
 
 # The format for the deps below is the following:
 # (target_folder, source_url, sha1, target_platform)
@@ -232,6 +231,10 @@
 NODE_MODULES_STATUS_FILE = os.path.join(UI_DIR, 'node_modules', '.last_install')
 
 
+def DownloadURL(url, out_file):
+  subprocess.check_call(['curl', '-#', '-o', out_file, url])
+
+
 def ReadFile(path):
   if not os.path.exists(path):
     return None
@@ -315,7 +318,7 @@
       logging.info('Downloading %s from %s', rel_path, url)
       with tempfile.NamedTemporaryFile(delete=False) as f:
         f.close()
-        urlretrieve(url, f.name)
+        DownloadURL(url, f.name)
         actual_sha1 = HashLocalFile(f.name)
         os.unlink(f.name)
         if (actual_sha1 != expected_sha1):
@@ -361,7 +364,7 @@
     if HashLocalFile(local_path) != expected_sha1:
       download_path = local_path + '.tmp'
       logging.info('Downloading %s from %s', local_path, url)
-      urlretrieve(url, download_path)
+      DownloadURL(url, download_path)
       os.chmod(download_path, 0o755)
       actual_sha1 = HashLocalFile(download_path)
       if (actual_sha1 != expected_sha1):