• 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/surfaceflinger_transactions_parser.h"
18 
19 #include "perfetto/ext/base/base64.h"
20 #include "protos/perfetto/trace/android/surfaceflinger_transactions.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/storage/trace_storage.h"
24 #include "src/trace_processor/types/trace_processor_context.h"
25 #include "src/trace_processor/util/winscope_proto_mapping.h"
26 
27 namespace perfetto {
28 namespace trace_processor {
29 
SurfaceFlingerTransactionsParser(TraceProcessorContext * context)30 SurfaceFlingerTransactionsParser::SurfaceFlingerTransactionsParser(
31     TraceProcessorContext* context)
32     : context_{context}, args_parser_{*context->descriptor_pool_} {}
33 
Parse(int64_t timestamp,protozero::ConstBytes blob)34 void SurfaceFlingerTransactionsParser::Parse(int64_t timestamp,
35                                              protozero::ConstBytes blob) {
36   tables::SurfaceFlingerTransactionsTable::Row row;
37   row.ts = timestamp;
38   row.base64_proto_id = context_->storage->mutable_string_pool()
39                             ->InternString(base::StringView(
40                                 base::Base64Encode(blob.data, blob.size)))
41                             .raw_id();
42   auto rowId = context_->storage->mutable_surfaceflinger_transactions_table()
43                    ->Insert(row)
44                    .id;
45 
46   ArgsTracker tracker(context_);
47   auto inserter = tracker.AddArgsTo(rowId);
48   ArgsParser writer(timestamp, inserter, *context_->storage.get());
49   base::Status status = args_parser_.ParseMessage(
50       blob,
51       *util::winscope_proto_mapping::GetProtoName(
52           tables::SurfaceFlingerTransactionsTable::Name()),
53       nullptr /* parse all fields */, writer);
54   if (!status.ok()) {
55     context_->storage->IncrementStats(
56         stats::winscope_sf_transactions_parse_errors);
57   }
58 }
59 
60 }  // namespace trace_processor
61 }  // namespace perfetto
62