Query callback and buffered tracing names (#135)
* Update include/rocprofiler/buffer_tracing.h
- add query functions for kind name, and kind operation name
- tweak iterate functions to not be specifically dedicated to names
* Update include/rocprofiler/callback_tracing.h
- add query functions for kind name, and kind operation name
- tweak iterate functions to not be specifically dedicated to names
* Update lib/rocprofiler/callback_tracing.cpp
- implement rocprofiler_query_callback_tracing_kind_name
- implement rocprofiler_query_callback_tracing_kind_name_buf
- implement rocprofiler_query_callback_tracing_kind_operation_name
- implement rocprofiler_query_callback_tracing_kind_operation_name_buf
- implement rocprofiler_iterate_callback_tracing_kinds
- implement rocprofiler_iterate_callback_tracing_kind_operations
* Update lib/rocprofiler/buffer_tracing.cpp
- implement rocprofiler_query_buffer_tracing_kind_name
- implement rocprofiler_query_buffer_tracing_kind_name_buf
- implement rocprofiler_query_buffer_tracing_kind_operation_name
- implement rocprofiler_query_buffer_tracing_kind_operation_name_buf
- implement rocprofiler_iterate_buffer_tracing_kinds
- implement rocprofiler_iterate_buffer_tracing_kind_operations
* Update lib/rocprofiler/tests/registration.cpp
- use new implementation for getting callback/buffer tracing names
* Update samples/api_buffered_tracing
- use new implementation for getting callback/buffer tracing names
* Update samples/api_callback_tracing
- use new implementation for getting callback/buffer tracing names
* Remove buffered query functions
- *_buf variants of the rocprofiler_query_X_tracing_Y functions were removed since we currently have no names requiring these functions
* Rename ROCPROFILER_STATUS_ERROR_DOMAIN_NOT_FOUND
- "DOMAIN" changed to "KIND" since former is more specific tracing whereas kind is used more generically
[ROCm/rocprofiler-sdk commit: 87cc748c3d]
This commit is contained in:
gecommit door
GitHub
bovenliggende
d05031db89
commit
6c26870c8c
@@ -37,6 +37,7 @@
|
||||
#include <rocprofiler/rocprofiler.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
@@ -45,7 +46,9 @@
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <ratio>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
@@ -72,7 +75,16 @@ struct source_location
|
||||
std::string context = {};
|
||||
};
|
||||
|
||||
using call_stack_t = std::vector<source_location>;
|
||||
using call_stack_t = std::vector<source_location>;
|
||||
using callback_kind_names_t = std::map<rocprofiler_service_callback_tracing_kind_t, const char*>;
|
||||
using callback_kind_operation_names_t =
|
||||
std::map<rocprofiler_service_callback_tracing_kind_t, std::map<uint32_t, const char*>>;
|
||||
|
||||
struct callback_name_info
|
||||
{
|
||||
callback_kind_names_t kind_names = {};
|
||||
callback_kind_operation_names_t operation_names = {};
|
||||
};
|
||||
|
||||
rocprofiler_client_id_t* client_id = nullptr;
|
||||
rocprofiler_client_finalize_t client_fini_func = nullptr;
|
||||
@@ -109,11 +121,12 @@ print_call_stack(const call_stack_t& _call_stack)
|
||||
std::cout << "Outputting collected data to " << ofname << "...\n" << std::flush;
|
||||
|
||||
size_t n = 0;
|
||||
*ofs << std::left;
|
||||
for(const auto& itr : _call_stack)
|
||||
{
|
||||
*ofs << std::setw(2) << ++n << "/" << std::setw(2) << _call_stack.size() << " ";
|
||||
*ofs << "[" << fs::path{itr.file}.filename() << ":" << itr.line << "] " << std::setw(20)
|
||||
<< std::left << itr.function;
|
||||
<< itr.function;
|
||||
if(!itr.context.empty()) *ofs << " :: " << itr.context;
|
||||
*ofs << "\n";
|
||||
}
|
||||
@@ -123,60 +136,74 @@ print_call_stack(const call_stack_t& _call_stack)
|
||||
if(cleanup) cleanup(ofs);
|
||||
}
|
||||
|
||||
void
|
||||
store_callback_id_names(call_stack_t* tool_data)
|
||||
callback_name_info
|
||||
get_callback_id_names()
|
||||
{
|
||||
auto cb_name_info = callback_name_info{};
|
||||
//
|
||||
// callback for each kind operation
|
||||
//
|
||||
static auto tracing_operation_names_cb =
|
||||
[](rocprofiler_service_callback_tracing_kind_t /*kindv*/,
|
||||
uint32_t /*operation*/,
|
||||
const char* operation_name,
|
||||
void* data_v) {
|
||||
static_cast<call_stack_t*>(data_v)->emplace_back(
|
||||
source_location{"rocprofiler_iterate_callback_tracing_kind_operation_names",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
std::string{" "} + std::string{operation_name}});
|
||||
static auto tracing_kind_operation_cb =
|
||||
[](rocprofiler_service_callback_tracing_kind_t kindv, uint32_t operation, void* data_v) {
|
||||
auto* name_info_v = static_cast<callback_name_info*>(data_v);
|
||||
|
||||
if(kindv == ROCPROFILER_SERVICE_CALLBACK_TRACING_HSA_API)
|
||||
{
|
||||
const char* name = nullptr;
|
||||
ROCPROFILER_CALL(rocprofiler_query_callback_tracing_kind_operation_name(
|
||||
kindv, operation, &name, nullptr),
|
||||
"query callback tracing kind operation name");
|
||||
if(name) name_info_v->operation_names[kindv][operation] = name;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
//
|
||||
// callback for each callback kind (i.e. domain)
|
||||
//
|
||||
static auto tracing_kind_names_cb = [](rocprofiler_service_callback_tracing_kind_t kind,
|
||||
const char* kind_name,
|
||||
void* data) {
|
||||
static auto tracing_kind_cb = [](rocprofiler_service_callback_tracing_kind_t kind, void* data) {
|
||||
// store the callback kind name
|
||||
static_cast<call_stack_t*>(data)->emplace_back(source_location{
|
||||
"rocprofiler_iterate_callback_tracing_kind_names ", __FILE__, __LINE__, kind_name});
|
||||
auto* name_info_v = static_cast<callback_name_info*>(data);
|
||||
const char* name = nullptr;
|
||||
ROCPROFILER_CALL(rocprofiler_query_callback_tracing_kind_name(kind, &name, nullptr),
|
||||
"query callback tracing kind operation name");
|
||||
if(name) name_info_v->kind_names[kind] = name;
|
||||
|
||||
// store the operation names for the HSA API
|
||||
if(kind == ROCPROFILER_SERVICE_CALLBACK_TRACING_HSA_API)
|
||||
{
|
||||
rocprofiler_iterate_callback_tracing_kind_operation_names(
|
||||
kind, tracing_operation_names_cb, data);
|
||||
ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_kind_operations(
|
||||
kind, tracing_kind_operation_cb, static_cast<void*>(data)),
|
||||
"iterating callback tracing kind operations");
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
rocprofiler_iterate_callback_tracing_kind_names(tracing_kind_names_cb,
|
||||
static_cast<void*>(tool_data));
|
||||
ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_kinds(tracing_kind_cb,
|
||||
static_cast<void*>(&cb_name_info)),
|
||||
"iterating callback tracing kinds");
|
||||
|
||||
return cb_name_info;
|
||||
}
|
||||
|
||||
void
|
||||
tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
rocprofiler_user_data_t*,
|
||||
void* user_data)
|
||||
rocprofiler_user_data_t* user_data,
|
||||
void* callback_data)
|
||||
{
|
||||
assert(user_data != nullptr);
|
||||
assert(callback_data != nullptr);
|
||||
|
||||
auto now = std::chrono::steady_clock::now().time_since_epoch().count();
|
||||
uint64_t dt = 0;
|
||||
if(record.phase == ROCPROFILER_SERVICE_CALLBACK_PHASE_ENTER)
|
||||
user_data->value = now;
|
||||
else
|
||||
dt = (now - user_data->value);
|
||||
|
||||
auto info = std::stringstream{};
|
||||
info << "tid=" << record.thread_id << ", cid=" << record.correlation_id.internal
|
||||
<< ", kind=" << record.kind << ", operation=" << record.operation
|
||||
<< ", phase=" << record.phase;
|
||||
info << std::left << "tid=" << record.thread_id << ", cid=" << std::setw(3)
|
||||
<< record.correlation_id.internal << ", kind=" << record.kind
|
||||
<< ", operation=" << std::setw(3) << record.operation << ", phase=" << record.phase
|
||||
<< ", dt_nsec=" << std::setw(6) << dt;
|
||||
|
||||
auto info_data_cb = [](rocprofiler_service_callback_tracing_kind_t,
|
||||
uint32_t,
|
||||
@@ -193,7 +220,7 @@ tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
};
|
||||
|
||||
auto info_data = std::stringstream{};
|
||||
ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_operation_args(
|
||||
ROCPROFILER_CALL(rocprofiler_iterate_callback_tracing_kind_operation_args(
|
||||
record, info_data_cb, static_cast<void*>(&info_data)),
|
||||
"Failure iterating trace operation args");
|
||||
|
||||
@@ -202,8 +229,8 @@ tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
|
||||
static auto _mutex = std::mutex{};
|
||||
_mutex.lock();
|
||||
static_cast<call_stack_t*>(user_data)->emplace_back(
|
||||
source_location{__FUNCTION__, __FILE__, __LINE__, info.str()});
|
||||
static_cast<call_stack_t*>(callback_data)
|
||||
->emplace_back(source_location{__FUNCTION__, __FILE__, __LINE__, info.str()});
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
@@ -212,10 +239,33 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
|
||||
{
|
||||
assert(tool_data != nullptr);
|
||||
|
||||
static_cast<call_stack_t*>(tool_data)->emplace_back(
|
||||
source_location{__FUNCTION__, __FILE__, __LINE__, ""});
|
||||
auto* call_stack_v = static_cast<call_stack_t*>(tool_data);
|
||||
|
||||
store_callback_id_names(static_cast<call_stack_t*>(tool_data));
|
||||
call_stack_v->emplace_back(source_location{__FUNCTION__, __FILE__, __LINE__, ""});
|
||||
|
||||
callback_name_info name_info = get_callback_id_names();
|
||||
|
||||
for(const auto& itr : name_info.operation_names)
|
||||
{
|
||||
auto name_idx = std::stringstream{};
|
||||
name_idx << " [" << std::setw(3) << static_cast<int32_t>(itr.first) << "]";
|
||||
call_stack_v->emplace_back(
|
||||
source_location{"rocprofiler_callback_tracing_kind_names " + name_idx.str(),
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
name_info.kind_names.at(itr.first)});
|
||||
|
||||
for(const auto& ditr : itr.second)
|
||||
{
|
||||
auto operation_idx = std::stringstream{};
|
||||
operation_idx << " [" << std::setw(3) << static_cast<int32_t>(ditr.first) << "]";
|
||||
call_stack_v->emplace_back(source_location{
|
||||
"rocprofiler_callback_tracing_kind_operation_names" + operation_idx.str(),
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
std::string{"- "} + std::string{ditr.second}});
|
||||
}
|
||||
}
|
||||
|
||||
client_fini_func = fini_func;
|
||||
|
||||
|
||||
Verwijs in nieuw issue
Block a user