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 17 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_CONTENT_ANALYZER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_CONTENT_ANALYZER_H_ 19 20 #include <utility> 21 #include <vector> 22 23 #include "perfetto/ext/base/flat_hash_map.h" 24 #include "perfetto/trace_processor/trace_blob_view.h" 25 #include "src/trace_processor/importers/proto/packet_analyzer.h" 26 #include "src/trace_processor/storage/trace_storage.h" 27 #include "src/trace_processor/types/trace_processor_context.h" 28 #include "src/trace_processor/util/proto_profiler.h" 29 30 namespace perfetto { 31 namespace trace_processor { 32 33 // Interface for a module that processes track event information. 34 class ProtoContentAnalyzer : public PacketAnalyzer { 35 public: 36 struct Sample { 37 size_t size; 38 size_t count; 39 }; 40 using PathToSamplesMap = 41 base::FlatHashMap<util::SizeProfileComputer::FieldPath, 42 Sample, 43 util::SizeProfileComputer::FieldPathHasher>; 44 using SampleAnnotation = PacketAnalyzer::SampleAnnotation; 45 46 struct SampleAnnotationHasher { 47 using argument_type = SampleAnnotation; 48 using result_type = size_t; 49 operatorSampleAnnotationHasher50 result_type operator()(const argument_type& p) const { 51 base::Hasher hash; 52 for (auto v : p) { 53 hash.Update(v.first.raw_id()); 54 hash.Update(v.second.raw_id()); 55 } 56 return static_cast<size_t>(hash.digest()); 57 } 58 }; 59 using AnnotatedSamplesMap = base:: 60 FlatHashMap<SampleAnnotation, PathToSamplesMap, SampleAnnotationHasher>; 61 62 ProtoContentAnalyzer(TraceProcessorContext* context); 63 ~ProtoContentAnalyzer() override; 64 65 void ProcessPacket(const TraceBlobView& packet, 66 const SampleAnnotation& annotation) override; 67 68 void NotifyEndOfFile() override; 69 70 private: 71 TraceProcessorContext* context_; 72 DescriptorPool pool_; 73 util::SizeProfileComputer computer_; 74 AnnotatedSamplesMap aggregated_samples_; 75 }; 76 77 } // namespace trace_processor 78 } // namespace perfetto 79 80 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_CONTENT_ANALYZER_H_ 81