// 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 getCounters() { return getJson("counters"); } export function getCounterSeries(id) { return getJson(`counter-series?id=${encodeURIComponent(id)}`); } 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"); }