Skip to content

Commit

Permalink
[Kineto][Profiler] Guard event metadata python thread via verbose flag (
Browse files Browse the repository at this point in the history
#87096)

Summary:
Pull Request resolved: #87096

For Python Tracing enabled trace files, this field "python thread": 0 is repeated for every python_function event. This bloats the trace json size for large number of events or deep call stacks. Instead make this metadata guarded by the verbose flag.

Test Plan: CI

Reviewed By: robieta, slgong-fb

Differential Revision: D40325815

Pulled By: aaronenyeshi

fbshipit-source-id: 1afb8b1e6f112c7f5dc9ea5f7bec5ea9aedff492
  • Loading branch information
aaronenyeshi authored and facebook-github-bot committed Oct 18, 2022
1 parent 440f734 commit df9918a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions torch/csrc/autograd/profiler_kineto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ struct AddTensorboardFields : public MetadataBase {
};

struct AddGenericMetadata : public MetadataBase {
AddGenericMetadata(std::shared_ptr<Result>& result) : MetadataBase(result) {
AddGenericMetadata(std::shared_ptr<Result>& result, const bool verbose)
: MetadataBase(result) {
result->visit(*this);
result->visit_if_base<PyExtraFieldsBase>([&, this](const auto& i) -> void {
this->addMetadata("Python thread", std::to_string(i.python_tid_));
});
if (verbose) {
result->visit_if_base<PyExtraFieldsBase>(
[&, this](const auto& i) -> void {
this->addMetadata("Python thread", std::to_string(i.python_tid_));
});
}
}

void operator()(ExtraFields<EventType::TorchOp>& op_event) {
Expand Down Expand Up @@ -311,7 +315,7 @@ struct KinetoThreadLocalState : public ProfilerStateBase {

kineto_events_.emplace_back(e, config_.experimental_config.verbose);
AddTensorboardFields add_tb(e, kineto_events_.back());
AddGenericMetadata add_generic(e);
AddGenericMetadata add_generic(e, config_.experimental_config.verbose);

// It is not safe to use the activity after post processing.
e->kineto_activity_ = nullptr;
Expand Down

0 comments on commit df9918a

Please sign in to comment.