1 /*
2  * Copyright (c) 2015 Sippy Software, Inc., http://www.sippysoft.com
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27 
28 struct memdeb_stats {
29     int64_t nalloc;
30     int64_t balloc;
31     int64_t nunalloc_baseln;
32     int64_t bunalloc_baseln;
33     int64_t nfree;
34     int64_t bfree;
35     int64_t nrealloc;
36     int64_t brealloc;
37     int64_t afails;
38 };
39 
40 /* a += b */
41 #define RTPP_MD_STATS_ADD(a, b) { \
42     (a)->nalloc += (b)->nalloc; \
43     (a)->balloc += (b)->balloc; \
44     (a)->nunalloc_baseln += (b)->nunalloc_baseln; \
45     (a)->bunalloc_baseln += (b)->bunalloc_baseln; \
46     (a)->nfree += (b)->nfree; \
47     (a)->bfree += (b)->bfree; \
48     (a)->nrealloc += (b)->nrealloc; \
49     (a)->brealloc += (b)->brealloc; \
50     (a)->afails += (b)->afails; \
51 }
52 
53 /* a -= b */
54 #define RTPP_MD_STATS_SUB(a, b) { \
55     (a)->nalloc -= (b)->nalloc; \
56     (a)->balloc -= (b)->balloc; \
57     (a)->nunalloc_baseln -= (b)->nunalloc_baseln; \
58     (a)->bunalloc_baseln -= (b)->bunalloc_baseln; \
59     (a)->nfree -= (b)->nfree; \
60     (a)->bfree -= (b)->bfree; \
61     (a)->nrealloc -= (b)->nrealloc; \
62     (a)->brealloc -= (b)->brealloc; \
63     (a)->afails -= (b)->afails; \
64 }
65 
66 /* (a == b) ? 0: 1 */
67 #define RTPP_MD_STATS_CMP(a, b) ( \
68     (((a)->nalloc == (b)->nalloc) && \
69      ((a)->balloc == (b)->balloc) && \
70      ((a)->nunalloc_baseln == (b)->nunalloc_baseln) && \
71      ((a)->bunalloc_baseln == (b)->bunalloc_baseln) && \
72      ((a)->nfree == (b)->nfree) && \
73      ((a)->bfree == (b)->bfree) && \
74      ((a)->nrealloc == (b)->nrealloc) && \
75      ((a)->brealloc == (b)->brealloc) && \
76      ((a)->afails == (b)->afails)) ? 0 : 1)
77 
78 int rtpp_memdeb_get_stats(void *, const char *, const char *, struct memdeb_stats *);
79