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

llnl / dftracer-utils / 28693295402

04 Jul 2026 03:17AM UTC coverage: 52.408% (+0.1%) from 52.278%
28693295402

push

github

hariharan-devarajan
feat: silence noisy warnings on aarch64

37318 of 92666 branches covered (40.27%)

Branch coverage included in aggregate %.

33462 of 42389 relevant lines covered (78.94%)

20557.64 hits per line

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

60.25
/src/dftracer/utils/python/utilities/statistics_query.cpp
1
#define PY_SSIZE_T_CLEAN
2
#include <dftracer/utils/core/coro/task.h>
3
#include <dftracer/utils/core/runtime.h>
4
#include <dftracer/utils/python/py_dict_helpers.h>
5
#include <dftracer/utils/python/py_runtime_mixin.h>
6
#include <dftracer/utils/python/py_type_helpers.h>
7
#include <dftracer/utils/python/runtime.h>
8
#include <dftracer/utils/python/utilities/statistics_query.h>
9
#include <dftracer/utils/utilities/composites/dft/internal/utils.h>
10
#include <dftracer/utils/utilities/composites/dft/statistics/statistics_aggregator_utility.h>
11
#include <dftracer/utils/utilities/composites/dft/statistics/statistics_query_utility.h>
12

13
#include <string>
14

15
using dftracer::utils::Runtime;
16
using dftracer::utils::coro::CoroTask;
17
using namespace dftracer::utils::utilities::composites::dft::statistics;
18

19
DFTRACER_UTILS_RUNTIME_BACKED_SLOTS(StatisticsQuery, StatisticsQueryObject)
48✔
20

21
static PyObject *StatisticsQuery_query(StatisticsQueryObject *self,
16✔
22
                                       PyObject *args, PyObject *kwds) {
23
    static const char *kwlist[] = {"file_path", "query_type", "top_n",
24
                                   "index_dir", NULL};
25
    const char *file_path;
26
    const char *query_type_str = "summary";
16✔
27
    Py_ssize_t top_n = 10;
16✔
28
    const char *index_dir = "";
16✔
29

30
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|sns", (char **)kwlist,
16!
31
                                     &file_path, &query_type_str, &top_n,
32
                                     &index_dir)) {
33
        return NULL;
×
34
    }
35

36
    StatisticsQueryType qt;
37
    if (strcmp(query_type_str, "summary") == 0) {
16✔
38
        qt = StatisticsQueryType::SUMMARY;
6✔
39
    } else if (strcmp(query_type_str, "categories") == 0) {
13✔
40
        qt = StatisticsQueryType::CATEGORIES;
4✔
41
    } else if (strcmp(query_type_str, "names") == 0) {
8✔
42
        qt = StatisticsQueryType::NAMES;
2✔
43
    } else if (strcmp(query_type_str, "pid_tids") == 0) {
5✔
44
        qt = StatisticsQueryType::PID_TIDS;
×
45
    } else if (strcmp(query_type_str, "time_range") == 0) {
4!
46
        qt = StatisticsQueryType::TIME_RANGE;
×
47
    } else if (strcmp(query_type_str, "duration_stats") == 0) {
4✔
48
        qt = StatisticsQueryType::DURATION_STATS;
2✔
49
    } else if (strcmp(query_type_str, "top_n_names") == 0) {
3✔
50
        qt = StatisticsQueryType::TOP_N_NAMES;
2✔
51
    } else if (strcmp(query_type_str, "top_n_categories") == 0) {
1!
52
        qt = StatisticsQueryType::TOP_N_CATEGORIES;
×
53
    } else if (strcmp(query_type_str, "detailed") == 0) {
×
54
        qt = StatisticsQueryType::DETAILED;
×
55
    } else {
56
        PyErr_Format(PyExc_ValueError, "unknown query_type: '%s'",
×
57
                     query_type_str);
58
        return NULL;
×
59
    }
60

61
    std::string file_path_str(file_path);
16!
62
    std::string index_dir_str(index_dir);
16!
63
    TraceStatistics stats;
16!
64
    StatisticsQueryOutput output;
16✔
65
    auto qt_copy = qt;
16✔
66
    auto top_n_copy = static_cast<std::uint64_t>(top_n);
16✔
67

68
    if (!run_blocking([&] {
24!
69
            Runtime *rt = resolve_runtime(self);
16!
70

71
            StatisticsAggregatorInput agg_input;
16✔
72
            agg_input.file_path = file_path_str;
16!
73
            agg_input.index_dir = index_dir_str;
16!
74
            agg_input.index_path = dftracer::utils::utilities::composites::dft::
8!
75
                internal::determine_index_path(file_path_str, index_dir_str);
16!
76

77
            auto *stats_p = &stats;
24✔
78
            auto agg_task = [stats_p, agg_input]() -> CoroTask<void> {
72!
79
                StatisticsAggregatorUtility util;
24!
80
                *stats_p = co_await util.process(agg_input);
32!
81
            };
48!
82
            rt->submit(agg_task(), "stats-agg").get();
16!
83

84
            StatisticsQueryInput query_input;
16!
85
            query_input.stats = std::move(stats);
16✔
86
            query_input.query_type = qt_copy;
16✔
87
            query_input.top_n = top_n_copy;
16✔
88

89
            auto *out_p = &output;
16✔
90
            auto query_task = [out_p, query_input]() -> CoroTask<void> {
72!
91
                StatisticsQueryUtility util;
24!
92
                *out_p = co_await util.process(query_input);
32!
93
            };
48!
94
            rt->submit(query_task(), "stats-query").get();
16!
95
        })) {
16✔
96
        return NULL;
×
97
    }
98

99
    PyObject *results_list =
8✔
100
        PyList_New(static_cast<Py_ssize_t>(output.results.size()));
16!
101
    if (!results_list) return NULL;
16✔
102

103
    for (std::size_t i = 0; i < output.results.size(); ++i) {
62✔
104
        PyObject *tup = PyTuple_New(2);
46!
105
        if (!tup) {
46!
106
            Py_DECREF(results_list);
×
107
            return NULL;
×
108
        }
109
        PyTuple_SET_ITEM(tup, 0,
46!
110
                         PyUnicode_FromString(output.results[i].first.c_str()));
111
        PyTuple_SET_ITEM(tup, 1,
46!
112
                         PyLong_FromUnsignedLongLong(output.results[i].second));
113
        PyList_SET_ITEM(results_list, static_cast<Py_ssize_t>(i), tup);
46!
114
    }
23✔
115

116
    PyObject *d = PyDict_New();
16!
117
    if (!d) {
16!
118
        Py_DECREF(results_list);
×
119
        return NULL;
×
120
    }
121

122
    int rc = 0;
16✔
123
    rc |= dict_set_str(d, "query_type", output.query_type_name.c_str());
16!
124
    rc |= dict_set_u64(d, "total_events", output.total_events);
16!
125
    rc |= dict_set_u64(d, "min_timestamp_us", output.min_timestamp_us);
16!
126
    rc |= dict_set_u64(d, "max_timestamp_us", output.max_timestamp_us);
16!
127
    rc |= dict_set_f64(d, "time_span_seconds", output.time_span_seconds);
16!
128
    rc |= dict_set_u64(d, "duration_count", output.duration_count);
16!
129
    rc |= dict_set_f64(d, "duration_mean_us", output.duration_mean_us);
16!
130
    rc |= dict_set_f64(d, "duration_stddev_us", output.duration_stddev_us);
16!
131
    rc |= dict_set_u64(d, "duration_min_us", output.duration_min_us);
16!
132
    rc |= dict_set_u64(d, "duration_max_us", output.duration_max_us);
16!
133
    // Steals (and always releases) the results_list reference.
134
    rc |= dict_set_steal(d, "results", results_list);
16!
135

136
    if (rc != 0) {
16!
137
        Py_DECREF(d);
×
138
        return NULL;
×
139
    }
140

141
    return d;
16✔
142
}
16✔
143

144
static PyObject *StatisticsQuery_call(PyObject *self, PyObject *args,
2✔
145
                                      PyObject *kwds) {
146
    return StatisticsQuery_query((StatisticsQueryObject *)self, args, kwds);
2✔
147
}
148

149
static PyMethodDef StatisticsQuery_methods[] = {
150
    {"process", (PyCFunction)StatisticsQuery_query,
151
     METH_VARARGS | METH_KEYWORDS,
152
     "process(file_path, query_type='summary', top_n=10, index_dir='')\n"
153
     "--\n"
154
     "\n"
155
     "Query statistics from an indexed trace file.\n"
156
     "\n"
157
     "Args:\n"
158
     "    file_path (str): Path to the trace file.\n"
159
     "    query_type (str): Query type (default 'summary'). One of\n"
160
     "        'summary', 'categories', 'names', 'pid_tids',\n"
161
     "        'time_range', 'duration_stats', 'top_n_names',\n"
162
     "        'top_n_categories', 'detailed'.\n"
163
     "    top_n (int): Top results for ranked queries (default 10).\n"
164
     "    index_dir (str): Directory for .dftindex stores (default '').\n"
165
     "\n"
166
     "Returns:\n"
167
     "    dict: Query results.\n"},
168
    {NULL}};
169

170
PyTypeObject StatisticsQueryUtilityType = {
171
    PyVarObject_HEAD_INIT(
172
        NULL, 0) "dftracer_utils_ext.StatisticsQueryUtility", /* tp_name */
173
    sizeof(StatisticsQueryObject),                            /* tp_basicsize */
174
    0,                                                        /* tp_itemsize */
175
    (destructor)StatisticsQuery_dealloc,                      /* tp_dealloc */
176
    0,                                        /* tp_vectorcall_offset */
177
    0,                                        /* tp_getattr */
178
    0,                                        /* tp_setattr */
179
    0,                                        /* tp_as_async */
180
    0,                                        /* tp_repr */
181
    0,                                        /* tp_as_number */
182
    0,                                        /* tp_as_sequence */
183
    0,                                        /* tp_as_mapping */
184
    0,                                        /* tp_hash */
185
    StatisticsQuery_call,                     /* tp_call */
186
    0,                                        /* tp_str */
187
    0,                                        /* tp_getattro */
188
    0,                                        /* tp_setattro */
189
    0,                                        /* tp_as_buffer */
190
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
191
    "StatisticsQueryUtility(runtime: Runtime | None = None)\n"
192
    "--\n\n"
193
    "Query pre-computed statistics from an indexed trace file.\n\n"
194
    "Args:\n"
195
    "    runtime (Runtime or None): Runtime for thread pool control.\n",
196
    0,                              /* tp_traverse */
197
    0,                              /* tp_clear */
198
    0,                              /* tp_richcompare */
199
    0,                              /* tp_weaklistoffset */
200
    0,                              /* tp_iter */
201
    0,                              /* tp_iternext */
202
    StatisticsQuery_methods,        /* tp_methods */
203
    0,                              /* tp_members */
204
    0,                              /* tp_getset */
205
    0,                              /* tp_base */
206
    0,                              /* tp_dict */
207
    0,                              /* tp_descr_get */
208
    0,                              /* tp_descr_set */
209
    0,                              /* tp_dictoffset */
210
    (initproc)StatisticsQuery_init, /* tp_init */
211
    0,                              /* tp_alloc */
212
    StatisticsQuery_new,            /* tp_new */
213
};
214

215
int init_statistics_query(PyObject *m) {
2✔
216
    if (register_type(m, &StatisticsQueryUtilityType,
2✔
217
                      "StatisticsQueryUtility") < 0)
2✔
218
        return -1;
×
219

220
    return 0;
2✔
221
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc