Eric Seckler | ab0604c | 2019-10-25 10:12:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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_ANDROID_PROBES_MODULE_H_ |
| 18 | #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_ANDROID_PROBES_MODULE_H_ |
| 19 | |
| 20 | #include "perfetto/base/build_config.h" |
| 21 | #include "src/trace_processor/importers/proto/android_probes_parser.h" |
| 22 | #include "src/trace_processor/importers/proto/proto_importer_module.h" |
| 23 | #include "src/trace_processor/timestamped_trace_piece.h" |
| 24 | |
Eric Seckler | d2af989 | 2019-11-01 10:10:53 +0000 | [diff] [blame] | 25 | #include "protos/perfetto/config/trace_config.pbzero.h" |
| 26 | #include "protos/perfetto/trace/trace_packet.pbzero.h" |
| 27 | |
Eric Seckler | ab0604c | 2019-10-25 10:12:07 +0100 | [diff] [blame] | 28 | namespace perfetto { |
| 29 | namespace trace_processor { |
| 30 | |
| 31 | class AndroidProbesModule : public ProtoImporterModuleBase<PERFETTO_BUILDFLAG( |
| 32 | PERFETTO_TP_ANDROID_PROBES)> { |
| 33 | public: |
| 34 | explicit AndroidProbesModule(TraceProcessorContext* context) |
| 35 | : ProtoImporterModuleBase(context), parser_(context) {} |
| 36 | |
| 37 | ModuleResult ParsePacket(const protos::pbzero::TracePacket::Decoder& decoder, |
| 38 | const TimestampedTracePiece& ttp) { |
| 39 | if (decoder.has_battery()) { |
| 40 | parser_.ParseBatteryCounters(ttp.timestamp, decoder.battery()); |
| 41 | return ModuleResult::Handled(); |
| 42 | } |
| 43 | |
| 44 | if (decoder.has_power_rails()) { |
| 45 | parser_.ParsePowerRails(ttp.timestamp, decoder.power_rails()); |
| 46 | return ModuleResult::Handled(); |
| 47 | } |
| 48 | |
| 49 | if (decoder.has_android_log()) { |
| 50 | parser_.ParseAndroidLogPacket(decoder.android_log()); |
| 51 | return ModuleResult::Handled(); |
| 52 | } |
| 53 | |
| 54 | if (decoder.has_packages_list()) { |
| 55 | parser_.ParseAndroidPackagesList(decoder.packages_list()); |
| 56 | return ModuleResult::Handled(); |
| 57 | } |
| 58 | |
| 59 | return ModuleResult::Ignored(); |
| 60 | } |
| 61 | |
| 62 | ModuleResult ParseTraceConfig( |
| 63 | const protos::pbzero::TraceConfig::Decoder& decoder) { |
| 64 | if (decoder.has_statsd_metadata()) { |
| 65 | parser_.ParseStatsdMetadata(decoder.statsd_metadata()); |
| 66 | return ModuleResult::Handled(); |
| 67 | } |
| 68 | return ModuleResult::Ignored(); |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | AndroidProbesParser parser_; |
| 73 | }; |
| 74 | |
| 75 | } // namespace trace_processor |
| 76 | } // namespace perfetto |
| 77 | |
| 78 | #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_ANDROID_PROBES_MODULE_H_ |