Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Fix event structure. #199

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dftracer/brahma/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class POSIXDFTracer : public POSIX {
inline uint16_t is_traced(const char *filename, const char *func) {
if (stop_trace) return 0;
if (trace_all_files) {
return logger->hash_and_store(filename);
return logger->hash_and_store(filename, METADATA_NAME_FILE_HASH);
} else {
const char *tracefile = is_traced_common(filename, func);
if (tracefile != nullptr)
DFTRACER_LOG_DEBUG(
"Calling POSIXDFTracer.is_traced with "
"filename %s for %s trace %d",
filename, func, tracefile != nullptr);
return logger->hash_and_store(tracefile);
return logger->hash_and_store(tracefile, METADATA_NAME_FILE_HASH);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/dftracer/brahma/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class STDIODFTracer : public STDIO {
func);
if (stop_trace) return 0;
if (trace_all_files)
return logger->hash_and_store(filename);
return logger->hash_and_store(filename, METADATA_NAME_FILE_HASH);
else {
const char *trace_file = is_traced_common(filename, func);
return logger->hash_and_store(trace_file);
return logger->hash_and_store(trace_file, METADATA_NAME_FILE_HASH);
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/dftracer/core/enumeration.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ enum ProfileInitType : uint8_t {
PROFILER_INIT_LD_PRELOAD = 1,
PROFILER_INIT_FUNCTION = 2
};
enum EventType : uint8_t {
COMPLETE_EVENT = 0,
METADATA_EVENT = 1,
HASH_EVENT = 2,
REDUCE_EVENT = 3,
};

inline void convert(const std::string &s, ProfileInitType &type) {
if (s == "PRELOAD") {
type = ProfileInitType::PROFILER_INIT_LD_PRELOAD;
Expand All @@ -49,4 +44,11 @@ inline void convert(const std::string &s, cpplogger::LoggerType &type) {
type = cpplogger::LoggerType::LOG_ERROR;
}
}

#define METADATA_NAME_PROCESS "PR"
#define METADATA_NAME_PROCESS_NAME "process_name"
#define METADATA_NAME_THREAD_NAME "thread_name"
#define METADATA_NAME_FILE_HASH "FH"
#define METADATA_NAME_HOSTNAME_HASH "HH"
#define METADATA_NAME_STRING_HASH "SH"
#endif // DFTRACER_ENUMERATION_H
85 changes: 51 additions & 34 deletions src/dftracer/df_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <cstring>
#include <dftracer/dftracer_config.hpp>
#include <unordered_map>

#include "core/enumeration.h"
#include "utils/posix_internal.h"
#ifdef DFTRACER_HWLOC_ENABLE
#include <hwloc.h>
#endif
Expand Down Expand Up @@ -100,7 +103,11 @@ class DFTLogger {
inline void update_log_file(std::string log_file, std::string exec_name,
std::string cmd, ProcessID process_id = -1) {
DFTRACER_LOG_DEBUG("DFTLogger.update_log_file %s", log_file.c_str());
this->process_id = process_id;
this->process_id = df_getpid();
ThreadID tid = 0;
if (dftracer_tid) {
tid = df_gettid();
}
this->writer = dftracer::Singleton<dftracer::ChromeWriter>::get_instance();
if (this->writer != nullptr) {
char hostname[256];
Expand All @@ -109,12 +116,22 @@ class DFTLogger {
md5String(hostname, &hostname_hash);
this->writer->initialize(log_file.data(), this->throw_error,
hostname_hash);
hostname_hash = hash_and_store(hostname);
hostname_hash = hash_and_store(hostname, METADATA_NAME_HOSTNAME_HASH);
char thread_name[128];
auto size = sprintf(thread_name, "%lu", this->process_id);
thread_name[size] = '\0';
this->enter_event();
this->writer->log_metadata(
index_stack[level - 1], thread_name, METADATA_NAME_THREAD_NAME,
METADATA_NAME_THREAD_NAME, this->process_id, tid);
this->exit_event();
std::unordered_map<std::string, std::any> *meta = nullptr;
if (include_metadata) {
meta = new std::unordered_map<std::string, std::any>();
uint16_t cmd_hash = hash_and_store(cmd.data());
uint16_t exec_hash = hash_and_store(exec_name.data());
uint16_t cmd_hash =
hash_and_store(cmd.data(), METADATA_NAME_STRING_HASH);
uint16_t exec_hash =
hash_and_store(exec_name.data(), METADATA_NAME_STRING_HASH);

meta->insert_or_assign("version", DFTRACER_VERSION);
meta->insert_or_assign("exec_hash", exec_hash);
Expand Down Expand Up @@ -151,9 +168,10 @@ class DFTLogger {
tid = df_gettid() + this->process_id;
}
this->enter_event();
this->writer->log(index_stack[level - 1], "core_affinity",
all_stream.str().c_str(), EventType::REDUCE_EVENT,
0, 0, nullptr, this->process_id, tid);
this->writer->log_metadata(index_stack[level - 1], "core_affinity",
all_stream.str().c_str(),
METADATA_NAME_PROCESS, this->process_id,
tid, false);
this->exit_event();
}
}
Expand Down Expand Up @@ -189,7 +207,7 @@ class DFTLogger {
DFTRACER_LOG_DEBUG("DFTLogger.log", "");
ThreadID tid = 0;
if (dftracer_tid) {
tid = df_gettid() + this->process_id;
tid = df_gettid();
}
int local_index;
if (!include_metadata) {
Expand All @@ -211,21 +229,18 @@ class DFTLogger {
this->writer != nullptr) {
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
auto meta = std::unordered_map<std::string, std::any>();
meta.insert_or_assign("rank", rank);
auto start = this->get_time();
this->enter_event();
this->writer->log(index_stack[level - 1], "mpi", "dftracer",
EventType::COMPLETE_EVENT, start, 0, &meta,
this->process_id, tid);
this->writer->log_metadata(
index_stack[level - 1], "rank", std::to_string(rank).c_str(),
METADATA_NAME_PROCESS, this->process_id, tid);
this->exit_event();
char process_name[1024];
auto size = sprintf(process_name, "Rank %d", rank);
process_name[size] = '\0';
this->enter_event();
this->writer->log(index_stack[level - 1], "process_name", process_name,
EventType::METADATA_EVENT, 0, 0, nullptr,
this->process_id, tid);
this->writer->log_metadata(
index_stack[level - 1], process_name, METADATA_NAME_PROCESS_NAME,
METADATA_NAME_PROCESS_NAME, this->process_id, tid);
this->exit_event();

mpi_event = true;
Expand All @@ -236,12 +251,11 @@ class DFTLogger {
if (this->writer != nullptr) {
if (include_metadata) {
this->writer->log(index_stack[level - 1], event_name, category,
EventType::COMPLETE_EVENT, start_time, duration,
metadata, this->process_id, tid);
start_time, duration, metadata, this->process_id,
tid);
} else {
this->writer->log(local_index, event_name, category,
EventType::COMPLETE_EVENT, start_time, duration,
metadata, this->process_id, tid);
this->writer->log(local_index, event_name, category, start_time,
duration, metadata, this->process_id, tid);
}

has_entry = true;
Expand All @@ -250,15 +264,16 @@ class DFTLogger {
}
}

inline uint16_t hash_and_store(char *filename) {
inline uint16_t hash_and_store(char *filename, ConstEventNameType name) {
if (filename == NULL) return 0;
char file[PATH_MAX];
strcpy(file, filename);
file[PATH_MAX - 1] = '\0';
return hash_and_store_str(file);
return hash_and_store_str(file, name);
}

inline uint16_t hash_and_store_str(char file[PATH_MAX]) {
inline uint16_t hash_and_store_str(char file[PATH_MAX],
ConstEventNameType name) {
auto iter = computed_hash.find(file);
uint16_t hash;
if (iter == computed_hash.end()) {
Expand All @@ -270,9 +285,9 @@ class DFTLogger {
tid = df_gettid();
}
this->enter_event();
this->writer->log(index_stack[level - 1], file,
std::to_string(hash).c_str(), EventType::HASH_EVENT,
0, 0, nullptr, this->process_id, tid);
this->writer->log_metadata(index_stack[level - 1], file,
std::to_string(hash).c_str(), name,
this->process_id, tid, false);
this->exit_event();
}
} else {
Expand All @@ -281,12 +296,13 @@ class DFTLogger {
return hash;
}

inline uint16_t hash_and_store(const char *filename) {
inline uint16_t hash_and_store(const char *filename,
ConstEventNameType name) {
if (filename == NULL) return 0;
char file[PATH_MAX];
strcpy(file, filename);
file[PATH_MAX - 1] = '\0';
return hash_and_store_str(file);
return hash_and_store_str(file, name);
}

inline void finalize() {
Expand All @@ -313,10 +329,11 @@ class DFTLogger {
if (trace && this->logger->include_metadata) \
metadata->insert_or_assign(#value, value);

#define DFT_LOGGER_UPDATE_HASH(value) \
if (trace && this->logger->include_metadata) { \
uint16_t value##_hash = this->logger->hash_and_store(value); \
DFT_LOGGER_UPDATE(value##_hash); \
#define DFT_LOGGER_UPDATE_HASH(value) \
if (trace && this->logger->include_metadata) { \
uint16_t value##_hash = \
this->logger->hash_and_store(value, METADATA_NAME_STRING_HASH); \
DFT_LOGGER_UPDATE(value##_hash); \
}

#define DFT_LOGGER_START(entity) \
Expand Down
Loading
Loading