aboutsummaryrefslogtreecommitdiff
path: root/src/zen/frontend/html/api.js
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-04-23 18:16:57 +0200
committerStefan Boberg <[email protected]>2026-04-23 18:16:57 +0200
commit0232b991cd7d8e3a2114ea30e4591dd3e7b65c36 (patch)
tree94730e7594fd09ae1fa820391ce311f6daf13905 /src/zen/frontend/html/api.js
parentFix forward declaration order for s_GotSigWinch and SigWinchHandler (diff)
parenttrace: declare Region event name fields as AnsiString (#1012) (diff)
downloadarchived-zen-sb/zen-help.tar.xz
archived-zen-sb/zen-help.zip
Merge branch 'main' into sb/zen-helpsb/zen-help
- Combine HelpCommand (this branch) with HistoryCommand (main) in zen CLI dispatcher - Keep filter-aware TuiPickOne rewrite; adopt main's ASCII arrow glyphs in doc comment
Diffstat (limited to 'src/zen/frontend/html/api.js')
-rw-r--r--src/zen/frontend/html/api.js137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/zen/frontend/html/api.js b/src/zen/frontend/html/api.js
new file mode 100644
index 000000000..fbe5304ca
--- /dev/null
+++ b/src/zen/frontend/html/api.js
@@ -0,0 +1,137 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+// Thin wrappers around the /api/* endpoints exposed by TraceViewerService.
+
+const API = "api/";
+
+const JSON_HEADERS = { Accept: "application/json" };
+
+async function getJson(path) {
+ const response = await fetch(API + path, { headers: JSON_HEADERS });
+ if (!response.ok) {
+ throw new Error(`${path}: HTTP ${response.status}`);
+ }
+ return response.json();
+}
+
+export function getSession() {
+ return getJson("session");
+}
+
+export function getThreads() {
+ return getJson("threads");
+}
+
+export function getChannels() {
+ return getJson("channels");
+}
+
+export function getScopeStats() {
+ return getJson("scope-stats");
+}
+
+export function getScopeNames() {
+ return getJson("scope-names");
+}
+
+export async function getTimeline(threadId, startUs, endUs, minDurUs = 0, resolution = 0, { signal } = {}) {
+ const params = new URLSearchParams({
+ thread: String(threadId),
+ start: String(startUs),
+ end: String(endUs),
+ });
+ if (minDurUs > 0) params.set("mindur", String(minDurUs));
+ if (resolution > 0) params.set("resolution", String(resolution));
+ const response = await fetch(API + "timeline?" + params.toString(), { signal, headers: JSON_HEADERS });
+ if (!response.ok) {
+ throw new Error(`timeline: HTTP ${response.status}`);
+ }
+ return response.json();
+}
+
+export async function getTimelineBatch(threadIds, startUs, endUs, minDurUs = 0, resolution = 0, { signal } = {}) {
+ let url = `${API}timeline-batch?threads=${threadIds.join(",")}&start=${startUs}&end=${endUs}`;
+ if (minDurUs > 0) url += `&mindur=${minDurUs}`;
+ if (resolution > 0) url += `&resolution=${resolution}`;
+ const response = await fetch(url, { signal, headers: JSON_HEADERS });
+ if (!response.ok) {
+ throw new Error(`timeline-batch: HTTP ${response.status}`);
+ }
+ return response.json();
+}
+
+export function getLogCategories() {
+ return getJson("log-categories");
+}
+
+export function getLogs({ startUs = 0, endUs = 0xffffffff, minVerbosity = 0, category = null, limit = 5000 } = {}) {
+ const params = new URLSearchParams({
+ start: String(startUs),
+ end: String(endUs),
+ min_verbosity: String(minVerbosity),
+ limit: String(limit),
+ });
+ if (category !== null && category !== undefined) {
+ params.set("category", String(category));
+ }
+ return getJson("logs?" + params.toString());
+}
+
+export function getBookmarks() {
+ return getJson("bookmarks");
+}
+
+export function getRegions() {
+ return getJson("regions");
+}
+
+export function getCsvCategories() {
+ return getJson("csv-categories");
+}
+
+export function getCsvStats() {
+ return getJson("csv-stats");
+}
+
+export function getCsvSeries(statId, threadId) {
+ let url = "csv-series?";
+ if (statId != null) url += `stat=${statId}&`;
+ if (threadId != null) url += `thread=${threadId}&`;
+ return getJson(url);
+}
+
+export function getCsvEvents() {
+ return getJson("csv-events");
+}
+
+export function getCsvMetadata() {
+ return getJson("csv-metadata");
+}
+
+export function getAllocSummary() {
+ return getJson("alloc-summary");
+}
+
+export function getMemoryTimeline({ startUs = 0, endUs = 0xffffffff, maxSamples = 2000 } = {}) {
+ const params = new URLSearchParams({
+ start: String(startUs),
+ end: String(endUs),
+ max_samples: String(maxSamples),
+ });
+ return getJson("memory-timeline?" + params.toString());
+}
+
+export function getCallstackStats(limit = 100) {
+ return getJson("callstack-stats?limit=" + encodeURIComponent(limit));
+}
+
+export function getChurnStats(limit = 100) {
+ return getJson("churn-stats?limit=" + encodeURIComponent(limit));
+}
+
+export function getCallstack(callstackId) {
+ return getJson("callstacks?id=" + encodeURIComponent(callstackId));
+}
+
+export function getAllocSizeHistogram() {
+ return getJson("alloc-size-histogram");
+}