• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

llnl / dftracer-utils / 29787659139

20 Jul 2026 11:34PM UTC coverage: 51.578% (-1.1%) from 52.66%
29787659139

Pull #99

github

web-flow
Merge ee805adeb into 06bc84ec9
Pull Request #99: Support CM time_metric (NS/MS/SEC/US) across reader and viz

34832 of 86278 branches covered (40.37%)

Branch coverage included in aggregate %.

1034 of 1319 new or added lines in 30 files covered. (78.39%)

5193 existing lines in 197 files now uncovered.

35349 of 49791 relevant lines covered (70.99%)

9765.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.55
/src/dftracer/utils/server/trace_api.cpp
1
#include <dftracer/utils/core/common/filesystem.h>
2
#include <dftracer/utils/core/common/logging.h>
3
#include <dftracer/utils/core/common/transparent_string_hash.h>
4
#include <dftracer/utils/core/coro/channel.h>
5
#include <dftracer/utils/core/pipeline/executor.h>
6
#include <dftracer/utils/core/tasks/coro_scope.h>
7
#include <dftracer/utils/server/cursor.h>
8
#include <dftracer/utils/server/http_request.h>
9
#include <dftracer/utils/server/http_response.h>
10
#include <dftracer/utils/server/json_builder.h>
11
#include <dftracer/utils/server/router.h>
12
#include <dftracer/utils/server/trace_api.h>
13
#include <dftracer/utils/server/trace_index.h>
14
#include <dftracer/utils/utilities/common/json/json_doc_guard.h>
15
#include <dftracer/utils/utilities/common/json/json_value.h>
16
#include <dftracer/utils/utilities/common/query/query.h>
17
#include <dftracer/utils/utilities/composites/dft/indexing/index_resolver_utility.h>
18
#include <dftracer/utils/utilities/composites/dft/internal/utils.h>
19
#include <dftracer/utils/utilities/composites/dft/statistics/shared_index_statistics_reader.h>
20
#include <dftracer/utils/utilities/composites/dft/statistics/statistics_aggregator_utility.h>
21
#include <dftracer/utils/utilities/composites/dft/statistics/statistics_query_utility.h>
22
#include <dftracer/utils/utilities/composites/dft/views/view_builder_utility.h>
23
#include <dftracer/utils/utilities/composites/dft/views/view_definition.h>
24
#include <dftracer/utils/utilities/composites/dft/views/view_reader_utility.h>
25
#include <dftracer/utils/utilities/fileio/lines/sources/async_streaming_gz_line_generator.h>
26
#include <simdjson.h>
27

28
#include <cstddef>
29
#include <limits>
30
#include <mutex>
31
#include <string>
32
#include <unordered_map>
33
#include <unordered_set>
34
#include <vector>
35

36
namespace dftracer::utils::server {
37

38
using namespace dftracer::utils::utilities::composites::dft;
39
using namespace dftracer::utils::utilities::composites::dft::indexing;
40
using namespace dftracer::utils::utilities::composites::dft::statistics;
41
using namespace dftracer::utils::utilities::composites::dft::views;
42

43
// Hash metadata types that need smart filtering (FH, HH, SH).
44
static const std::unordered_set<std::string> HASH_METADATA_NAMES = {"FH", "HH",
278!
45
                                                                    "SH"};
278!
46

47
using dftracer::utils::utilities::common::query::Query;
48

49
// --- GET /api/v1/files ---
50
static coro::CoroTask<HttpResponse> handle_files(const HttpRequest& /*req*/,
75!
51
                                                 const QueryParams& /*params*/,
52
                                                 TraceIndex& index) {
15!
53
    auto& b = scratch_json_builder();
15!
54
    b.start_object();
15✔
55
    b.escape_and_append_with_quotes("files");
15✔
56
    b.append_colon();
15✔
57
    b.start_array();
15✔
58
    bool first = true;
15✔
59
    for (const auto& f : index.files()) {
32!
60
        if (!first) b.append_comma();
17✔
61
        first = false;
17✔
62
        b.start_object();
17✔
63
        b.append_key_value("path", f.path);
17!
64
        b.append_comma();
17✔
65
        b.append_key_value("has_bloom_data", f.has_bloom_data);
17✔
66
        b.append_comma();
17✔
67
        b.append_key_value("has_checkpoint_index", f.has_checkpoint_index);
17✔
68
        b.end_object();
17✔
69
    }
17✔
70
    b.end_array();
15✔
71
    b.append_comma();
15✔
72
    b.append_key_value("count", static_cast<std::int64_t>(index.file_count()));
15!
73
    b.end_object();
15✔
74
    co_return HttpResponse::ok(std::string(b));
30!
75
}
15✔
76

77
// --- GET /api/v1/files/info ---
78
static coro::CoroTask<HttpResponse> handle_file_info(const HttpRequest& /*req*/,
14!
79
                                                     const QueryParams& params,
80
                                                     TraceIndex& index) {
2!
81
    auto file_param = params.get("file");
2!
82
    if (file_param.empty()) {
2✔
83
        co_return HttpResponse::bad_request("Missing required parameter: file");
3!
84
    }
85

86
    std::string file_path(file_param);
1!
87
    auto* info = index.find_file(file_path);
1!
88
    if (!info) {
1!
UNCOV
89
        co_return HttpResponse::not_found();
×
90
    }
91

92
    auto& b = scratch_json_builder();
1!
93
    b.start_object();
1✔
94
    b.append_key_value("path", info->path);
1!
95
    b.append_comma();
1✔
96
    b.append_key_value("has_bloom_data", info->has_bloom_data);
1✔
97
    b.append_comma();
1✔
98
    b.append_key_value("has_checkpoint_index", info->has_checkpoint_index);
1✔
99
    b.append_comma();
1✔
100
    b.append_key_value("size_mb", info->size_mb);
1✔
101
    b.append_comma();
1✔
102
    b.append_key_value("compressed_size",
2✔
103
                       static_cast<std::int64_t>(info->compressed_size));
1✔
104
    b.append_comma();
1✔
105
    b.append_key_value("num_lines", static_cast<std::int64_t>(info->num_lines));
1✔
106
    b.append_comma();
1✔
107
    b.append_key_value("num_checkpoints",
2✔
108
                       static_cast<std::int64_t>(info->num_checkpoints));
1✔
109
    b.append_comma();
1✔
110
    b.append_key_value("uncompressed_size",
2✔
111
                       static_cast<std::int64_t>(info->uncompressed_size));
1✔
112
    b.end_object();
1✔
113
    co_return HttpResponse::ok(std::string(b));
1!
114
}
2✔
115

116
static std::vector<std::string> split_csv(std::string_view s) {
×
117
    std::vector<std::string> result;
×
118
    std::string token;
×
119
    for (char c : s) {
×
120
        if (c == ',') {
×
121
            if (!token.empty()) result.push_back(token);
×
122
            token.clear();
×
UNCOV
123
        } else {
×
124
            token += c;
×
125
        }
126
    }
127
    if (!token.empty()) result.push_back(token);
×
128
    return result;
×
129
}
×
130

131
static std::string format_in_clause(const std::string& field,
×
132
                                    const std::vector<std::string>& vals) {
133
    if (vals.size() == 1) return field + " == \"" + vals[0] + "\"";
×
134
    std::string s = field + " in [";
×
135
    for (std::size_t i = 0; i < vals.size(); ++i) {
×
136
        if (i > 0) s += ", ";
×
137
        s += "\"" + vals[i] + "\"";
×
UNCOV
138
    }
×
139
    s += "]";
×
140
    return s;
×
141
}
×
142

143
static std::optional<Query> build_query_from_params(const QueryParams& params) {
6✔
144
    std::string dsl;
6✔
145

146
    auto cat = params.get("cat");
6!
147
    if (!cat.empty()) {
6!
148
        auto vals = split_csv(cat);
×
149
        if (!vals.empty()) dsl += format_in_clause("cat", vals);
×
150
    }
×
151

152
    auto name = params.get("name");
6!
153
    if (!name.empty()) {
6!
154
        auto vals = split_csv(name);
×
155
        if (!vals.empty()) {
×
156
            if (!dsl.empty()) dsl += " and ";
×
157
            dsl += format_in_clause("name", vals);
×
UNCOV
158
        }
×
159
    }
×
160

161
    auto pid = params.get("pid");
6!
162
    if (!pid.empty()) {
6!
163
        if (!dsl.empty()) dsl += " and ";
×
164
        dsl += "pid == " + std::string(pid);
×
UNCOV
165
    }
×
166

167
    double ts_min = params.get_double("ts_min", 0);
6!
168
    double ts_max = params.get_double("ts_max", 0);
6!
169
    if (ts_min > 0) {
6!
170
        if (!dsl.empty()) dsl += " and ";
×
171
        dsl += "ts >= " + std::to_string(static_cast<uint64_t>(ts_min));
×
UNCOV
172
    }
×
173
    if (ts_max > 0) {
6!
174
        if (!dsl.empty()) dsl += " and ";
×
175
        dsl += "ts <= " + std::to_string(static_cast<uint64_t>(ts_max));
×
UNCOV
176
    }
×
177

178
    double dur_min = params.get_double("dur_min", 0);
6!
179
    double dur_max = params.get_double("dur_max", 0);
6!
180
    if (dur_min > 0) {
6!
181
        if (!dsl.empty()) dsl += " and ";
×
182
        dsl += "dur >= " + std::to_string(static_cast<uint64_t>(dur_min));
×
UNCOV
183
    }
×
184
    if (dur_max > 0) {
6!
185
        if (!dsl.empty()) dsl += " and ";
×
186
        dsl += "dur <= " + std::to_string(static_cast<uint64_t>(dur_max));
×
UNCOV
187
    }
×
188

189
    if (dsl.empty()) return std::nullopt;
6!
190
    auto result = Query::from_string(dsl);
×
191
    if (!result) return std::nullopt;
×
192
    return std::move(*result);
×
193
}
6✔
194

195
static ViewDefinition build_view_from_params(const QueryParams& params) {
3✔
196
    ViewDefinition view;
3✔
197
    view.name = "api_query";
3!
198
    view.description = "HTTP API query";
3!
199

200
    auto q = build_query_from_params(params);
3!
201
    if (q) view.with_query(std::move(*q));
3!
202
    return view;
3✔
203
}
3!
204

205
// ============================================================================
206
// Shared helpers for event streaming endpoints
207
// ============================================================================
208

209
static std::vector<const TraceIndex::FileInfo*> resolve_target_files(
3✔
210
    TraceIndex& index, const QueryParams& params, double ts_min = 0,
211
    double ts_max = 0) {
212
    auto files = collect_candidate_files(index, params);
3✔
213

214
    if (ts_min > 0 || ts_max > 0) {
3!
215
        std::vector<const TraceIndex::FileInfo*> filtered;
×
216
        filtered.reserve(files.size());
×
217
        for (auto* fi : files) {
×
218
            if (fi->min_timestamp_us == 0 && fi->max_timestamp_us == 0) {
×
219
                filtered.push_back(fi);
×
220
                continue;
×
221
            }
222
            double fi_min = static_cast<double>(fi->min_timestamp_us);
×
223
            double fi_max = static_cast<double>(fi->max_timestamp_us);
×
224
            if (fi_max < ts_min || (ts_max > 0 && fi_min > ts_max)) continue;
×
225
            filtered.push_back(fi);
×
226
        }
227
        files = std::move(filtered);
×
228
    }
×
229

230
    return files;
3✔
231
}
3!
232

233
using StreamChunk = HttpResponse::StreamChunk;
234

235
static coro::AsyncGenerator<StreamChunk> stream_events(
27!
236
    std::vector<const TraceIndex::FileInfo*> files, ViewDefinition ev_view,
237
    std::optional<Query> /*query_opt*/, double ts_min, double ts_max,
238
    BloomFilterCache* bloom_cache, int limit, CancelToken cancel) {
3!
239
    int emitted = 0;
3✔
240

241
    for (auto* file_info : files) {
12✔
242
        if (cancel.cancelled()) co_return;
6!
243
        if (limit > 0 && emitted >= limit) break;
3!
244

245
        if (file_info->uncompressed_size == 0 &&
3!
UNCOV
246
            file_info->num_checkpoints == 0)
×
UNCOV
247
            continue;
×
248

249
        ViewBuilderInput builder_input;
3✔
250
        builder_input.with_view(ev_view)
6!
251
            .with_file_path(file_info->path)
3!
252
            .with_index_path(file_info->has_bloom_data ? file_info->index_path
3!
UNCOV
253
                                                       : "")
×
254
            .with_uncompressed_size(file_info->uncompressed_size)
3!
255
            .with_num_checkpoints(file_info->num_checkpoints)
3!
256
            .with_bloom_cache(bloom_cache)
3!
257
            .with_time_range(ts_min, ts_max);
3!
258

259
        ViewBuilderUtility builder;
3!
260
        auto build_output = co_await builder.process(builder_input);
6!
261
        if (!build_output || !build_output->file_may_match) continue;
3!
262

263
        for (const auto& candidate : build_output->candidates) {
12!
264
            if (limit > 0 && emitted >= limit) break;
3!
265

266
            ViewReaderInput reader_input;
3✔
267
            reader_input.with_file_path(file_info->path)
3!
268
                .with_index_path(file_info->index_path)
3!
269
                .with_byte_range(candidate.start_byte, candidate.end_byte)
3!
270
                .with_checkpoint_idx(candidate.checkpoint_idx)
3!
271
                .with_view(ev_view);
3!
272

273
            ViewReaderUtility reader;
3!
274
            auto event_gen = reader.process(reader_input);
3!
275
            while (auto batch = co_await event_gen.next()) {
24!
276
                if (cancel.cancelled()) co_return;
3!
277
                int count = std::min(
6!
278
                    static_cast<int>(batch->events.size()),
3✔
279
                    limit > 0 ? limit - emitted
3✔
280
                              : static_cast<int>(batch->events.size()));
2✔
281
                if (count > 0) {
3✔
282
                    co_yield StreamChunk{std::span<const std::string_view>(
21!
283
                        batch->events.data(), static_cast<std::size_t>(count))};
9✔
284
                    emitted += count;
3✔
285
                }
3✔
286
            }
12✔
287
        }
9✔
288
    }
9!
289
}
45!
290

291
// ============================================================================
292
// Event endpoints
293
// ============================================================================
294

295
// --- GET /api/v1/events ---
296
static coro::CoroTask<HttpResponse> handle_events(const HttpRequest& req,
5!
297
                                                  const QueryParams& params,
298
                                                  TraceIndex& index) {
1!
299
    int limit = params.get_int("limit", 1000);
1!
300
    if (limit <= 0) limit = 1000;
1!
301
    if (limit > 100000) limit = 100000;
1!
302

303
    double ts_min = params.get_double("ts_min", 0);
1!
304
    double ts_max = params.get_double("ts_max", 0);
1!
305
    auto files = resolve_target_files(index, params, ts_min, ts_max);
1!
306
    auto view = build_view_from_params(params);
1!
307
    auto query = build_query_from_params(params);
1!
308

309
    auto gen = std::make_unique<HttpResponse::StreamGenerator>(stream_events(
1!
310
        std::move(files), std::move(view), std::move(query), ts_min, ts_max,
1✔
311
        &index.bloom_cache(), limit, req.cancel_token));
1!
312

313
    auto resp = HttpResponse::streaming(std::move(gen));
1!
314
    resp.headers.push_back({"X-Limit", std::to_string(limit)});
1!
315
    co_return resp;
2✔
316
}
1✔
317

318
// --- GET /api/v1/events/stream ---
319
static coro::CoroTask<HttpResponse> handle_events_stream(
10!
320
    const HttpRequest& req, const QueryParams& params, TraceIndex& index) {
2!
321
    double ts_min = params.get_double("ts_min", 0);
2!
322
    double ts_max = params.get_double("ts_max", 0);
2!
323
    auto files = resolve_target_files(index, params, ts_min, ts_max);
2!
324
    auto view = build_view_from_params(params);
2!
325
    auto query = build_query_from_params(params);
2!
326
    int limit = params.get_int("limit", 0);
2!
327

328
    auto gen = std::make_unique<HttpResponse::StreamGenerator>(stream_events(
4!
329
        std::move(files), std::move(view), std::move(query), ts_min, ts_max,
2✔
330
        &index.bloom_cache(), limit, req.cancel_token));
2✔
331

332
    co_return HttpResponse::streaming(std::move(gen));
4!
333
}
2✔
334

335
// --- GET /api/v1/stats ---
336
static coro::CoroTask<HttpResponse> handle_stats(const HttpRequest& req,
5!
337
                                                 const QueryParams& /*params*/,
338
                                                 TraceIndex& index) {
1!
339
    static std::mutex cache_mutex;
1!
340
    static std::unordered_map<std::string, std::string,
1!
341
                              dftracer::utils::TransparentStringHash,
342
                              dftracer::utils::TransparentStringEqual>
343
        stats_cache;
1✔
344

345
    {
346
        std::lock_guard<std::mutex> lock(cache_mutex);
1!
347
        auto it = stats_cache.find(req.path);
1!
348
        if (it != stats_cache.end()) {
1!
349
            co_return HttpResponse::ok(it->second);
1!
350
        }
351
    }
1!
352

353
    std::vector<TraceStatistics> all_stats;
1✔
354

355
    // Group files by index_path
356
    std::unordered_map<std::string,
1✔
357
                       std::vector<std::pair<std::size_t, std::string>>>
358
        files_by_index;
1✔
359
    std::size_t file_idx = 0;
1✔
360
    for (const auto& file_info : index.files()) {
2✔
361
        if (!file_info.has_bloom_data) continue;
1!
362
        files_by_index[file_info.index_path].emplace_back(file_idx++,
1!
363
                                                          file_info.path);
1✔
364
    }
1!
365

366
    // Resolve each group and read statistics
367
    for (auto& [idx_path, files] : files_by_index) {
4!
368
        if (req.cancel_token.cancelled()) co_return HttpResponse::ok("{}");
3!
369
        std::vector<std::string> file_paths;
3✔
370
        file_paths.reserve(files.size());
3!
371
        for (const auto& [_, path] : files) {
4✔
372
            file_paths.push_back(path);
1!
373
        }
1✔
374

375
        IndexResolverUtility resolver;
3!
376
        ResolverInput input;
3✔
377
        input.files = std::move(file_paths);
3✔
378
        input.require_checkpoints = false;
3✔
379

380
        auto result = co_await resolver.process(input);
4!
381

382
        if (result.cached.empty()) {
3!
UNCOV
383
            continue;
×
384
        }
385

386
        try {
387
            SharedIndexStatisticsReader reader;
3✔
388
            auto batch_rows = co_await reader.query(
4!
389
                result.index_path, std::move(result.cached),
3!
390
                StatisticsQueryType::SUMMARY);
391
            auto callback = [&all_stats](std::size_t /*file_index*/,
2✔
392
                                         TraceStatistics&& stats) {
393
                if (stats.success) {
1!
394
                    all_stats.push_back(std::move(stats));
1✔
395
                }
1✔
396
            };
1✔
397
            SharedIndexStatisticsReader::process_batch_results(batch_rows,
1!
398
                                                               callback);
399
        } catch (const std::exception& e) {
1!
UNCOV
400
            DFTRACER_UTILS_LOG_WARN("Server stats batch read failed for %s: %s",
×
401
                                    idx_path.c_str(), e.what());
UNCOV
402
        }
×
403
    }
3!
404

405
    std::uint64_t total_events = 0;
1✔
406
    std::size_t file_count = all_stats.size();
1✔
407
    for (const auto& s : all_stats) {
2✔
408
        total_events += s.total_events();
1!
409
    }
1✔
410

411
    auto& sb = scratch_json_builder();
1!
412
    sb.start_object();
1✔
413
    sb.append_key_value("file_count", static_cast<std::int64_t>(file_count));
1✔
414
    sb.append_comma();
1✔
415
    sb.append_key_value("total_events",
2✔
416
                        static_cast<std::int64_t>(total_events));
1✔
417
    sb.append_comma();
1✔
418
    sb.escape_and_append_with_quotes("files");
1✔
419
    sb.append_colon();
1✔
420
    sb.start_array();
1✔
421
    for (std::size_t i = 0; i < all_stats.size(); ++i) {
2✔
422
        if (i > 0) sb.append_comma();
1!
423
        sb.append_raw(all_stats[i].to_json());  // already JSON
1!
424
    }
1✔
425
    sb.end_array();
1✔
426
    sb.end_object();
1✔
427
    std::string body(sb);
1!
428

429
    {
430
        std::lock_guard<std::mutex> lock(cache_mutex);
1!
431
        stats_cache.emplace(std::string(req.path), body);
1!
432
    }
1✔
433
    co_return HttpResponse::ok(body);
1!
434
}
9!
435

436
// --- GET /api/v1/info ---
437
static coro::CoroTask<HttpResponse> handle_info(const HttpRequest& /*req*/,
10!
438
                                                const QueryParams& /*params*/,
439
                                                TraceIndex& index) {
2!
440
    auto global_min_native = index.global_min_timestamp_us();
2!
441
    auto global_max_native = index.global_max_timestamp_us();
2!
442
    bool has_time_range =
4✔
443
        global_max_native > 0 &&
2!
444
        global_min_native != std::numeric_limits<std::uint64_t>::max();
2✔
445
    // Client works in microseconds; scale native (index-unit) bounds to us.
446
    auto global_min = index.native_to_us(global_min_native);
2!
447
    auto global_max = index.native_to_us(global_max_native);
2!
448

449
    auto& b = scratch_json_builder();
2!
450
    b.start_object();
2✔
451
    b.append_key_value("file_count",
4✔
452
                       static_cast<std::int64_t>(index.file_count()));
2✔
453

454
    if (has_time_range) {
2!
455
        b.append_comma();
2✔
456
        b.escape_and_append_with_quotes("time_range");
2✔
457
        b.append_colon();
2✔
458
        b.start_object();
2✔
459
        b.append_key_value("min_timestamp_us",
4✔
460
                           static_cast<std::int64_t>(global_min));
2✔
461
        b.append_comma();
2✔
462
        b.append_key_value("max_timestamp_us",
4✔
463
                           static_cast<std::int64_t>(global_max));
2✔
464
        b.end_object();
2✔
465
    }
2✔
466

467
    b.append_comma();
2✔
468
    b.escape_and_append_with_quotes("files");
2✔
469
    b.append_colon();
2✔
470
    b.start_array();
2✔
471
    bool first = true;
2✔
472
    for (const auto& f : index.files()) {
4✔
473
        if (!first) b.append_comma();
2!
474
        first = false;
2✔
475
        b.start_object();
2✔
476
        b.append_key_value("path", f.path);
2!
477
        b.append_comma();
2✔
478
        b.append_key_value("has_bloom_data", f.has_bloom_data);
2✔
479
        b.append_comma();
2✔
480
        b.append_key_value("has_checkpoint_index", f.has_checkpoint_index);
2✔
481
        if (f.min_timestamp_us > 0 || f.max_timestamp_us > 0) {
2!
482
            b.append_comma();
2✔
483
            b.append_key_value("min_timestamp_us",
2✔
484
                               static_cast<std::int64_t>(
485
                                   index.native_to_us(f.min_timestamp_us)));
2!
486
            b.append_comma();
2✔
487
            b.append_key_value("max_timestamp_us",
2✔
488
                               static_cast<std::int64_t>(
489
                                   index.native_to_us(f.max_timestamp_us)));
2!
490
        }
2✔
491
        b.end_object();
2✔
492
    }
2✔
493
    b.end_array();
2✔
494
    b.end_object();
2✔
495
    co_return HttpResponse::ok(std::string(b));
4!
496
}
2✔
497

498
void register_trace_api(Router& router, TraceIndex& index) {
8✔
499
    auto* index_ptr = &index;
8✔
500

501
    router.get(
16!
502
        "/api/v1/files",
8✔
503
        [index_ptr](const HttpRequest& req,
113!
504
                    const QueryParams& params) -> coro::CoroTask<HttpResponse> {
15!
505
            co_return co_await handle_files(req, params, *index_ptr);
75!
506
        },
30✔
507
        RouteDoc{
8✔
508
            "List the indexed trace files.",
8!
509
            "Trace data",
8!
510
            {},
8✔
511
            R"({"files":[{"path":"trace-0.pfw.gz","has_bloom_data":true}],)"
8!
512
            R"("count":1})"});
513

514
    router.get(
16!
515
        "/api/v1/files/info",
8✔
516
        [index_ptr](const HttpRequest& req,
22!
517
                    const QueryParams& params) -> coro::CoroTask<HttpResponse> {
2!
518
            co_return co_await handle_file_info(req, params, *index_ptr);
10!
519
        },
4✔
520
        RouteDoc{"Metadata for one trace file.",
16!
521
                 "Trace data",
8!
522
                 {{"file", "Trace file path", true, ""}},
8!
523
                 R"({"path":"trace-0.pfw.gz","has_bloom_data":true})"});
8!
524

525
    router.get(
16!
526
        "/api/v1/events",
8✔
527
        [index_ptr](const HttpRequest& req,
15!
528
                    const QueryParams& params) -> coro::CoroTask<HttpResponse> {
1!
529
            co_return co_await handle_events(req, params, *index_ptr);
5!
530
        },
2✔
531
        RouteDoc{"Query raw events as NDJSON (filtered, limited).",
16!
532
                 "Trace data",
8!
533
                 {{"file", "Trace file path", false, ""},
32!
534
                  {"name", "Filter by operation name", false, "read"},
8!
535
                  {"dur_min", "Minimum duration (us)", false, ""},
8!
536
                  {"limit", "Max events (0 = all)", false, "20"}},
8!
537
                 R"({"id":1,"name":"read","cat":"POSIX","pid":100,"tid":100,)"
8!
538
                 R"("ts":1000,"dur":150,"args":{"ret":4096}})"});
539

540
    router.get(
16!
541
        "/api/v1/events/stream",
8✔
542
        [index_ptr](const HttpRequest& req,
22!
543
                    const QueryParams& params) -> coro::CoroTask<HttpResponse> {
2!
544
            co_return co_await handle_events_stream(req, params, *index_ptr);
10!
545
        },
4✔
546
        RouteDoc{"Stream all matching events as NDJSON (no limit).",
16!
547
                 "Trace data",
8!
548
                 {{"name", "Filter by operation name", false, ""}},
8!
549
                 ""});
8!
550

551
    router.get(
16!
552
        "/api/v1/stats",
8✔
553
        [index_ptr](const HttpRequest& req,
15!
554
                    const QueryParams& params) -> coro::CoroTask<HttpResponse> {
1!
555
            co_return co_await handle_stats(req, params, *index_ptr);
5!
556
        },
2✔
557
        RouteDoc{"Aggregate statistics over the index.", "Trace data", {}, ""});
8!
558

559
    router.get(
16!
560
        "/api/v1/info",
8✔
561
        [index_ptr](const HttpRequest& req,
22!
562
                    const QueryParams& params) -> coro::CoroTask<HttpResponse> {
2!
563
            co_return co_await handle_info(req, params, *index_ptr);
10!
564
        },
4✔
565
        RouteDoc{"Global summary: file count and time bounds.",
8!
566
                 "Trace data",
8!
567
                 {},
8✔
568
                 R"({"file_count":2,"global_min_timestamp_us":1000000,)"
8!
569
                 R"("global_max_timestamp_us":6999732})"});
570

571
    router.post(
16!
572
        "/api/v1/cancel",
8✔
573
        [](const HttpRequest& /*req*/,
13!
574
           const QueryParams& params) -> coro::CoroTask<HttpResponse> {
1!
575
            std::string id(params.get("id"));
1!
576
            bool found = CancelRegistry::instance().cancel(id);
1!
577
            co_return HttpResponse::ok(std::string("{\"cancelled\":") +
3!
578
                                       (found ? "true" : "false") + "}");
1!
579
        },
1✔
580
        RouteDoc{"Cancel an in-flight request by its X-Request-Id.",
16!
581
                 "Control",
8!
582
                 {{"id", "Request id to cancel", true, ""}},
8!
583
                 R"({"cancelled":true})"});
8!
584
}
8✔
585

586
}  // namespace dftracer::utils::server
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc