• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 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 
17 #include "src/trace_processor/importers/proto/winscope/shell_transitions_parser.h"
18 #include "src/trace_processor/importers/proto/winscope/shell_transitions_tracker.h"
19 
20 #include "protos/perfetto/trace/android/shell_transition.pbzero.h"
21 #include "src/trace_processor/importers/common/args_tracker.h"
22 #include "src/trace_processor/importers/proto/args_parser.h"
23 #include "src/trace_processor/importers/proto/winscope/winscope.descriptor.h"
24 #include "src/trace_processor/storage/trace_storage.h"
25 #include "src/trace_processor/types/trace_processor_context.h"
26 
27 namespace perfetto {
28 namespace trace_processor {
29 
ShellTransitionsParser(TraceProcessorContext * context)30 ShellTransitionsParser::ShellTransitionsParser(TraceProcessorContext* context)
31     : context_(context), args_parser_{pool_} {
32   pool_.AddFromFileDescriptorSet(kWinscopeDescriptor.data(),
33                                  kWinscopeDescriptor.size());
34 }
35 
ParseTransition(protozero::ConstBytes blob)36 void ShellTransitionsParser::ParseTransition(protozero::ConstBytes blob) {
37   protos::pbzero::ShellTransition::Decoder transition(blob);
38 
39   auto row_id =
40       ShellTransitionsTracker::GetOrCreate(context_)->InternTransition(
41           transition.id());
42 
43   auto* window_manager_shell_transitions_table =
44       context_->storage->mutable_window_manager_shell_transitions_table();
45   auto row = window_manager_shell_transitions_table->FindById(row_id).value();
46 
47   if (transition.has_dispatch_time_ns()) {
48     row.set_ts(transition.dispatch_time_ns());
49   }
50 
51   auto inserter = context_->args_tracker->AddArgsTo(row_id);
52   ArgsParser writer(/*timestamp=*/0, inserter, *context_->storage.get());
53   base::Status status = args_parser_.ParseMessage(
54       blob, kShellTransitionsProtoName, nullptr /* parse all fields */, writer);
55 
56   if (!status.ok()) {
57     context_->storage->IncrementStats(
58         stats::winscope_shell_transitions_parse_errors);
59   }
60 }
61 
ParseHandlerMappings(protozero::ConstBytes blob)62 void ShellTransitionsParser::ParseHandlerMappings(protozero::ConstBytes blob) {
63   auto* shell_handlers_table =
64       context_->storage
65           ->mutable_window_manager_shell_transition_handlers_table();
66 
67   protos::pbzero::ShellHandlerMappings::Decoder handler_mappings(blob);
68   for (auto it = handler_mappings.mapping(); it; ++it) {
69     protos::pbzero::ShellHandlerMapping::Decoder mapping(it.field().as_bytes());
70 
71     tables::WindowManagerShellTransitionHandlersTable::Row row;
72     row.handler_id = mapping.id();
73     row.handler_name = context_->storage->InternString(
74         base::StringView(mapping.name().ToStdString()));
75     shell_handlers_table->Insert(row);
76   }
77 }
78 
79 }  // namespace trace_processor
80 }  // namespace perfetto
81