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 #include "gfxstream/host/Tracing.h" 16 17 #include <atomic> 18 #include <mutex> 19 20 #if defined(GFXSTREAM_BUILD_WITH_TRACING) 21 22 PERFETTO_TRACK_EVENT_STATIC_STORAGE(); 23 24 #endif // defined(GFXSTREAM_BUILD_WITH_TRACING) 25 26 namespace gfxstream { 27 namespace host { 28 InitializeTracing()29void InitializeTracing() { 30 #if defined(GFXSTREAM_BUILD_WITH_TRACING) 31 [[clang::no_destroy]] static std::once_flag sOnceFlag; 32 std::call_once(sOnceFlag, [](){ 33 perfetto::TracingInitArgs args; 34 args.backends |= perfetto::kSystemBackend; 35 perfetto::Tracing::Initialize(args); 36 perfetto::TrackEvent::Register(); 37 }); 38 #endif // defined(GFXSTREAM_BUILD_WITH_TRACING) 39 } 40 GetUniqueTracingId()41uint64_t GetUniqueTracingId() { 42 static std::atomic<uint64_t> sNextId{4194304}; 43 return sNextId++; 44 } 45 46 } // namespace host 47 } // namespace gfxstream