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_VULKAN_MEMORY_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_VULKAN_MEMORY_TRACKER_H_ 19 20 #include <cstdint> 21 #include <vector> 22 23 #include "perfetto/ext/base/string_view.h" 24 #include "src/trace_processor/importers/proto/packet_sequence_state_generation.h" 25 #include "src/trace_processor/storage/trace_storage.h" 26 #include "src/trace_processor/types/trace_processor_context.h" 27 28 #include "protos/perfetto/trace/gpu/vulkan_memory_event.pbzero.h" 29 #include "protos/perfetto/trace/profiling/profile_common.pbzero.h" 30 31 namespace perfetto::trace_processor { 32 33 class VulkanMemoryTracker { 34 public: 35 using VulkanMemoryEvent = protos::pbzero::VulkanMemoryEvent; 36 37 explicit VulkanMemoryTracker(TraceProcessorContext* context); 38 39 template <int32_t FieldId> GetInternedString(PacketSequenceStateGeneration * state,uint64_t iid)40 StringId GetInternedString(PacketSequenceStateGeneration* state, 41 uint64_t iid) { 42 auto* decoder = 43 state->LookupInternedMessage<FieldId, protos::pbzero::InternedString>( 44 iid); 45 if (!decoder) 46 return kNullStringId; 47 return context_->storage->InternString( 48 base::StringView(reinterpret_cast<const char*>(decoder->str().data), 49 decoder->str().size)); 50 } 51 52 StringId FindSourceString(VulkanMemoryEvent::Source); 53 StringId FindOperationString(VulkanMemoryEvent::Operation); 54 StringId FindAllocationScopeString(VulkanMemoryEvent::AllocationScope); 55 56 private: 57 TraceProcessorContext* const context_; 58 59 std::vector<StringId> source_strs_id_; 60 std::vector<StringId> operation_strs_id_; 61 std::vector<StringId> scope_strs_id_; 62 }; 63 64 } // namespace perfetto::trace_processor 65 66 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_VULKAN_MEMORY_TRACKER_H_ 67