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

llnl-asr / dftracer-utils / 38033748054

10 Oct 2026 07:14AM UTC coverage: 62.608% (+5.2%) from 57.391%
38033748054

push

github

rayandrew
ci: shard the test job

The coverage jobs ran 64 minutes of C++ tests in one process. Each shard
runs every n-th test with ctest -I, the Python tests and the type check
run in shard 1 only, and each shard uploads its own coverage report to
Coveralls, which merges the parallel uploads.

117733 of 235605 branches covered (49.97%)

Branch coverage included in aggregate %.

102379 of 115969 relevant lines covered (88.28%)

3014114.56 hits per line

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

50.94
/src/dftracer/utils/python/indexer.cpp
1
#include <dftracer/utils/core/runtime.h>
2
#include <dftracer/utils/core/tasks/coro_scope.h>
3
#include <dftracer/utils/index/build/batch_builder.h>
4
#include <dftracer/utils/index/gzip/checkpoint_indexer_factory.h>
5
#include <dftracer/utils/index/store/index_database.h>
6
#include <dftracer/utils/index/store/internal/helpers.h>
7
#include <dftracer/utils/python/indexer.h>
8
#include <dftracer/utils/python/py_errors.h>
9
#include <dftracer/utils/python/py_method.h>
10
#include <dftracer/utils/python/py_runtime_mixin.h>
11
#include <dftracer/utils/python/py_str_helpers.h>
12
#include <dftracer/utils/python/py_type_helpers.h>
13
#include <dftracer/utils/python/runtime.h>
14
#include <dftracer/utils/trace/internal/utils.h>
15
#include <structmember.h>
16

17
#include <cstring>
18
#include <memory>
19

20
static void CheckpointIndexer_dealloc(CheckpointIndexerObject *self) {
13 ✔
21
    if (self->handle) {
13 ✔
22
        // The Python wrapper owns only the native indexer handle. The
23
        // underlying RocksDB instance remains manager-owned and may continue to
24
        // live process-wide for the same .dftindex path.
25
        delete self->handle;
5 !
26
        self->handle = NULL;
5 ✔
27
    }
28
    Py_XDECREF(self->gz_path);
13 ✔
29
    Py_XDECREF(self->index_path);
13 ✔
30
    Py_XDECREF(self->runtime_obj);
13 ✔
31
    Py_TYPE(self)->tp_free((PyObject *)self);
13 ✔
32
}
13 ✔
33

34
static void CheckpointIndexer_release_handle(CheckpointIndexerObject *self) {
7 ✔
35
    if (self->handle) {
7 !
36
        // Releasing the handle drops this wrapper's native indexer state only.
37
        // Shared RocksDB lifetime is managed separately by RocksDBManager.
38
        delete self->handle;
7 !
39
        self->handle = NULL;
7 ✔
40
    }
41
}
7 ✔
42

43
static PyObject *CheckpointIndexer_new(PyTypeObject *type, PyObject *,
8 ✔
44
                                       PyObject *) {
45
    CheckpointIndexerObject *self;
46
    self = (CheckpointIndexerObject *)type->tp_alloc(type, 0);
8 ✔
47
    if (self != NULL) {
8 !
48
        self->handle = NULL;
8 ✔
49
        self->gz_path = NULL;
8 ✔
50
        self->index_path = NULL;
8 ✔
51
        self->checkpoint_size = 0;
8 ✔
52
        self->build_bloom = 0;
8 ✔
53
        self->runtime_obj = NULL;
8 ✔
54
    }
55
    return (PyObject *)self;
8 ✔
56
}
57

58
static int CheckpointIndexer_init(CheckpointIndexerObject *self, PyObject *args,
8 ✔
59
                                  PyObject *kwds) {
60
    static const char *kwlist[] = {"gz_path",
61
                                   "index_path",
62
                                   "checkpoint_size",
63
                                   "force_rebuild",
64
                                   "build_bloom",
65
                                   "runtime",
66
                                   NULL};
67
    const char *gz_path;
68
    const char *index_path = NULL;
8 ✔
69
    std::uint64_t checkpoint_size =
8 ✔
70
        dftracer::utils::constants::indexer::DEFAULT_CHECKPOINT_SIZE;
71
    int force_rebuild = 0;
8 ✔
72
    int build_bloom = 0;
8 ✔
73
    PyObject *runtime_arg = NULL;
8 ✔
74

75
    if (!PyArg_ParseTupleAndKeywords(
8 !
76
            args, kwds, "s|snppO", const_cast<char **>(kwlist), &gz_path,
77
            &index_path, &checkpoint_size, &force_rebuild, &build_bloom,
78
            &runtime_arg)) {
79
        return -1;
×
80
    }
81

82
    if (runtime_arg && runtime_arg != Py_None) {
8 !
83
        if (PyObject_TypeCheck(runtime_arg, &RuntimeType)) {
×
84
            Py_INCREF(runtime_arg);
×
85
            self->runtime_obj = runtime_arg;
×
86
        } else {
87
            PyObject *native = PyObject_GetAttrString(runtime_arg, "_native");
×
88
            if (native && PyObject_TypeCheck(native, &RuntimeType)) {
×
89
                self->runtime_obj = native;
×
90
            } else {
91
                Py_XDECREF(native);
×
92
                PyErr_SetString(PyExc_TypeError,
×
93
                                "runtime must be a Runtime instance or None");
94
                return -1;
×
95
            }
96
        }
97
    }
98

99
    self->gz_path = PyUnicode_FromString(gz_path);
8 !
100
    if (!self->gz_path) {
8 !
101
        return -1;
×
102
    }
103

104
    if (index_path) {
8 ✔
105
        self->index_path = PyUnicode_FromString(index_path);
7 !
106
    } else {
107
        const std::string resolved_index_path =
108
            dftracer::utils::trace::internal::determine_index_path(gz_path, "");
2 !
109
        self->index_path = PyUnicode_FromString(resolved_index_path.c_str());
1 !
110
    }
1 ✔
111

112
    if (!self->index_path) {
8 !
113
        Py_DECREF(self->gz_path);
×
114
        return -1;
×
115
    }
116

117
    self->checkpoint_size = checkpoint_size;
8 ✔
118
    self->build_bloom = build_bloom;
8 ✔
119

120
    const char *index_path_str = as_utf8(self->index_path);
8 !
121
    if (!index_path_str) {
8 !
122
        return -1;
×
123
    }
124

125
    try {
126
        auto indexer =
127
            dftracer::utils::index::gzip::CheckpointIndexerFactory::create(
128
                gz_path, index_path_str, checkpoint_size, force_rebuild != 0);
19 !
129
        if (!indexer) {
7 !
130
            PyErr_SetString(PyExc_RuntimeError, "Unsupported archive format");
×
131
            return -1;
×
132
        }
133
        self->handle = new std::shared_ptr<
7 ✔
134
            dftracer::utils::index::gzip::CheckpointIndexer>(
135
            std::move(indexer));
7 !
136
    } catch (const std::exception &e) {
8 !
137
        PyErr_SetString(PyExc_RuntimeError, e.what());
1 !
138
        return -1;
1 ✔
139
    }
1 ✔
140

141
    return 0;
7 ✔
142
}
143

144
static dftracer::utils::Runtime *get_indexer_runtime(
1 ✔
145
    CheckpointIndexerObject *self) {
146
    if (self->runtime_obj) {
1 !
147
        return ((RuntimeObject *)self->runtime_obj)->runtime.get();
×
148
    }
149
    return dftracer::utils::python::get_default_runtime();
1 ✔
150
}
151

152
static PyObject *CheckpointIndexer_build(CheckpointIndexerObject *self,
5 ✔
153
                                         PyObject *Py_UNUSED(ignored)) {
154
    if (!self->handle) {
5 !
155
        PyErr_SetString(PyExc_RuntimeError, "Indexer not initialized");
×
156
        return NULL;
×
157
    }
158

159
    // Use BatchBuilder when bloom is requested; otherwise build checkpoints
160
    // only.
161
    if (self->build_bloom) {
5 ✔
162
        using namespace dftracer::utils;
163
        using namespace dftracer::utils::index::build;
164
        using namespace dftracer::utils::index::store;
165

166
        const char *gz = as_utf8(self->gz_path);
1 !
167
        const char *idx = as_utf8(self->index_path);
1 !
168
        if (!gz || !idx) {
1 !
169
            return NULL;
×
170
        }
171

172
        auto batch_config = std::make_shared<IndexBuildBatchConfig>();
1 !
173
        batch_config->file_paths.emplace_back(gz);
1 !
174
        batch_config->checkpoint_size =
2 ✔
175
            static_cast<std::size_t>(self->checkpoint_size);
1 ✔
176
        batch_config->parallelism = 1;
1 ✔
177

178
        std::string idx_str(idx);
1 !
179
        auto pos = idx_str.find_last_of('/');
1 ✔
180
        if (pos != std::string::npos) {
1 !
181
            batch_config->index_dir = idx_str.substr(0, pos);
1 !
182
        }
183

184
        Runtime *rt = get_indexer_runtime(self);
1 !
185
        IndexBuildBatchResult batch_result;
1 ✔
186

187
        if (!run_blocking([&] {
1 !
188
                rt->submit(run_coro_scope(
3 !
189
                               rt->executor(),
1 ✔
190
                               [](CoroScope &scope,
1 !
191
                                  std::shared_ptr<IndexBuildBatchConfig> cfg,
192
                                  IndexBuildBatchResult *out)
193
                                   -> coro::CoroTask<void> {
194
                                   *out = co_await BatchBuilder::process(
195
                                       &scope, std::move(cfg));
196
                               },
2 !
197
                               batch_config, &batch_result),
1 ✔
198
                           "indexer-build")
199
                    .get();
1 !
200
            })) {
1 ✔
201
            return NULL;
×
202
        }
203

204
        if (batch_result.failed > 0 && !batch_result.results.empty()) {
1 !
205
            const auto &result = batch_result.results[0];
×
206
            if (!result.success) {
×
207
                PyErr_SetString(PyExc_RuntimeError,
×
208
                                result.error_message.c_str());
209
                return NULL;
×
210
            }
211
        }
212
    } else {
1 !
213
        // Simple checkpoint-only build
214
        std::string error;
4 ✔
215
        Py_BEGIN_ALLOW_THREADS try {
4 !
216
            (*self->handle)->build();
4 !
217
        } catch (const std::exception &e) {
×
218
            error = e.what();
×
219
        }
×
220
        Py_END_ALLOW_THREADS if (!error.empty()) {
4 !
221
            PyErr_SetString(PyExc_RuntimeError, error.c_str());
×
222
            return NULL;
×
223
        }
224
    }
4 !
225

226
    Py_RETURN_NONE;
5 ✔
227
}
228

229
static PyObject *CheckpointIndexer_need_rebuild(CheckpointIndexerObject *self,
6 ✔
230
                                                PyObject *Py_UNUSED(ignored)) {
231
    if (!self->handle) {
6 !
232
        PyErr_SetString(PyExc_RuntimeError, "Indexer not initialized");
×
233
        return NULL;
×
234
    }
235

236
    try {
237
        return PyBool_FromLong((*self->handle)->need_rebuild() ? 1 : 0);
6 !
238
    } catch (const std::exception &e) {
×
239
        PyErr_SetString(PyExc_RuntimeError, e.what());
×
240
        return NULL;
×
241
    }
×
242
}
243

244
static PyObject *CheckpointIndexer_exists(CheckpointIndexerObject *self,
×
245
                                          PyObject *Py_UNUSED(ignored)) {
246
    if (!self->handle) {
×
247
        PyErr_SetString(PyExc_RuntimeError, "Indexer not initialized");
×
248
        return NULL;
×
249
    }
250

251
    try {
252
        return PyBool_FromLong((*self->handle)->exists() ? 1 : 0);
×
253
    } catch (const std::exception &e) {
×
254
        PyErr_SetString(PyExc_RuntimeError, e.what());
×
255
        return NULL;
×
256
    }
×
257
}
258

259
static PyObject *CheckpointIndexer_get_max_bytes(CheckpointIndexerObject *self,
3 ✔
260
                                                 PyObject *Py_UNUSED(ignored)) {
261
    if (!self->handle) {
3 !
262
        PyErr_SetString(PyExc_RuntimeError, "Indexer not initialized");
×
263
        return NULL;
×
264
    }
265

266
    try {
267
        return PyLong_FromUnsignedLongLong((*self->handle)->get_max_bytes());
3 !
268
    } catch (const std::exception &e) {
×
269
        PyErr_SetString(PyExc_RuntimeError, e.what());
×
270
        return NULL;
×
271
    }
×
272
}
273

274
static PyObject *CheckpointIndexer_get_num_lines(CheckpointIndexerObject *self,
5 ✔
275
                                                 PyObject *Py_UNUSED(ignored)) {
276
    if (!self->handle) {
5 !
277
        PyErr_SetString(PyExc_RuntimeError, "Indexer not initialized");
×
278
        return NULL;
×
279
    }
280

281
    try {
282
        return PyLong_FromUnsignedLongLong((*self->handle)->get_num_lines());
5 !
283
    } catch (const std::exception &e) {
×
284
        PyErr_SetString(PyExc_RuntimeError, e.what());
×
285
        return NULL;
×
286
    }
×
287
}
288

289
static PyObject *CheckpointIndexer_has_bloom(CheckpointIndexerObject *self,
1 ✔
290
                                             void *) {
291
    const char *idx = as_utf8(self->index_path);
1 ✔
292
    const char *gz = as_utf8(self->gz_path);
1 ✔
293
    if (!idx || !gz) {
1 !
294
        Py_RETURN_FALSE;
×
295
    }
296
    try {
297
        using namespace dftracer::utils::index::build;
298
        using namespace dftracer::utils::index::store;
299
        using namespace dftracer::utils::index::store::internal;
300
        IndexDatabase db(
301
            idx, dftracer::utils::index::store::IndexOpenMode::ReadOnly);
2 !
302
        std::string logical = get_logical_path(gz);
1 !
303
        int fid = db.get_file_info_id(logical);
1 !
304
        if (fid >= 0 && db.pruning_tier_current(fid)) {
1 !
305
            Py_RETURN_TRUE;
1 ✔
306
        }
307
    } catch (...) {
2 !
308
    }
×
309
    Py_RETURN_FALSE;
×
310
}
311

312
static PyObject *CheckpointIndexer_gz_path(CheckpointIndexerObject *self,
3 ✔
313
                                           void *) {
314
    Py_INCREF(self->gz_path);
3 !
315
    return self->gz_path;
3 ✔
316
}
317

318
static PyObject *CheckpointIndexer_index_path(CheckpointIndexerObject *self,
2 ✔
319
                                              void *) {
320
    Py_INCREF(self->index_path);
2 !
321
    return self->index_path;
2 ✔
322
}
323

324
static PyObject *CheckpointIndexer_checkpoint_size(
2 ✔
325
    CheckpointIndexerObject *self, void *) {
326
    return PyLong_FromUnsignedLongLong(self->checkpoint_size);
2 ✔
327
}
328

329
static PyObject *CheckpointIndexer_enter(CheckpointIndexerObject *self,
6 !
330
                                         PyObject *Py_UNUSED(ignored)) {
331
    Py_INCREF(self);
332
    return (PyObject *)self;
6 ✔
333
}
334

335
static PyObject *CheckpointIndexer_close(CheckpointIndexerObject *self,
1 ✔
336
                                         PyObject *Py_UNUSED(ignored)) {
337
    CheckpointIndexer_release_handle(self);
1 ✔
338
    Py_RETURN_NONE;
1 ✔
339
}
340

341
static PyObject *CheckpointIndexer_exit(CheckpointIndexerObject *self,
6 ✔
342
                                        PyObject *) {
343
    CheckpointIndexer_release_handle(self);
6 ✔
344
    Py_RETURN_NONE;
6 ✔
345
}
346

347
static PyMethodDef CheckpointIndexer_methods[] = {
348
    {"build", DFTU_PYCFUNCTION(CheckpointIndexer_build), METH_NOARGS,
349
     "build()\n"
350
     "--\n"
351
     "\n"
352
     "Build or rebuild the index.\n"},
353
    {"need_rebuild", DFTU_PYCFUNCTION(CheckpointIndexer_need_rebuild),
354
     METH_NOARGS, "Check if a rebuild is needed."},
355
    {"exists", DFTU_PYCFUNCTION(CheckpointIndexer_exists), METH_NOARGS,
356
     "Check if the .dftindex store exists."},
357
    {"get_max_bytes", DFTU_PYCFUNCTION(CheckpointIndexer_get_max_bytes),
358
     METH_NOARGS, "Get the maximum uncompressed bytes in the indexed file."},
359
    {"get_num_lines", DFTU_PYCFUNCTION(CheckpointIndexer_get_num_lines),
360
     METH_NOARGS, "Get the total number of lines in the indexed file."},
361
    {"close", DFTU_PYCFUNCTION(CheckpointIndexer_close), METH_NOARGS,
362
     "Release this Python wrapper's native indexer handle.\n"
363
     "\n"
364
     "The shared RocksDB instance for the same .dftindex path remains managed\n"
365
     "by the native RocksDBManager cache."},
366
    {"__enter__", DFTU_PYCFUNCTION(CheckpointIndexer_enter), METH_NOARGS,
367
     "Enter the runtime context for the with statement."},
368
    {"__exit__", DFTU_PYCFUNCTION(CheckpointIndexer_exit), METH_VARARGS,
369
     "Release this Python wrapper on context exit.\n"
370
     "\n"
371
     "This does not force-close the shared RocksDB instance for the same\n"
372
     ".dftindex path."},
373
    {NULL} /* Sentinel */
374
};
375

376
static PyGetSetDef CheckpointIndexer_getsetters[] = {
377
    {"gz_path", (getter)CheckpointIndexer_gz_path, NULL,
378
     "Path to the gzip file", NULL},
379
    {"index_path", (getter)CheckpointIndexer_index_path, NULL,
380
     "Path to the .dftindex store", NULL},
381
    {"checkpoint_size", (getter)CheckpointIndexer_checkpoint_size, NULL,
382
     "Checkpoint size in bytes", NULL},
383
    {"has_bloom", (getter)CheckpointIndexer_has_bloom, NULL,
384
     "Whether bloom data exists in index", NULL},
385
    {NULL} /* Sentinel */
386
};
387

388
PyTypeObject CheckpointIndexerType = {
389
    PyVarObject_HEAD_INIT(
390
        NULL, 0) "dftracer_utils_ext.CheckpointIndexer", /* tp_name */
391
    sizeof(CheckpointIndexerObject),                     /* tp_basicsize */
392
    0,                                                   /* tp_itemsize */
393
    (destructor)CheckpointIndexer_dealloc,               /* tp_dealloc */
394
    0,                                        /* tp_vectorcall_offset */
395
    0,                                        /* tp_getattr */
396
    0,                                        /* tp_setattr */
397
    0,                                        /* tp_as_async */
398
    0,                                        /* tp_repr */
399
    0,                                        /* tp_as_number */
400
    0,                                        /* tp_as_sequence */
401
    0,                                        /* tp_as_mapping */
402
    0,                                        /* tp_hash */
403
    0,                                        /* tp_call */
404
    0,                                        /* tp_str */
405
    0,                                        /* tp_getattro */
406
    0,                                        /* tp_setattro */
407
    0,                                        /* tp_as_buffer */
408
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
409
    "CheckpointIndexer(gz_path, index_path=None, checkpoint_size=33554432, "
410
    "force_rebuild=False, build_bloom=False, runtime=None)\n"
411
    "--\n"
412
    "\n"
413
    "Checkpoint indexer for single-file checkpoint-level operations on a "
414
    "gzip trace.\n"
415
    "\n"
416
    "Args:\n"
417
    "    gz_path (str): Path to the gzip trace file.\n"
418
    "    index_path (str or None): Path to the .dftindex store. If None,\n"
419
    "        uses the root-local \".dftindex\" next to gz_path.\n"
420
    "    checkpoint_size (int): Checkpoint size in bytes for index\n"
421
    "        building (default 1 MB).\n"
422
    "    force_rebuild (bool): If True, rebuild the index even if it\n"
423
    "        exists.\n"
424
    "    build_bloom (bool): If True, build bloom filter data in the\n"
425
    "        index.\n"
426
    "    runtime (Runtime or None): Runtime instance for thread pool\n"
427
    "        control. If None, uses the default global Runtime.\n", /* tp_doc */
428
    0,                                /* tp_traverse */
429
    0,                                /* tp_clear */
430
    0,                                /* tp_richcompare */
431
    0,                                /* tp_weaklistoffset */
432
    0,                                /* tp_iter */
433
    0,                                /* tp_iternext */
434
    CheckpointIndexer_methods,        /* tp_methods */
435
    0,                                /* tp_members */
436
    CheckpointIndexer_getsetters,     /* tp_getset */
437
    0,                                /* tp_base */
438
    0,                                /* tp_dict */
439
    0,                                /* tp_descr_get */
440
    0,                                /* tp_descr_set */
441
    0,                                /* tp_dictoffset */
442
    (initproc)CheckpointIndexer_init, /* tp_init */
443
    0,                                /* tp_alloc */
444
    CheckpointIndexer_new,            /* tp_new */
445
};
446

447
int dftracer::utils::python::init_checkpoint_indexer(PyObject *m) {
7 ✔
448
    if (register_type(m, &CheckpointIndexerType, "CheckpointIndexer") < 0)
7 !
449
        return -1;
×
450

451
    return 0;
7 ✔
452
}
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