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
14 changes: 13 additions & 1 deletion frontend/app/components/trace_viewer_v2/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
#include <stdlib.h>

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "xprof/frontend/app/components/trace_viewer_v2/timeline/data_provider.h"
#include "xprof/frontend/app/components/trace_viewer_v2/timeline/timeline.h"
#include "xprof/frontend/app/components/trace_viewer_v2/trace_helper/trace_event.h"
#include "xprof/frontend/app/components/trace_viewer_v2/webgpu_render_platform.h"
#include "absl/base/no_destructor.h"
#include "absl/time/clock.h"
Expand Down Expand Up @@ -43,13 +47,21 @@ class Application {
};
DataProvider& data_provider() { return data_provider_; };

void set_events(std::vector<TraceEvent> events) {
events_ = std::move(events);
}

std::vector<TraceEvent>& events() { return events_; }

private:
friend class absl::NoDestructor<Application>;

// Members are initialized to nullptr here and will be properly allocated in
// the Initialize() method.
Application() = default;

std::vector<TraceEvent> events_;

std::unique_ptr<WGPURenderPlatform> platform_;
std::unique_ptr<Timeline> timeline_;
// The data provider for trace events.
Expand All @@ -65,4 +77,4 @@ class Application {

} // namespace traceviewer

#endif // PERFTOOLS_ACCELERATORS_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_APPLICATION_H_
#endif // THIRD_PARTY_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_APPLICATION_H_
8 changes: 5 additions & 3 deletions frontend/app/components/trace_viewer_v2/event_data.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef PERFTOOLS_ACCELERATORS_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_EVENT_DATA_H_
#define PERFTOOLS_ACCELERATORS_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_EVENT_DATA_H_
#ifndef THIRD_PARTY_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_EVENT_DATA_H_
#define THIRD_PARTY_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_EVENT_DATA_H_

#include <any>
#include <string>
Expand All @@ -22,7 +22,9 @@ inline constexpr absl::string_view kEventSelected = "eventselected";

inline constexpr absl::string_view kEventSelectedIndex = "eventIndex";
inline constexpr absl::string_view kEventSelectedName = "name";
inline constexpr absl::string_view kEventSelectedStart = "start";
inline constexpr absl::string_view kEventSelectedDuration = "duration";

} // namespace traceviewer

#endif // PERFTOOLS_ACCELERATORS_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_EVENT_DATA_H_
#endif // THIRD_PARTY_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_EVENT_DATA_H_
62 changes: 62 additions & 0 deletions frontend/app/components/trace_viewer_v2/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export declare interface TraceViewerV2Module extends WasmModule {
processTraceEvents(data: TraceData): void;
loadJsonData?(url: string): Promise<void>;
getProcessList?(url: string): Promise<string[] | undefined>;
getEventData?(
name: string,
start: number,
duration: number,
): Promise<EventData|undefined>;
getHloModuleForEvent?(
name: string,
start: number,
duration: number,
): Promise<string>;
StringVector: {
size(): number;
get(index: number): string;
Expand All @@ -29,6 +39,17 @@ export declare interface TraceViewerV2Module extends WasmModule {
Instance(): {
data_provider(): {
getProcessList(): TraceViewerV2Module['StringVector'];
getEventMetaData(
name: string,
start: number,
duration: number,
): EventData |
undefined;
getHloModuleForEvent(
name: string,
start: number,
duration: number,
): string;
};
};
};
Expand All @@ -38,6 +59,14 @@ declare interface TraceData {
traceEvents: Array<{[key: string]: unknown}>;
}

declare interface EventData {
name: string;
processName: string;
start: number;
duration: number;
arguments: {[key: string]: string};
}

// Type guard to check if an object conforms to the TraceData interface
function isTraceData(data: unknown): data is TraceData {
return (
Expand Down Expand Up @@ -206,5 +235,38 @@ export async function traceViewerV2Main(): Promise<TraceViewerV2Module | null> {
return processArray;
};

traceviewerModule.getEventData = async(
name: string,
start: number,
duration: number,
): Promise<EventData|undefined> => {
try {
const eventData = traceviewerModule.Application.Instance()
.data_provider()
.getEventMetaData(name, start, duration);
return eventData || undefined;
} catch (e) {
console.error('Error in getEventData:', e);
return undefined;
}
};

traceviewerModule.getHloModuleForEvent = async(
name: string,
start: number,
duration: number,
): Promise<string> => {
try {
// Assuming Application.Instance().data_provider() exposes
// getHloModuleForEvent
const moduleName = traceviewerModule!.Application.Instance()
.data_provider()
.getHloModuleForEvent(name, start, duration);
return moduleName;
} catch (e) {
console.error('Error in getHloModuleForEvent:', e);
return '';
}
};
return traceviewerModule;
}
3 changes: 3 additions & 0 deletions frontend/app/components/trace_viewer_v2/timeline/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ cc_library(
"//util/gtl:comparator",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/log",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span",
"@org_xprof//frontend/app/components/trace_viewer_v2/trace_helper:trace_event",
Expand Down
Loading