1 // Copyright (C) 2024 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Simple wrapper around Perfetto tracing that allows for building 16 // without tracing. 17 18 #pragma once 19 20 #include <stdint.h> 21 22 #define GFXSTREAM_TRACE_DEFAULT_CATEGORY "gfxstream.default" 23 #define GFXSTREAM_TRACE_DECODER_CATEGORY "gfxstream.decoder" 24 #define GFXSTREAM_TRACE_STREAM_RENDERER_CATEGORY "gfxstream.stream_renderer" 25 #define GFXSTREAM_TRACE_VIRTIO_GPU_TIMELINE_CATEGORY "gfxstream.virtio_gpu_timeline" 26 27 #ifdef GFXSTREAM_BUILD_WITH_TRACING 28 29 #ifdef GFXSTREAM_BUILD_WITH_PERFETTO_SDK 30 #include <perfetto.h> 31 #else 32 #include <perfetto/tracing.h> 33 #endif 34 35 PERFETTO_DEFINE_CATEGORIES(perfetto::Category(GFXSTREAM_TRACE_DEFAULT_CATEGORY) 36 .SetDescription("Default events") 37 .SetTags("default"), 38 perfetto::Category(GFXSTREAM_TRACE_DECODER_CATEGORY) 39 .SetDescription("Decoder events") 40 .SetTags("decoder"), 41 perfetto::Category(GFXSTREAM_TRACE_STREAM_RENDERER_CATEGORY) 42 .SetDescription("Gfxstream frontend command events") 43 .SetTags("stream-renderer"), 44 perfetto::Category(GFXSTREAM_TRACE_VIRTIO_GPU_TIMELINE_CATEGORY) 45 .SetDescription("Virtio GPU fence timeline events") 46 .SetTags("virtio-gpu")); 47 48 #define GFXSTREAM_TRACE_EVENT(...) TRACE_EVENT(__VA_ARGS__) 49 #define GFXSTREAM_TRACE_EVENT_INSTANT(...) TRACE_EVENT_INSTANT(__VA_ARGS__) 50 51 #define GFXSTREAM_TRACE_FLOW(id) perfetto::Flow::ProcessScoped(id) 52 53 #define GFXSTREAM_TRACE_TRACK_FOR_CURRENT_THREAD() perfetto::ThreadTrack::Current() 54 #define GFXSTREAM_TRACE_TRACK(id) perfetto::Track(id) 55 56 #define GFXSTREAM_TRACE_NAME_TRACK(track, name) \ 57 do { \ 58 auto trackDescriptor = track.Serialize(); \ 59 trackDescriptor.set_name(name); \ 60 perfetto::TrackEvent::SetTrackDescriptor(track, trackDescriptor); \ 61 } while (0) 62 63 #else 64 65 #define GFXSTREAM_TRACE_EVENT(...) 66 #define GFXSTREAM_TRACE_EVENT_INSTANT(...) 67 68 #define GFXSTREAM_TRACE_FLOW(id) 69 70 #define GFXSTREAM_TRACE_TRACK_FOR_CURRENT_THREAD() 71 #define GFXSTREAM_TRACE_TRACK(id) 72 #define GFXSTREAM_TRACE_NAME_TRACK(track, name) 73 74 #endif // GFXSTREAM_BUILD_WITH_TRACING 75 76 namespace gfxstream { 77 namespace host { 78 79 uint64_t GetUniqueTracingId(); 80 81 void InitializeTracing(); 82 83 } // namespace host 84 } // namespace gfxstream 85