Files
rocm-systems/source/lib/core/perfetto.cpp
T

102 строки
3.3 KiB
C++
Исходник Обычный вид История

2022-01-26 23:25:00 -06:00
// MIT License
//
// Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
2022-01-26 23:25:00 -06:00
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
2022-01-26 23:25:00 -06:00
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2022-01-26 23:25:00 -06:00
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2022-01-26 23:25:00 -06:00
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "perfetto.hpp"
#include "config.hpp"
2022-09-26 07:52:14 -05:00
namespace omnitrace
{
namespace perfetto
{
2023-02-03 14:10:42 -06:00
auto&
get_config()
{
static auto _v = ::perfetto::TraceConfig{};
return _v;
}
auto&
get_session()
{
static auto _v = std::unique_ptr<::perfetto::TracingSession>{};
return _v;
}
2022-09-26 07:52:14 -05:00
void
setup()
{
auto args = ::perfetto::TracingInitArgs{};
auto track_event_cfg = ::perfetto::protos::gen::TrackEventConfig{};
2023-02-03 14:10:42 -06:00
auto& cfg = get_config();
2022-09-26 07:52:14 -05:00
// environment settings
2023-02-03 14:10:42 -06:00
auto shmem_size_hint = config::get_perfetto_shmem_size_hint();
auto buffer_size = config::get_perfetto_buffer_size();
2022-09-26 07:52:14 -05:00
auto _policy =
2023-02-03 14:10:42 -06:00
config::get_perfetto_fill_policy() == "discard"
2022-09-26 07:52:14 -05:00
? ::perfetto::protos::gen::TraceConfig_BufferConfig_FillPolicy_DISCARD
: ::perfetto::protos::gen::TraceConfig_BufferConfig_FillPolicy_RING_BUFFER;
auto* buffer_config = cfg.add_buffers();
buffer_config->set_size_kb(buffer_size);
buffer_config->set_fill_policy(_policy);
2023-02-03 14:10:42 -06:00
for(const auto& itr : config::get_disabled_categories())
2022-09-26 07:52:14 -05:00
{
OMNITRACE_VERBOSE_F(1, "Disabling perfetto track event category: %s\n",
itr.c_str());
track_event_cfg.add_disabled_categories(itr);
}
auto* ds_cfg = cfg.add_data_sources()->mutable_config();
ds_cfg->set_name("track_event"); // this MUST be track_event
ds_cfg->set_track_event_config_raw(track_event_cfg.SerializeAsString());
args.shmem_size_hint_kb = shmem_size_hint;
if(get_backend() != "inprocess") args.backends |= ::perfetto::kSystemBackend;
if(get_backend() != "system") args.backends |= ::perfetto::kInProcessBackend;
::perfetto::Tracing::Initialize(args);
::perfetto::TrackEvent::Register();
}
void
start()
{
2023-02-03 14:10:42 -06:00
auto& cfg = get_config();
auto& tracing_session = get_session();
2022-09-26 07:52:14 -05:00
tracing_session = ::perfetto::Tracing::NewTrace();
tracing_session->Setup(cfg);
tracing_session->StartBlocking();
}
} // namespace perfetto
2023-02-03 14:10:42 -06:00
std::unique_ptr<::perfetto::TracingSession>&
get_perfetto_session()
{
return ::omnitrace::perfetto::get_session();
}
2022-09-26 07:52:14 -05:00
} // namespace omnitrace
PERFETTO_TRACK_EVENT_STATIC_STORAGE();