Adding late-replace envvar filenames to ATT
Change-Id: I5df51934ffa25358503013e1a230adb894d6ff94
Этот коммит содержится в:
коммит произвёл
Giovanni Baraldi
родитель
a1999fa366
Коммит
fe00badc6e
@@ -40,6 +40,7 @@
|
||||
#include <hsa/hsa.h>
|
||||
#include <mutex>
|
||||
#include <sys/stat.h>
|
||||
#include <regex>
|
||||
|
||||
#include "rocprofiler.h"
|
||||
#include "rocprofiler_plugin.h"
|
||||
@@ -49,6 +50,23 @@
|
||||
#define ATT_FILENAME_MAXBYTES 90
|
||||
#define TEST_INVALID_KERNEL size_t(-1)
|
||||
|
||||
static bool env_var_search(std::string& s) {
|
||||
std::smatch m;
|
||||
std::regex e("(.*)\\%\\q\\{([^}]+)\\}(.*)");
|
||||
std::regex_match(s, m, e);
|
||||
|
||||
if (m.size() != 4) return false;
|
||||
|
||||
while (m.size() == 4) {
|
||||
const char* envvar = getenv(m[2].str().c_str());
|
||||
if (!envvar) envvar = "";
|
||||
s = m[1].str() + envvar + m[3].str();
|
||||
std::regex_match(s, m, e);
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class att_plugin_t {
|
||||
public:
|
||||
att_plugin_t(void* data) {
|
||||
@@ -70,12 +88,30 @@ class att_plugin_t {
|
||||
static std::mutex writing_lock;
|
||||
bool is_valid_{true};
|
||||
rocprofiler::att_header_packet_t header{.raw = 0};
|
||||
std::string output_dir = ".";
|
||||
|
||||
bool CheckAddrMatches(uint64_t kernel_addr, uint64_t base_address, uint64_t size)
|
||||
{
|
||||
return (kernel_addr >= base_address) && (kernel_addr < base_address + size);
|
||||
}
|
||||
|
||||
void InitOutputDir()
|
||||
{
|
||||
static bool bIsInit = false;
|
||||
if (bIsInit) return;
|
||||
bIsInit = true;
|
||||
|
||||
if (const char* env = getenv("OUTPUT_PATH")) output_dir = std::string(env);
|
||||
env_var_search(output_dir);
|
||||
|
||||
if (!output_dir.size()) return;
|
||||
|
||||
try {
|
||||
std::experimental::filesystem::create_directories(output_dir);
|
||||
} catch (...) {}
|
||||
output_dir += '/';
|
||||
}
|
||||
|
||||
inline bool att_file_exists(const std::string& name) {
|
||||
struct stat buffer;
|
||||
return stat(name.c_str(), &buffer) == 0;
|
||||
@@ -87,6 +123,7 @@ class att_plugin_t {
|
||||
rocprofiler_session_id_t session_id, rocprofiler_buffer_id_t buffer_id) {
|
||||
|
||||
if (!att_tracer_record) return ROCPROFILER_STATUS_ERROR;
|
||||
InitOutputDir();
|
||||
|
||||
std::string kernel_name_mangled;
|
||||
// Found problem with rocprofiler API for invalid kernel_ids;
|
||||
@@ -113,9 +150,6 @@ class att_plugin_t {
|
||||
if (name_demangled.size() > ATT_FILENAME_MAXBYTES) // Limit filename size
|
||||
name_demangled = name_demangled.substr(0, ATT_FILENAME_MAXBYTES);
|
||||
|
||||
std::string output_dir = ".";
|
||||
if (const char* env = getenv("OUTPUT_PATH")) output_dir = std::string(env);
|
||||
|
||||
std::string outfilepath = output_dir + '/' + name_demangled;
|
||||
outfilepath.reserve(output_dir.size() + 128); // Max filename size
|
||||
if (MPI_ENABLE) outfilepath += "_rank" + std::to_string(MPI_RANK);
|
||||
|
||||
@@ -205,7 +205,7 @@ bool AttTracer::AsyncSignalHandlerATT(hsa_signal_value_t /* signal */, void* dat
|
||||
// return true;
|
||||
rocprofiler_record_att_tracer_t record{};
|
||||
record.kernel_id = rocprofiler_kernel_id_t{pending.kernel_descriptor};
|
||||
record.gpu_id = rocprofiler_agent_id_t{(uint64_t)queue_info_session->gpu_index};
|
||||
record.gpu_id = rocprofiler_agent_id_t{(uint64_t)queue_info_session->agent.handle};
|
||||
record.kernel_properties = pending.kernel_properties;
|
||||
record.thread_id = rocprofiler_thread_id_t{pending.thread_id};
|
||||
record.queue_idx = rocprofiler_queue_index_t{pending.queue_index};
|
||||
|
||||
@@ -482,12 +482,15 @@ void plugins_load(void* userdata) {
|
||||
else
|
||||
plugin_name = "libcli_plugin.so";
|
||||
}
|
||||
env_var_replace("OUTPUT_PATH");
|
||||
|
||||
bool bIsATT = std::string_view(plugin_name) == "libatt_plugin.so";
|
||||
if (!bIsATT)
|
||||
env_var_replace("OUTPUT_PATH");
|
||||
env_var_replace("OUT_FILE_NAME");
|
||||
|
||||
std::string out_path = getenv("OUTPUT_PATH") ? getenv("OUTPUT_PATH") : "";
|
||||
|
||||
if (out_path.size()) {
|
||||
if (out_path.size() && !bIsATT) {
|
||||
try {
|
||||
std::experimental::filesystem::create_directories(out_path);
|
||||
} catch (...) {
|
||||
|
||||
Ссылка в новой задаче
Block a user