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_COMMON_METADATA_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_METADATA_TRACKER_H_ 19 20 #include "src/trace_processor/storage/trace_storage.h" 21 22 namespace perfetto { 23 namespace trace_processor { 24 25 // Tracks information in the metadata table. 26 class MetadataTracker { 27 public: 28 MetadataTracker(TraceStorage* storage); 29 30 // Example usage: 31 // SetMetadata(metadata::benchmark_name, 32 // Variadic::String(storage->InternString("foo")); 33 // Returns the id of the new entry. 34 MetadataId SetMetadata(metadata::KeyId key, Variadic value); 35 36 // Example usage: 37 // AppendMetadata(metadata::benchmark_story_tags, 38 // Variadic::String(storage->InternString("bar")); 39 // Returns the id of the new entry. 40 MetadataId AppendMetadata(metadata::KeyId key, Variadic value); 41 42 // Sets a metadata entry using any interned string as key. 43 // Returns the id of the new entry. 44 MetadataId SetDynamicMetadata(StringId key, Variadic value); 45 46 // Reads back a set metadata value. 47 // Only kSingle types are supported right now. 48 SqlValue GetMetadata(metadata::KeyId key); 49 50 // Tracks how many ChromeMetadata bundles have been parsed. IncrementChromeMetadataBundleCount()51 uint32_t IncrementChromeMetadataBundleCount() { 52 return ++chrome_metadata_bundle_count_; 53 } 54 55 private: 56 static constexpr size_t kNumKeys = 57 static_cast<size_t>(metadata::KeyId::kNumKeys); 58 static constexpr size_t kNumKeyTypes = 59 static_cast<size_t>(metadata::KeyType::kNumKeyTypes); 60 61 void WriteValue(uint32_t row, Variadic value); 62 63 std::array<StringId, kNumKeys> key_ids_; 64 std::array<StringId, kNumKeyTypes> key_type_ids_; 65 uint32_t chrome_metadata_bundle_count_ = 0; 66 67 TraceStorage* storage_; 68 }; 69 70 } // namespace trace_processor 71 } // namespace perfetto 72 73 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_METADATA_TRACKER_H_ 74