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