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 #include "src/trace_processor/importers/proto/vulkan_memory_tracker.h"
18
19 #include <array>
20 #include <cstddef>
21 #include <vector>
22
23 #include "src/trace_processor/storage/trace_storage.h"
24 #include "src/trace_processor/types/trace_processor_context.h"
25
26 namespace perfetto::trace_processor {
27
VulkanMemoryTracker(TraceProcessorContext * context)28 VulkanMemoryTracker::VulkanMemoryTracker(TraceProcessorContext* context)
29 : context_(context) {
30 static constexpr std::array kEventSources = {
31 "UNSPECIFIED", "DRIVER", "DEVICE",
32 "GPU_DEVICE_MEMORY", "GPU_BUFFER", "GPU_IMAGE",
33 };
34 for (const auto& event_source : kEventSources) {
35 source_strs_id_.emplace_back(context_->storage->InternString(event_source));
36 }
37
38 static constexpr std::array kEventOperations = {
39 "UNSPECIFIED", "CREATE", "DESTROY",
40 "BIND", "DESTROY_BOUND", "ANNOTATIONS",
41 };
42 for (const auto& event_operation : kEventOperations) {
43 operation_strs_id_.emplace_back(
44 context_->storage->InternString(event_operation));
45 }
46
47 static constexpr std::array kEventScopes = {
48 "UNSPECIFIED", "COMMAND", "OBJECT", "CACHE", "DEVICE", "INSTANCE",
49 };
50 for (const auto& event_scope : kEventScopes) {
51 scope_strs_id_.emplace_back(context_->storage->InternString(event_scope));
52 }
53 }
54
FindSourceString(VulkanMemoryEvent::Source source)55 StringId VulkanMemoryTracker::FindSourceString(
56 VulkanMemoryEvent::Source source) {
57 return source_strs_id_[static_cast<size_t>(source)];
58 }
59
FindOperationString(VulkanMemoryEvent::Operation operation)60 StringId VulkanMemoryTracker::FindOperationString(
61 VulkanMemoryEvent::Operation operation) {
62 return operation_strs_id_[static_cast<size_t>(operation)];
63 }
64
FindAllocationScopeString(VulkanMemoryEvent::AllocationScope scope)65 StringId VulkanMemoryTracker::FindAllocationScopeString(
66 VulkanMemoryEvent::AllocationScope scope) {
67 return scope_strs_id_[static_cast<size_t>(scope)];
68 }
69
70 } // namespace perfetto::trace_processor
71