• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2019 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 at
7--
8--     https://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--
16
17-- On Linux/Android perfetto profilers (heapprofd, traced_perf) record the
18-- .note.gnu.build-id as build_id. Within Google, this can be used as a lookup
19-- key for most cases, but not for Chrome/Webview. Chrome is special and stores
20-- symbols indexed by "breadkpad module ID". Breakpad module ID can be derived
21-- with the following formula:
22--      base::StrCat({module_id->substr(6, 2), module_id->substr(4, 2),
23--                    module_id->substr(2, 2), module_id->substr(0, 2),
24--                    module_id->substr(10, 2), module_id->substr(8, 2),
25--                    module_id->substr(14, 2), module_id->substr(12, 2),
26--                    module_id->substr(16, 16), "0"});
27-- See also https://source.chromium.org/chromium/chromium/src/+/main:services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.cc;l=603;drc=cba00174ca338153b9c4f0c31ddbabaac7dd38c7
28-- Note that in SQL SUBSTR() indexes are 1-based, not 0 based.
29DROP VIEW IF EXISTS mangled_stack_profile_mapping;
30CREATE VIEW mangled_stack_profile_mapping AS
31SELECT
32  id,
33  name,
34  build_id,
35  CASE ((name GLOB '*libmonochrome_64.so'
36    OR name GLOB '*libchrome.so'
37    OR name GLOB '*libmonochrome.so'
38    OR name GLOB '*libwebviewchromium.so'
39    OR name GLOB '*libchromium_android_linker.so'
40  ) AND length(build_id) >= 40)
41  WHEN 0 THEN build_id
42  ELSE (
43    SUBSTR(build_id, 7, 2)
44    || SUBSTR(build_id, 5, 2)
45    || SUBSTR(build_id, 3, 2)
46    || SUBSTR(build_id, 1, 2)
47    || SUBSTR(build_id, 11, 2)
48    || SUBSTR(build_id, 9, 2)
49    || SUBSTR(build_id, 15, 2)
50    || SUBSTR(build_id, 13, 2)
51    || SUBSTR(build_id, 17, 16)
52    || '0')
53  END AS google_lookup_id
54FROM stack_profile_mapping;
55
56DROP VIEW IF EXISTS unsymbolized_frames_view;
57CREATE VIEW unsymbolized_frames_view AS
58SELECT UnsymbolizedFrames_Frame(
59    'module', spm.name,
60    'build_id', spm.build_id,
61    'address', spf.rel_pc,
62    'google_lookup_id', spm.google_lookup_id
63) AS frame_proto
64FROM stack_profile_frame spf
65JOIN mangled_stack_profile_mapping spm
66  ON spf.mapping = spm.id
67WHERE spm.build_id != ''
68  AND spf.symbol_set_id IS NULL;
69
70DROP VIEW IF EXISTS unsymbolized_frames_output;
71CREATE VIEW unsymbolized_frames_output AS
72SELECT UnsymbolizedFrames(
73  'frames',
74  (SELECT RepeatedField(frame_proto) FROM unsymbolized_frames_view)
75);
76