// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "trace_model.h" #include #include #include #include namespace zen::trace_detail { // Plain-data view of a single timeline scope returned by a TimelineQuery. // Mirrors the on-disk TimelineScope but is intentionally decoupled from the // in-memory model so that alternative backends can share the same result type. struct TimelineScopeView { uint32_t BeginUs; uint32_t DurationUs; uint32_t NameId; uint16_t Depth; uint16_t MergeCount; // 0 == raw LOD 0, N>0 == N merged scopes }; // Common parameters for a viewport-style timeline query. struct TimelineQueryRequest { uint32_t StartUs; uint32_t EndUs; uint32_t MinDurUs; uint32_t ResolutionUs; // 0 == LOD 0 (raw); >0 picks the smallest LOD with ResolutionUs >= this }; // Backend-agnostic interface for serving timeline scope data to the trace // viewer HTTP handlers. Currently only the in-memory implementation exists, // but the abstraction is preserved as a clean swap point if a different // backend (e.g. on-disk indexed store) ever becomes useful. class TimelineQuery { public: virtual ~TimelineQuery() = default; // Append all scopes for a single thread matching the request to Out. // Out is not cleared; callers can chain queries into the same buffer. virtual void QueryThread(uint32_t ThreadId, const TimelineQueryRequest& Req, std::vector& Out) const = 0; // Result of a batch query: a single flat scope vector plus per-thread // ranges into it. Ranges[i] corresponds to ThreadIds[i] from the request. struct BatchResult { struct Range { uint32_t Begin; uint32_t End; }; std::vector Scopes; std::vector Ranges; }; // Query several threads in one call. Out is cleared before being filled. virtual void QueryBatch(std::span ThreadIds, const TimelineQueryRequest& Req, BatchResult& Out) const = 0; }; // In-memory implementation. Holds a reference to Model — the model must // outlive the returned object. std::unique_ptr MakeInMemoryTimelineQuery(const TraceModel& Model); } // namespace zen::trace_detail