Files
rocm-systems/projects/roctracer/src/roctx/roctx.cpp
T

87 řádky
3.0 KiB
C++
Surový Normální zobrazení Historie

2022-04-19 07:18:05 -07:00
/* Copyright (c) 2018-2022 Advanced Micro Devices, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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:
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
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. */
2019-08-30 08:53:34 -05:00
2022-05-17 20:59:56 -07:00
#include "roctx.h"
#include "roctracer_roctx.h"
#include "ext/prof_protocol.h"
2019-08-30 08:53:34 -05:00
2022-05-23 11:44:36 -07:00
#include "util/callback_table.h"
2022-05-20 20:19:32 -07:00
2022-05-06 12:29:50 -07:00
namespace {
2022-04-18 16:13:08 -07:00
2022-05-23 11:44:36 -07:00
roctracer::util::CallbackTable<ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_NUMBER> callbacks;
2022-05-20 20:19:32 -07:00
thread_local int nested_range_level(0);
2022-04-18 16:13:08 -07:00
2022-05-06 12:29:50 -07:00
} // namespace
2019-08-30 08:53:34 -05:00
2022-05-23 20:58:53 -07:00
ROCTX_API uint32_t roctx_version_major() { return ROCTX_VERSION_MAJOR; }
ROCTX_API uint32_t roctx_version_minor() { return ROCTX_VERSION_MINOR; }
2019-08-30 08:53:34 -05:00
2022-05-23 20:58:53 -07:00
ROCTX_API void roctxMarkA(const char* message) {
2022-05-06 19:46:09 -07:00
roctx_api_data_t api_data{};
api_data.args.roctxMarkA.message = message;
callbacks.Invoke(ROCTX_API_ID_roctxMarkA, &api_data);
2019-08-30 08:53:34 -05:00
}
2022-05-23 20:58:53 -07:00
ROCTX_API int roctxRangePushA(const char* message) {
2022-05-06 19:46:09 -07:00
roctx_api_data_t api_data{};
api_data.args.roctxRangePushA.message = message;
callbacks.Invoke(ROCTX_API_ID_roctxRangePushA, &api_data);
2019-10-21 21:18:54 -05:00
2022-05-20 20:19:32 -07:00
return nested_range_level++;
2019-08-30 08:53:34 -05:00
}
2022-05-23 20:58:53 -07:00
ROCTX_API int roctxRangePop() {
2022-05-06 19:46:09 -07:00
roctx_api_data_t api_data{};
callbacks.Invoke(ROCTX_API_ID_roctxRangePop, &api_data);
2022-05-06 12:29:50 -07:00
2022-05-20 20:19:32 -07:00
if (nested_range_level == 0) return -1;
return --nested_range_level;
2019-10-21 21:18:54 -05:00
}
2022-05-23 20:58:53 -07:00
ROCTX_API roctx_range_id_t roctxRangeStartA(const char* message) {
2022-05-20 20:19:32 -07:00
static std::atomic<roctx_range_id_t> start_stop_range_id(1);
2022-05-20 23:10:05 -07:00
auto id = start_stop_range_id++;
2020-07-29 18:28:51 -04:00
2022-05-06 19:46:09 -07:00
roctx_api_data_t api_data{};
api_data.args.roctxRangeStartA.message = message;
2022-05-20 23:10:05 -07:00
api_data.args.roctxRangeStartA.id = id;
2022-05-06 19:46:09 -07:00
callbacks.Invoke(ROCTX_API_ID_roctxRangeStartA, &api_data);
2020-07-29 18:28:51 -04:00
2022-05-20 23:10:05 -07:00
return id;
2020-07-29 18:28:51 -04:00
}
2022-05-23 20:58:53 -07:00
ROCTX_API void roctxRangeStop(roctx_range_id_t rangeId) {
2022-05-06 19:46:09 -07:00
roctx_api_data_t api_data{};
api_data.args.roctxRangeStop.id = rangeId;
callbacks.Invoke(ROCTX_API_ID_roctxRangeStop, &api_data);
2020-07-29 18:28:51 -04:00
}
2022-05-23 20:58:53 -07:00
extern "C" ROCTX_EXPORT bool RegisterApiCallback(uint32_t op, void* callback, void* arg) {
2022-04-18 16:13:08 -07:00
if (op >= ROCTX_API_ID_NUMBER) return false;
2022-05-06 12:29:50 -07:00
callbacks.Set(op, reinterpret_cast<activity_rtapi_callback_t>(callback), arg);
2022-04-18 16:13:08 -07:00
return true;
}
2022-05-23 20:58:53 -07:00
extern "C" ROCTX_EXPORT bool RemoveApiCallback(uint32_t op) {
2022-04-18 16:13:08 -07:00
if (op >= ROCTX_API_ID_NUMBER) return false;
2022-05-06 12:29:50 -07:00
callbacks.Set(op, nullptr, nullptr);
2022-04-18 16:13:08 -07:00
return true;
2022-05-06 12:29:50 -07:00
}