1 /* 2 * Copyright (C) 2020 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_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_ANDROID_PROBES_TRACKER_H_ 19 20 #include <set> 21 22 #include "perfetto/ext/base/optional.h" 23 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 30 class TraceProcessorContext; 31 32 class AndroidProbesTracker : public Destructible { 33 public: 34 explicit AndroidProbesTracker(TraceProcessorContext*); 35 ~AndroidProbesTracker() override; 36 GetOrCreate(TraceProcessorContext * context)37 static AndroidProbesTracker* GetOrCreate(TraceProcessorContext* context) { 38 if (!context->android_probes_tracker) { 39 context->android_probes_tracker.reset(new AndroidProbesTracker(context)); 40 } 41 return static_cast<AndroidProbesTracker*>( 42 context->android_probes_tracker.get()); 43 } 44 ShouldInsertPackage(const std::string & package_name)45 bool ShouldInsertPackage(const std::string& package_name) const { 46 auto it = seen_packages_.find(package_name); 47 return it == seen_packages_.end(); 48 } 49 InsertedPackage(std::string package_name)50 void InsertedPackage(std::string package_name) { 51 seen_packages_.emplace(std::move(package_name)); 52 } 53 GetPowerRailName(uint32_t index)54 base::Optional<StringId> GetPowerRailName(uint32_t index) { 55 if (index >= power_rails_strs_id_.size()) 56 return base::nullopt; 57 return power_rails_strs_id_[index]; 58 } 59 SetPowerRailName(uint32_t index,StringId name)60 void SetPowerRailName(uint32_t index, StringId name) { 61 if (power_rails_strs_id_.size() <= index) 62 power_rails_strs_id_.resize(index + 1); 63 power_rails_strs_id_[index] = name; 64 } 65 66 private: 67 std::set<std::string> seen_packages_; 68 std::vector<StringId> power_rails_strs_id_; 69 }; 70 71 } // namespace trace_processor 72 } // namespace perfetto 73 74 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_ANDROID_PROBES_TRACKER_H_ 75