Skip to content

Commit d31b9c3

Browse files
sanrisefacebook-github-bot
authored andcommitted
Setters and getters for trace IDs (#967)
Summary: This commit moves the trace ID initialization logic to be inline with how ActivityProfilers interact with LoggerObservers by setting a default local trace ID when a profiler config does not contain a trace ID. The USTLoggerCollector, which is our internal LoggerObserver will record the trace ID for a given environment (which is a PID today) using the `setTraceID` method that all LoggerObservers must staisfy. Additionally any internal calls to read this trace ID, for example from our ManifoldChromeTrace logger, may use a special `getTraceID` method that ships with `USTLoggerCollector`. Group trace IDs are handled accordingly. Reviewed By: aaronenyeshi Differential Revision: D60267172
1 parent 596126c commit d31b9c3

3 files changed

+8
-4
lines changed

libkineto/src/ActivityProfilerController.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ void ActivityProfilerController::setLoggerCollectorFactory(
4040
std::function<std::shared_ptr<LoggerCollector>()> factory) {
4141
loggerCollectorFactory() = factory();
4242
}
43+
44+
std::shared_ptr<LoggerCollector>
45+
ActivityProfilerController::getLoggerCollector() {
46+
return loggerCollectorFactory();
47+
}
4348
#endif // !USE_GOOGLE_LOG
4449

4550
ActivityProfilerController::ActivityProfilerController(

libkineto/src/ActivityProfilerController.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ActivityProfilerController : public ConfigLoader::ConfigHandler {
4040
~ActivityProfilerController();
4141

4242
#if !USE_GOOGLE_LOG
43+
static std::shared_ptr<LoggerCollector> getLoggerCollector();
4344
static void setLoggerCollectorFactory(
4445
std::function<std::shared_ptr<LoggerCollector>()> factory);
4546
#endif // !USE_GOOGLE_LOG

libkineto/src/CuptiActivityProfiler.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1054,13 +1054,11 @@ void CuptiActivityProfiler::configure(
10541054

10551055
// Set useful metadata into the logger.
10561056
LOGGER_OBSERVER_SET_TRACE_DURATION_MS(config_->activitiesDuration().count());
1057+
LOGGER_OBSERVER_SET_TRACE_ID(config_->requestTraceID());
1058+
LOGGER_OBSERVER_SET_GROUP_TRACE_ID(config_->requestGroupTraceID());
10571059
if (!config_->requestTraceID().empty()) {
1058-
LOGGER_OBSERVER_SET_TRACE_ID(config_->requestTraceID());
10591060
addMetadata("trace_id", "\"" + config_->requestTraceID() + "\"");
10601061
}
1061-
if (!config_->requestGroupTraceID().empty()) {
1062-
LOGGER_OBSERVER_SET_GROUP_TRACE_ID(config_->requestGroupTraceID());
1063-
}
10641062

10651063
#if defined(HAS_CUPTI) || defined(HAS_ROCTRACER)
10661064
if (!cpuOnly_) {

0 commit comments

Comments
 (0)