• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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  *      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  */
16 #include "src/trace_processor/importers/proto/translation_table_module.h"
17 
18 #include "src/trace_processor/importers/common/args_translation_table.h"
19 #include "src/trace_processor/importers/common/process_track_translation_table.h"
20 #include "src/trace_processor/importers/common/slice_translation_table.h"
21 #include "src/trace_processor/importers/proto/packet_sequence_state_generation.h"
22 
23 #include "protos/perfetto/trace/trace_packet.pbzero.h"
24 #include "protos/perfetto/trace/translation/translation_table.pbzero.h"
25 
26 namespace perfetto {
27 namespace trace_processor {
28 
29 using perfetto::protos::pbzero::TracePacket;
30 
TranslationTableModule(TraceProcessorContext * context)31 TranslationTableModule::TranslationTableModule(TraceProcessorContext* context)
32     : context_(context) {
33   RegisterForField(TracePacket::kTranslationTableFieldNumber, context);
34 }
35 
36 TranslationTableModule::~TranslationTableModule() = default;
37 
TokenizePacket(const protos::pbzero::TracePacket_Decoder & decoder,TraceBlobView *,int64_t,RefPtr<PacketSequenceStateGeneration>,uint32_t field_id)38 ModuleResult TranslationTableModule::TokenizePacket(
39     const protos::pbzero::TracePacket_Decoder& decoder,
40     TraceBlobView* /*packet*/,
41     int64_t /*packet_timestamp*/,
42     RefPtr<PacketSequenceStateGeneration> /*state*/,
43     uint32_t field_id) {
44   if (field_id != TracePacket::kTranslationTableFieldNumber) {
45     return ModuleResult::Ignored();
46   }
47   const auto translation_table =
48       protos::pbzero::TranslationTable::Decoder(decoder.translation_table());
49   if (translation_table.has_chrome_histogram()) {
50     ParseChromeHistogramRules(translation_table.chrome_histogram());
51   } else if (translation_table.has_chrome_user_event()) {
52     ParseChromeUserEventRules(translation_table.chrome_user_event());
53   } else if (translation_table.has_chrome_performance_mark()) {
54     ParseChromePerformanceMarkRules(
55         translation_table.chrome_performance_mark());
56   } else if (translation_table.has_slice_name()) {
57     ParseSliceNameRules(translation_table.slice_name());
58   } else if (translation_table.has_process_track_name()) {
59     ParseProcessTrackNameRules(translation_table.process_track_name());
60   }
61   return ModuleResult::Handled();
62 }
63 
ParseChromeHistogramRules(protozero::ConstBytes bytes)64 void TranslationTableModule::ParseChromeHistogramRules(
65     protozero::ConstBytes bytes) {
66   const auto chrome_histogram =
67       protos::pbzero::ChromeHistorgramTranslationTable::Decoder(bytes);
68   for (auto it = chrome_histogram.hash_to_name(); it; ++it) {
69     protos::pbzero::ChromeHistorgramTranslationTable::HashToNameEntry::Decoder
70         entry(*it);
71     context_->args_translation_table->AddChromeHistogramTranslationRule(
72         entry.key(), entry.value());
73   }
74 }
75 
ParseChromeUserEventRules(protozero::ConstBytes bytes)76 void TranslationTableModule::ParseChromeUserEventRules(
77     protozero::ConstBytes bytes) {
78   const auto chrome_user_event =
79       protos::pbzero::ChromeUserEventTranslationTable::Decoder(bytes);
80   for (auto it = chrome_user_event.action_hash_to_name(); it; ++it) {
81     protos::pbzero::ChromeUserEventTranslationTable::ActionHashToNameEntry::
82         Decoder entry(*it);
83     context_->args_translation_table->AddChromeUserEventTranslationRule(
84         entry.key(), entry.value());
85   }
86 }
87 
ParseChromePerformanceMarkRules(protozero::ConstBytes bytes)88 void TranslationTableModule::ParseChromePerformanceMarkRules(
89     protozero::ConstBytes bytes) {
90   const auto chrome_performance_mark =
91       protos::pbzero::ChromePerformanceMarkTranslationTable::Decoder(bytes);
92   for (auto it = chrome_performance_mark.site_hash_to_name(); it; ++it) {
93     protos::pbzero::ChromePerformanceMarkTranslationTable::SiteHashToNameEntry::
94         Decoder entry(*it);
95     context_->args_translation_table
96         ->AddChromePerformanceMarkSiteTranslationRule(entry.key(),
97                                                       entry.value());
98   }
99   for (auto it = chrome_performance_mark.mark_hash_to_name(); it; ++it) {
100     protos::pbzero::ChromePerformanceMarkTranslationTable::MarkHashToNameEntry::
101         Decoder entry(*it);
102     context_->args_translation_table
103         ->AddChromePerformanceMarkMarkTranslationRule(entry.key(),
104                                                       entry.value());
105   }
106 }
107 
ParseSliceNameRules(protozero::ConstBytes bytes)108 void TranslationTableModule::ParseSliceNameRules(protozero::ConstBytes bytes) {
109   const auto slice_name =
110       protos::pbzero::SliceNameTranslationTable::Decoder(bytes);
111   for (auto it = slice_name.raw_to_deobfuscated_name(); it; ++it) {
112     protos::pbzero::SliceNameTranslationTable::RawToDeobfuscatedNameEntry::
113         Decoder entry(*it);
114     context_->slice_translation_table->AddNameTranslationRule(entry.key(),
115                                                               entry.value());
116   }
117 }
118 
ParseProcessTrackNameRules(protozero::ConstBytes bytes)119 void TranslationTableModule::ParseProcessTrackNameRules(
120     protozero::ConstBytes bytes) {
121   const auto process_track_name =
122       protos::pbzero::ProcessTrackNameTranslationTable::Decoder(bytes);
123   for (auto it = process_track_name.raw_to_deobfuscated_name(); it; ++it) {
124     protos::pbzero::ProcessTrackNameTranslationTable::
125         RawToDeobfuscatedNameEntry::Decoder entry(*it);
126     context_->process_track_translation_table->AddNameTranslationRule(
127         entry.key(), entry.value());
128   }
129 }
130 
131 }  // namespace trace_processor
132 }  // namespace perfetto
133