Skip to content

Commit a32549b

Browse files
committed
fix perf regression in tracing layer
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.
1 parent ed85c3e commit a32549b

File tree

3 files changed

+1732
-960
lines changed

3 files changed

+1732
-960
lines changed

scripts/templates/trcddi.cpp.mako

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ namespace ur_tracing_layer
4545
${th.make_pfncb_param_type(n, tags, obj)} params = { &${",&".join(th.make_param_lines(n, tags, obj, format=["name"]))} };
4646
uint64_t instance = getContext()->notify_begin(${th.make_func_etor(n, tags, obj)}, "${th.make_func_name(n, tags, obj)}", &params);
4747

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

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

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

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

5862
return result;
5963
}

source/common/logger/ur_logger_details.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Logger {
3030

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

33+
logger::Level getLevel() { return this->level; }
34+
3335
void setFlushLevel(logger::Level level) {
3436
if (sink) {
3537
this->sink->setFlushLevel(level);

0 commit comments

Comments
 (0)