• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2023 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License a
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from python.generators.diff_tests.testing import Path, DataPath, Metric
17from python.generators.diff_tests.testing import Csv, Json, TextProto
18from python.generators.diff_tests.testing import DiffTestBlueprint
19from python.generators.diff_tests.testing import TestSuite
20
21
22class ChromeMemorySnapshots(TestSuite):
23
24  def test_memory_snapshot_general_validation(self):
25    return DiffTestBlueprint(
26        trace=DataPath('chrome_memory_snapshot.pftrace'),
27        query="""
28        SELECT
29          (
30            SELECT COUNT(*) FROM memory_snapshot
31          ) AS total_snapshots,
32          (
33            SELECT COUNT(*) FROM process
34          ) AS total_processes,
35          (
36            SELECT COUNT(*) FROM process_memory_snapshot
37          ) AS total_process_snapshots,
38          (
39            SELECT COUNT(*) FROM memory_snapshot_node
40          ) AS total_nodes,
41          (
42            SELECT COUNT(*) FROM memory_snapshot_edge
43          ) AS total_edges,
44          (
45            SELECT COUNT(DISTINCT args.id)
46            FROM args
47            JOIN memory_snapshot_node
48              ON args.arg_set_id = memory_snapshot_node.arg_set_id
49          ) AS total_node_args,
50          (
51            SELECT COUNT(*) FROM profiler_smaps
52            JOIN memory_snapshot ON timestamp = ts
53          ) AS total_smaps;
54        """,
55        out=Path('memory_snapshot_general_validation.out'))
56
57  def test_memory_snapshot_os_dump_events(self):
58    return DiffTestBlueprint(
59        trace=DataPath('chrome_memory_snapshot.pftrace'),
60        query=Path('memory_snapshot_os_dump_events_test.sql'),
61        out=Path('memory_snapshot_os_dump_events.out'))
62
63  def test_memory_snapshot_chrome_dump_events(self):
64    return DiffTestBlueprint(
65        trace=DataPath('chrome_memory_snapshot.pftrace'),
66        query="""
67        SELECT
68          pms.id AS process_snapshot_id,
69          upid,
70          snapshot_id,
71          timestamp,
72          detail_level
73        FROM memory_snapshot ms
74        LEFT JOIN process_memory_snapshot pms
75          ON ms.id = pms.snapshot_id;
76        """,
77        out=Path('memory_snapshot_chrome_dump_events.out'))
78
79  def test_memory_snapshot_nodes(self):
80    return DiffTestBlueprint(
81        trace=DataPath('chrome_memory_snapshot.pftrace'),
82        query="""
83        SELECT
84          id,
85          process_snapshot_id,
86          parent_node_id,
87          path,
88          size,
89          effective_size
90        FROM memory_snapshot_node
91        LIMIT 20;
92        """,
93        out=Path('memory_snapshot_nodes.out'))
94
95  def test_memory_snapshot_edges(self):
96    return DiffTestBlueprint(
97        trace=DataPath('chrome_memory_snapshot.pftrace'),
98        query="""
99        SELECT
100          id,
101          source_node_id,
102          target_node_id,
103          importance
104        FROM memory_snapshot_edge
105        LIMIT 20;
106        """,
107        out=Path('memory_snapshot_edges.out'))
108
109  def test_memory_snapshot_node_args(self):
110    return DiffTestBlueprint(
111        trace=DataPath('chrome_memory_snapshot.pftrace'),
112        query="""
113        SELECT
114          node.id AS node_id,
115          key,
116          value_type,
117          int_value,
118          string_value
119        FROM memory_snapshot_node node
120        JOIN args ON node.arg_set_id = args.arg_set_id
121        LIMIT 20;
122        """,
123        out=Path('memory_snapshot_node_args.out'))
124
125  def test_memory_snapshot_smaps(self):
126    return DiffTestBlueprint(
127        trace=DataPath('chrome_memory_snapshot.pftrace'),
128        query="""
129        SELECT
130          process.upid,
131          process.name,
132          smap.ts,
133          path,
134          size_kb,
135          private_dirty_kb,
136          swap_kb,
137          file_name,
138          start_address,
139          module_timestamp,
140          module_debugid,
141          module_debug_path,
142          protection_flags,
143          private_clean_resident_kb,
144          shared_dirty_resident_kb,
145          shared_clean_resident_kb,
146          locked_kb,
147          proportional_resident_kb
148        FROM process
149        JOIN profiler_smaps smap ON process.upid = smap.upid
150        JOIN memory_snapshot ms ON ms.timestamp = smap.ts
151        LIMIT 20;
152        """,
153        out=Path('memory_snapshot_smaps.out'))
154