• 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 "protos/perfetto/trace/android/surfaceflinger_transactions.pbzero.h"
20 #include "src/trace_processor/importers/common/args_tracker.h"
21 #include "src/trace_processor/importers/proto/args_parser.h"
22 #include "src/trace_processor/importers/proto/winscope/winscope.descriptor.h"
23 #include "src/trace_processor/storage/trace_storage.h"
24 #include "src/trace_processor/types/trace_processor_context.h"
25 
26 namespace perfetto {
27 namespace trace_processor {
28 
SurfaceFlingerTransactionsParser(TraceProcessorContext * context)29 SurfaceFlingerTransactionsParser::SurfaceFlingerTransactionsParser(
30     TraceProcessorContext* context)
31     : context_{context}, args_parser_{pool_} {
32   pool_.AddFromFileDescriptorSet(kWinscopeDescriptor.data(),
33                                  kWinscopeDescriptor.size());
34 }
35 
Parse(int64_t timestamp,protozero::ConstBytes blob)36 void SurfaceFlingerTransactionsParser::Parse(int64_t timestamp,
37                                              protozero::ConstBytes blob) {
38   tables::SurfaceFlingerTransactionsTable::Row row;
39   row.ts = timestamp;
40   auto rowId = context_->storage->mutable_surfaceflinger_transactions_table()
41                    ->Insert(row)
42                    .id;
43 
44   ArgsTracker tracker(context_);
45   auto inserter = tracker.AddArgsTo(rowId);
46   ArgsParser writer(timestamp, inserter, *context_->storage.get());
47   base::Status status =
48       args_parser_.ParseMessage(blob, kTransactionTraceEntryProtoName,
49                                 nullptr /* parse all fields */, writer);
50   if (!status.ok()) {
51     context_->storage->IncrementStats(
52         stats::winscope_sf_transactions_parse_errors);
53   }
54 }
55 
56 }  // namespace trace_processor
57 }  // namespace perfetto
58