]> git.ipfire.org Git - thirdparty/squid.git/blob - include/util.h
Refactor memory pools statistics gathering (#1186)
[thirdparty/squid.git] / include / util.h
1 /*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_UTIL_H
10 #define SQUID_UTIL_H
11
12 #if HAVE_ARPA_INET_H
13 #include <arpa/inet.h>
14 #endif
15
16 SQUIDCEXTERN void Tolower(char *);
17
18 SQUIDCEXTERN double xpercent(double part, double whole);
19 SQUIDCEXTERN int xpercentInt(double part, double whole);
20 SQUIDCEXTERN double xdiv(double nom, double denom);
21
22 SQUIDCEXTERN const char *xitoa(int num);
23 SQUIDCEXTERN const char *xint64toa(int64_t num);
24
25 typedef struct {
26 size_t count;
27 size_t bytes;
28 size_t gb;
29 } gb_t;
30
31 /* gb_type operations */
32 #define gb_flush_limit (0x3FFFFFFF)
33 #define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; }
34 #define gb_incb(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; }
35 #define gb_incc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->count+= delta; }
36 extern double gb_to_double(const gb_t *);
37 SQUIDCEXTERN const char *double_to_str(char *buf, int buf_size, double value);
38 extern const char *gb_to_str(const gb_t *);
39 extern void gb_flush(gb_t *); /* internal, do not use this */
40
41 SQUIDCEXTERN unsigned int RoundTo(const unsigned int num, const unsigned int what);
42
43 #endif /* SQUID_UTIL_H */
44