Skip to content

Commit

Permalink
Add GetLevelForDuration() helper function.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 642351477
  • Loading branch information
tensorflower-gardener committed Jun 11, 2024
1 parent b64a157 commit ff2ce71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tensorflow/core/profiler/convert/trace_viewer/trace_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ void MaybeAddEventUniqueId(std::vector<TraceEvent*>& events) {

} // namespace

int GetLevelForDuration(uint64_t duration_ps) {
int i = 0;
for (; i < NumLevels(); ++i) {
if (duration_ps > kLayerResolutions[i]) {
return i;
}
}
return i;
}

std::vector<TraceEvent*> MergeEventTracks(
const std::vector<const TraceEventTrack*>& event_tracks) {
std::vector<TraceEvent*> events;
Expand Down
3 changes: 3 additions & 0 deletions tensorflow/core/profiler/convert/trace_viewer/trace_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ absl::Status ReadFileTraceMetadata(std::string& filepath, Trace* trace);
std::vector<std::vector<const TraceEvent*>> GetEventsByLevel(
const Trace& trace, std::vector<TraceEvent*>& events);

// Returns the level that an event with `duration_ps` would go into.
int GetLevelForDuration(uint64_t duration_ps);

struct EventFactory {
TraceEvent* Create() {
events.push_back(std::make_unique<TraceEvent>());
Expand Down

0 comments on commit ff2ce71

Please sign in to comment.