Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion xprof/convert/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,6 @@ cc_library(
"@org_xprof//xprof/convert/trace_viewer:trace_event_arguments_builder",
"@org_xprof//xprof/convert/trace_viewer:trace_events",
"@org_xprof//xprof/convert/trace_viewer:trace_events_util",
"@org_xprof//xprof/convert/trace_viewer:trace_utils",
"@tsl//tsl/profiler/protobuf:xplane_proto_cc",
"@xla//xla/tsl/profiler/utils:tf_xplane_visitor",
"@xla//xla/tsl/profiler/utils:timespan",
Expand Down
1 change: 1 addition & 0 deletions xprof/convert/trace_viewer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ cc_library(
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
"@com_google_absl//absl/types:optional",
"@com_google_protobuf//:protobuf",
"@org_xprof//plugin/xprof/protobuf:task_proto_cc",
"@org_xprof//plugin/xprof/protobuf:trace_events_proto_cc",
"@org_xprof//plugin/xprof/protobuf:trace_events_raw_proto_cc",
Expand Down
16 changes: 11 additions & 5 deletions xprof/convert/trace_viewer/trace_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ limitations under the License.
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "absl/types/optional.h"
#include "google/protobuf/arena.h"
#include "xla/tsl/lib/io/iterator.h"
#include "xla/tsl/lib/io/table.h"
#include "xla/tsl/lib/io/table_builder.h"
Expand Down Expand Up @@ -579,11 +580,8 @@ uint64_t LayerResolutionPs(unsigned level);
std::pair<uint64_t, uint64_t> GetLevelBoundsForDuration(uint64_t duration_ps);

struct EventFactory {
TraceEvent* Create() {
events.push_back(std::make_unique<TraceEvent>());
return events.back().get();
}
std::vector<std::unique_ptr<TraceEvent>> events;
TraceEvent* Create() { return google::protobuf::Arena::Create<TraceEvent>(&arena_); }
google::protobuf::Arena arena_;
};

struct DefaultStdHash {
Expand All @@ -609,6 +607,14 @@ class TraceEventsContainerBase {
void Merge(TraceEventsContainerBase&& other, int host_id);

// Creates a TraceEvent prefilled with the given values.
// Reserves capacity for events for a specific device and resource.
void ReserveEvents(uint32_t device_id, uint64_t resource_id, size_t count) {
if (count > 0) {
events_by_device_[device_id].events_by_resource[resource_id].reserve(
count);
}
}

void AddCompleteEvent(absl::string_view name, uint64_t resource_id,
uint32_t device_id, tsl::profiler::Timespan timespan,
RawData* raw_data = nullptr,
Expand Down
1 change: 1 addition & 0 deletions xprof/convert/xplane_to_trace_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void ConvertXLineToTraceEventsContainer(uint32_t device_id,
resource->set_resource_id(*resource_id);
resource->set_name(std::string(line.DisplayName()));
resource->set_num_events(line.NumEvents());
container->ReserveEvents(device_id, *resource_id, line.NumEvents());
}

RawData raw_data; // hoisted for performance
Expand Down