Skip to content

Commit

Permalink
fix perf regression in tracing layer
Browse files Browse the repository at this point in the history
In the current tracing layer, the parameters of the function
being called are always printed to a string stream that may
be used for logging. However, if logs are disabled, this
just unnecessarily wastes times.
  • Loading branch information
pbalcer committed Sep 20, 2024
1 parent ed85c3e commit a32549b
Show file tree
Hide file tree
Showing 3 changed files with 1,732 additions and 960 deletions.
12 changes: 8 additions & 4 deletions scripts/templates/trcddi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ namespace ur_tracing_layer
${th.make_pfncb_param_type(n, tags, obj)} params = { &${",&".join(th.make_param_lines(n, tags, obj, format=["name"]))} };
uint64_t instance = getContext()->notify_begin(${th.make_func_etor(n, tags, obj)}, "${th.make_func_name(n, tags, obj)}", &params);

getContext()->logger.info("---> ${th.make_func_name(n, tags, obj)}");
auto &logger = getContext()->logger;

logger.info("---> ${th.make_func_name(n, tags, obj)}");

${x}_result_t result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );

getContext()->notify_end(${th.make_func_etor(n, tags, obj)}, "${th.make_func_name(n, tags, obj)}", &params, &result, instance);

std::ostringstream args_str;
ur::extras::printFunctionParams(args_str, ${th.make_func_etor(n, tags, obj)}, &params);
getContext()->logger.info("({}) -> {};\n", args_str.str(), result);
if (logger.getLevel() <= logger::Level::INFO) {
std::ostringstream args_str;
ur::extras::printFunctionParams(args_str, ${th.make_func_etor(n, tags, obj)}, &params);
logger.info("({}) -> {};\n", args_str.str(), result);
}

return result;
}
Expand Down
2 changes: 2 additions & 0 deletions source/common/logger/ur_logger_details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Logger {

void setLevel(logger::Level level) { this->level = level; }

logger::Level getLevel() { return this->level; }

void setFlushLevel(logger::Level level) {
if (sink) {
this->sink->setFlushLevel(level);
Expand Down
Loading

0 comments on commit a32549b

Please sign in to comment.