Skip to content

Commit

Permalink
Setters and getters for trace IDs (#967)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sanrise authored and facebook-github-bot committed Nov 21, 2024
1 parent d9673d2 commit 9a580e6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions libkineto/src/ActivityProfilerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ void ActivityProfilerController::setLoggerCollectorFactory(
std::function<std::shared_ptr<LoggerCollector>()> factory) {
loggerCollectorFactory() = factory();
}

std::shared_ptr<LoggerCollector>
ActivityProfilerController::getLoggerCollector() {
return loggerCollectorFactory();
}
#endif // !USE_GOOGLE_LOG

ActivityProfilerController::ActivityProfilerController(
Expand Down
1 change: 1 addition & 0 deletions libkineto/src/ActivityProfilerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ActivityProfilerController : public ConfigLoader::ConfigHandler {
~ActivityProfilerController();

#if !USE_GOOGLE_LOG
static std::shared_ptr<LoggerCollector> getLoggerCollector();
static void setLoggerCollectorFactory(
std::function<std::shared_ptr<LoggerCollector>()> factory);
#endif // !USE_GOOGLE_LOG
Expand Down
6 changes: 2 additions & 4 deletions libkineto/src/CuptiActivityProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,13 +1054,11 @@ void CuptiActivityProfiler::configure(

// Set useful metadata into the logger.
LOGGER_OBSERVER_SET_TRACE_DURATION_MS(config_->activitiesDuration().count());
LOGGER_OBSERVER_SET_TRACE_ID(config_->requestTraceID());
LOGGER_OBSERVER_SET_GROUP_TRACE_ID(config_->requestGroupTraceID());
if (!config_->requestTraceID().empty()) {
LOGGER_OBSERVER_SET_TRACE_ID(config_->requestTraceID());
addMetadata("trace_id", "\"" + config_->requestTraceID() + "\"");
}
if (!config_->requestGroupTraceID().empty()) {
LOGGER_OBSERVER_SET_GROUP_TRACE_ID(config_->requestGroupTraceID());
}

#if defined(HAS_CUPTI) || defined(HAS_ROCTRACER)
if (!cpuOnly_) {
Expand Down

0 comments on commit 9a580e6

Please sign in to comment.