• 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

17.51
/src/dftracer/utils/python/index_database.cpp
1
#include <dftracer/utils/core/common/transparent_string_hash.h>
2
#include <dftracer/utils/index/schemas/dft/agg/agg_store.h>
3
#include <dftracer/utils/index/schemas/dft/agg/association_tracker.h>
4
#include <dftracer/utils/index/store/index_database.h>
5
#include <dftracer/utils/index/store/index_database_sst_writer_context.h>
6
#include <dftracer/utils/python/index_database.h>
7
#include <dftracer/utils/python/py_agg_config.h>
8
#include <dftracer/utils/python/py_errors.h>
9
#include <dftracer/utils/python/py_list_helpers.h>
10
#include <dftracer/utils/python/py_method.h>
11
#include <dftracer/utils/python/py_runtime_mixin.h>
12
#include <dftracer/utils/python/py_str_helpers.h>
13
#include <dftracer/utils/python/py_type_helpers.h>
14
#include <dftracer/utils/python/sst_distribution.h>
15

16
#include <new>
17
#include <string>
18
#include <vector>
19

20
using dftracer::utils::index::store::IndexDatabase;
21
using dftracer::utils::index::store::SstArtifactRegistry;
22

23
static void IndexDatabase_dealloc(IndexDatabaseObject *self) {
4 ✔
24
    self->db.~shared_ptr<IndexDatabase>();
4 ✔
25
    Py_TYPE(self)->tp_free((PyObject *)self);
4 ✔
26
}
4 ✔
27

28
static PyObject *IndexDatabase_new(PyTypeObject *type, PyObject * /*args*/,
4 ✔
29
                                   PyObject * /*kwds*/) {
30
    auto *self = (IndexDatabaseObject *)type->tp_alloc(type, 0);
4 ✔
31
    if (!self) return NULL;
4 !
32
    new (&self->db) std::shared_ptr<IndexDatabase>();
4 ✔
33
    return (PyObject *)self;
4 ✔
34
}
35

36
static int IndexDatabase_init(IndexDatabaseObject *self, PyObject *args,
4 ✔
37
                              PyObject *kwds) {
38
    static const char *kwlist[] = {"index_path", NULL};
39
    const char *index_path;
40
    if (!PyArg_ParseTupleAndKeywords(
4 !
41
            args, kwds, "s", const_cast<char **>(kwlist), &index_path)) {
42
        return -1;
×
43
    }
44
    try {
45
        self->db = std::make_shared<IndexDatabase>(index_path);
4 !
46
    } catch (const std::exception &e) {
×
47
        dftracer::utils::python::set_typed_py_error(e);
×
48
        return -1;
×
49
    }
×
50
    return 0;
4 ✔
51
}
52

53
static PyObject *IndexDatabase_init_schema(IndexDatabaseObject *self,
×
54
                                           PyObject * /*ignored*/) {
55
    if (!self->db) {
×
56
        PyErr_SetString(PyExc_RuntimeError, "IndexDatabase not initialised");
×
57
        return NULL;
×
58
    }
59
    if (!run_blocking([&] { self->db->init_schema(); })) return NULL;
×
60
    Py_RETURN_NONE;
×
61
}
62

63
static PyObject *IndexDatabase_assign_file_ids(IndexDatabaseObject *self,
×
64
                                               PyObject *args, PyObject *kwds) {
65
    static const char *kwlist[] = {"paths", NULL};
66
    PyObject *paths_obj;
67
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O",
×
68
                                     const_cast<char **>(kwlist), &paths_obj)) {
69
        return NULL;
×
70
    }
71
    std::vector<std::string> paths;
×
72
    if (!parse_str_list(paths_obj, "paths", paths)) return NULL;
×
73

74
    std::vector<int> ids;
×
75
    if (!run_blocking_r([&] { return self->db->assign_file_ids(paths); },
×
76
                        ids)) {
77
        return NULL;
×
78
    }
79

80
    PyObject *out = PyList_New(static_cast<Py_ssize_t>(ids.size()));
×
81
    if (!out) return NULL;
×
82
    for (Py_ssize_t i = 0; i < static_cast<Py_ssize_t>(ids.size()); ++i) {
×
83
        PyList_SET_ITEM(out, i, PyLong_FromLong(ids[i]));
×
84
    }
85
    return out;
×
86
}
×
87

88
static PyObject *IndexDatabase_reserve_file_id_range(IndexDatabaseObject *self,
×
89
                                                     PyObject *args) {
90
    Py_ssize_t count;
91
    if (!PyArg_ParseTuple(args, "n", &count)) return NULL;
×
92
    if (count < 0) {
×
93
        PyErr_SetString(PyExc_ValueError, "count must be >= 0");
×
94
        return NULL;
×
95
    }
96
    int first;
97
    if (!run_blocking_r(
×
98
            [&] {
×
99
                return self->db->reserve_file_id_range(
×
100
                    static_cast<std::size_t>(count));
×
101
            },
102
            first)) {
103
        return NULL;
×
104
    }
105
    return PyLong_FromLong(first);
×
106
}
107

108
static PyObject *IndexDatabase_bulk_ingest(IndexDatabaseObject *self,
×
109
                                           PyObject *args, PyObject *kwds) {
110
    static const char *kwlist[] = {"registry", "skip_cfs", NULL};
111
    PyObject *registry_obj;
112
    PyObject *skip_cfs_obj = NULL;
×
113
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O",
×
114
                                     const_cast<char **>(kwlist), &registry_obj,
115
                                     &skip_cfs_obj)) {
116
        return NULL;
×
117
    }
118

119
    SstArtifactRegistry *registry =
120
        dftracer::utils::python::sst_artifact_registry_get(registry_obj);
×
121
    if (!registry) {
×
122
        PyErr_SetString(PyExc_TypeError,
×
123
                        "expected an SstArtifactRegistry instance");
124
        return NULL;
×
125
    }
126

127
    dftracer::utils::StringViewSet skip_cfs;
×
128
    if (skip_cfs_obj && skip_cfs_obj != Py_None) {
×
129
        PyObject *seq =
130
            PySequence_Fast(skip_cfs_obj, "skip_cfs must be an iterable");
×
131
        if (!seq) return NULL;
×
132
        Py_ssize_t n = PySequence_Fast_GET_SIZE(seq);
×
133
        for (Py_ssize_t i = 0; i < n; ++i) {
×
134
            PyObject *item = PySequence_Fast_GET_ITEM(seq, i);
×
135
            const char *s = as_utf8(item);
×
136
            if (!s) {
×
137
                Py_DECREF(seq);
138
                return NULL;
×
139
            }
140
            skip_cfs.emplace(s);
×
141
        }
142
        Py_DECREF(seq);
143
    }
144

145
    if (!run_blocking([&] { self->db->bulk_ingest(*registry, skip_cfs); }))
×
146
        return NULL;
×
147
    Py_RETURN_NONE;
×
148
}
×
149

150
static PyObject *IndexDatabase_write_agg_config(IndexDatabaseObject *self,
×
151
                                                PyObject *args) {
152
    PyObject *config_obj;
153
    if (!PyArg_ParseTuple(args, "O", &config_obj)) return NULL;
×
154
    const auto config = dftracer::utils::python::agg_config_from_py(config_obj);
×
155
    if (!run_blocking([&] {
×
156
            dftracer::utils::index::schemas::dft::agg::tier::write_config(
×
157
                *self->db->db(), {config.time_interval_us, config.params_hash(),
×
158
                                  config.group_by_file});
×
159
        }))
×
160
        return NULL;
×
161
    Py_RETURN_NONE;
×
162
}
×
163

164
static PyObject *IndexDatabase_write_aggregation_tracker(
×
165
    IndexDatabaseObject *self, PyObject *args) {
166
    PyObject *blobs_obj;
167
    if (!PyArg_ParseTuple(args, "O", &blobs_obj)) return NULL;
×
168
    PyObject *seq = PySequence_Fast(blobs_obj, "blobs must be an iterable");
×
169
    if (!seq) return NULL;
×
170
    Py_ssize_t n = PySequence_Fast_GET_SIZE(seq);
×
171
    std::vector<std::string> blobs;
×
172
    blobs.reserve(static_cast<std::size_t>(n));
×
173
    for (Py_ssize_t i = 0; i < n; ++i) {
×
174
        PyObject *item = PySequence_Fast_GET_ITEM(seq, i);
×
175
        if (item == Py_None) continue;
×
176
        char *buf = nullptr;
×
177
        Py_ssize_t len = 0;
×
178
        if (PyBytes_Check(item)) {
×
179
            if (PyBytes_AsStringAndSize(item, &buf, &len) < 0) {
×
180
                Py_DECREF(seq);
181
                return NULL;
×
182
            }
183
        } else {
184
            Py_DECREF(seq);
185
            PyErr_SetString(PyExc_TypeError,
×
186
                            "blobs entries must be bytes or None");
187
            return NULL;
×
188
        }
189
        if (len > 0) blobs.emplace_back(buf, static_cast<std::size_t>(len));
×
190
    }
191
    Py_DECREF(seq);
192
    if (!run_blocking([&] {
×
193
            using dftracer::utils::index::schemas::dft::agg::AssociationTracker;
194
            AssociationTracker unified;
×
195
            for (const auto &b : blobs)
×
196
                unified.merge(AssociationTracker::deserialize(b));
×
197
            unified.finalize();
×
198
            dftracer::utils::index::schemas::dft::agg::tier::write_tracker(
×
199
                *self->db->db(), unified.serialize());
×
200
        }))
×
201
        return NULL;
×
202
    Py_RETURN_NONE;
×
203
}
×
204

205
static PyObject *IndexDatabase_find_stale_files(IndexDatabaseObject *self,
4 ✔
206
                                                PyObject *args,
207
                                                PyObject *kwds) {
208
    static const char *kwlist[] = {"paths", NULL};
209
    PyObject *paths_obj;
210
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O",
4 !
211
                                     const_cast<char **>(kwlist), &paths_obj)) {
212
        return NULL;
×
213
    }
214
    std::vector<std::string> paths;
4 ✔
215
    if (!parse_str_list(paths_obj, "paths", paths)) return NULL;
4 !
216

217
    IndexDatabase::StaleCheckResult result;
4 ✔
218
    if (!run_blocking_r([&] { return self->db->find_stale_files(paths); },
8 !
219
                        result)) {
220
        return NULL;
×
221
    }
222

223
    PyObject *changed = str_list_from(result.changed);
4 !
224
    PyObject *added = str_list_from(result.added);
4 !
225
    PyObject *removed = str_list_from(result.removed);
4 !
226
    PyObject *d = PyDict_New();
4 !
227
    if (!changed || !added || !removed || !d) {
4 !
228
        Py_XDECREF(changed);
×
229
        Py_XDECREF(added);
×
230
        Py_XDECREF(removed);
×
231
        Py_XDECREF(d);
×
232
        return NULL;
×
233
    }
234
    PyObject *so = PyBool_FromLong(result.format_outdated);
4 !
235
    PyObject *st = PyBool_FromLong(result.stale());
4 !
236
    PyDict_SetItemString(d, "changed", changed);
4 !
237
    PyDict_SetItemString(d, "added", added);
4 !
238
    PyDict_SetItemString(d, "removed", removed);
4 !
239
    PyDict_SetItemString(d, "format_outdated", so);
4 !
240
    PyDict_SetItemString(d, "stale", st);
4 !
241
    Py_DECREF(changed);
242
    Py_DECREF(added);
243
    Py_DECREF(removed);
244
    Py_DECREF(so);
245
    Py_DECREF(st);
246
    return d;
4 ✔
247
}
4 ✔
248

249
static PyMethodDef IndexDatabase_methods[] = {
250
    {"init_schema", DFTU_PYCFUNCTION(IndexDatabase_init_schema), METH_NOARGS,
251
     "Idempotently write the format version and extension registry."},
252
    {"assign_file_ids", DFTU_PYCFUNCTION(IndexDatabase_assign_file_ids),
253
     METH_VARARGS | METH_KEYWORDS,
254
     "assign_file_ids(paths) -> list[int]\n"
255
     "The file_id of each path: its registered id, or a newly reserved one. "
256
     "The file record is written with the file's index data."},
257
    {"find_stale_files", DFTU_PYCFUNCTION(IndexDatabase_find_stale_files),
258
     METH_VARARGS | METH_KEYWORDS,
259
     "find_stale_files(paths) -> dict\n"
260
     "Stat-only (mtime + size) staleness check of the given trace paths "
261
     "against the index. Returns {changed, added, removed, format_outdated, "
262
     "stale}."},
263
    {"reserve_file_id_range",
264
     DFTU_PYCFUNCTION(IndexDatabase_reserve_file_id_range), METH_VARARGS,
265
     "reserve_file_id_range(count) -> int\n"
266
     "Atomically reserve `count` contiguous file_ids, return the first."},
267
    {"bulk_ingest", DFTU_PYCFUNCTION(IndexDatabase_bulk_ingest),
268
     METH_VARARGS | METH_KEYWORDS,
269
     "bulk_ingest(registry, skip_cfs=None) -> None\n"
270
     "Ingest all SSTs collected in the SstArtifactRegistry.\n"
271
     "skip_cfs is an optional iterable of CF names whose SSTs are left "
272
     "outside the unified DB (used by distributed builds to keep "
273
     "AGGREGATION/SYSTEM_METRICS SSTs addressable by manifest)."},
274
    {"write_agg_config", DFTU_PYCFUNCTION(IndexDatabase_write_agg_config),
275
     METH_VARARGS,
276
     "write_agg_config(aggregation_config) -> None\n"
277
     "Record the aggregation config a distributed build aggregated its "
278
     "files with. Each file's dftracer.agg entry comes with its SSTs."},
279
    {"write_aggregation_tracker",
280
     DFTU_PYCFUNCTION(IndexDatabase_write_aggregation_tracker), METH_VARARGS,
281
     "write_aggregation_tracker(blobs) -> None\n"
282
     "Merge a list of serialized AssociationTracker bytes and write the "
283
     "result to the aggregation tier."},
284
    {NULL}};
285

286
PyTypeObject IndexDatabaseType = {
287
    PyVarObject_HEAD_INIT(NULL, 0) "dftracer_utils_ext.IndexDatabase",
288
    sizeof(IndexDatabaseObject),
289
    0,
290
    (destructor)IndexDatabase_dealloc,
291
    0,
292
    0,
293
    0,
294
    0,
295
    0,
296
    0,
297
    0,
298
    0,
299
    0,
300
    0,
301
    0,
302
    0,
303
    0,
304
    0,
305
    Py_TPFLAGS_DEFAULT,
306
    "Handle to a .dftindex RocksDB store.",
307
    0,
308
    0,
309
    0,
310
    0,
311
    0,
312
    0,
313
    IndexDatabase_methods,
314
    0,
315
    0,
316
    0,
317
    0,
318
    0,
319
    0,
320
    0,
321
    (initproc)IndexDatabase_init,
322
    0,
323
    IndexDatabase_new,
324
};
325

326
int dftracer::utils::python::init_index_database(PyObject *m) {
7 ✔
327
    if (register_type(m, &IndexDatabaseType, "IndexDatabase") < 0) return -1;
7 !
328
    return 0;
7 ✔
329
}
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