allow rpm to custom systemd installation
[platform/upstream/rpm.git] / rpmio / rpmsw.h
1 #ifndef H_RPMSW
2 #define H_RPMSW
3
4 /** \ingroup rpmio
5  * \file rpmio/rpmsw.h
6  */
7
8 #include <unistd.h>
9 #include <sys/time.h>
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 /** \ingroup rpmsw
16  */
17 typedef unsigned long int rpmtime_t;
18
19 /** \ingroup rpmsw
20  */
21 typedef struct rpmsw_s * rpmsw;
22
23 /** \ingroup rpmsw
24  */
25 typedef struct rpmop_s * rpmop;
26
27 /** \ingroup rpmsw
28  */
29 struct rpmsw_s {
30     union {
31         struct timeval tv;
32         unsigned long long int ticks;
33         unsigned long int tocks[2];
34     } u;
35 };
36
37 /** \ingroup rpmsw
38  * Cumulative statistics for an operation.
39  */
40 struct rpmop_s {
41     struct rpmsw_s      begin;  /*!< Starting time stamp. */
42     int                 count;  /*!< Number of operations. */
43     size_t              bytes;  /*!< Number of bytes transferred. */
44     rpmtime_t           usecs;  /*!< Number of ticks. */
45 };
46
47 /** \ingroup rpmsw
48  * Return benchmark time stamp.
49  * @param *sw           time stamp
50  * @return              0 on success
51  */
52 rpmsw rpmswNow(rpmsw sw);
53
54 /** \ingroup rpmsw
55  * Return benchmark time stamp difference.
56  * @param *end          end time stamp
57  * @param *begin        begin time stamp
58  * @return              difference in micro-seconds
59  */
60 rpmtime_t rpmswDiff(rpmsw end, rpmsw begin);
61
62 /** \ingroup rpmsw
63  * Return benchmark time stamp overhead.
64  * @return              overhead in micro-seconds
65  */
66 rpmtime_t rpmswInit(void);
67
68 /** \ingroup rpmsw
69  * Enter timed operation.
70  * @param op                    operation statistics
71  * @param rc                    -1 clears usec counter
72  * @return                      0 always
73  */
74 int rpmswEnter(rpmop op, ssize_t rc);
75
76 /** \ingroup rpmsw
77  * Exit timed operation.
78  * @param op                    operation statistics
79  * @param rc                    per-operation data (e.g. bytes transferred)
80  * @return                      cumulative usecs for operation
81  */
82 rpmtime_t rpmswExit(rpmop op, ssize_t rc);
83
84 /** \ingroup rpmsw
85  * Sum statistic counters.
86  * @param to                    result statistics
87  * @param from                  operation statistics
88  * @return                      cumulative usecs for operation
89  */
90 rpmtime_t rpmswAdd(rpmop to, rpmop from);
91
92 /** \ingroup rpmsw
93  * Subtract statistic counters.
94  * @param to                    result statistics
95  * @param from                  operation statistics
96  * @return                      cumulative usecs for operation
97  */
98 rpmtime_t rpmswSub(rpmop to, rpmop from);
99
100 #ifdef __cplusplus
101 }
102 #endif
103
104 #endif  /* H_RPMSW */