2 * libdpkg - Debian packaging suite library routines
3 * perf.h - performance testing support
5 * Copyright © 2009-2019 Guillem Jover <guillem@debian.org>
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
12 * This is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 #ifndef LIBDPKG_PERF_H
22 #define LIBDPKG_PERF_H
30 #define TEST_OMIT_VARIABLES
31 #include <dpkg/test.h>
36 struct timespec t_ini
, t_end
;
40 perf_ts_sub(struct timespec
*a
, struct timespec
*b
, struct timespec
*res
)
42 res
->tv_sec
= a
->tv_sec
- b
->tv_sec
;
43 res
->tv_nsec
= a
->tv_nsec
- b
->tv_nsec
;
44 if (res
->tv_nsec
< 0) {
46 res
->tv_nsec
+= 1000000000;
51 perf_ts_mark_print(const char *str
)
55 clock_gettime(CLOCK_MONOTONIC
, &ts
);
57 printf("%lu.%.9lu: %s\n", ts
.tv_sec
, ts
.tv_nsec
, str
);
61 perf_ts_slot_print(struct perf_slot
*ps
, const char *str
)
63 struct timespec t_res
;
65 perf_ts_sub(&ps
->t_end
, &ps
->t_ini
, &t_res
);
67 printf("%lu.%.9lu: %s (%lu.%.9lu sec)\n",
68 ps
->t_end
.tv_sec
, ps
->t_end
.tv_nsec
,
69 str
, t_res
.tv_sec
, t_res
.tv_nsec
);
72 #define perf_ts_slot_start(ps) clock_gettime(CLOCK_MONOTONIC, &((ps)->t_ini))
73 #define perf_ts_slot_stop(ps) clock_gettime(CLOCK_MONOTONIC, &((ps)->t_end))