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