1 /*!\file stats.cxx
2
3 \brief Statistics (fs, av, cache, etc.) routines
4
5 *//*
6
7 ClamFS - An user-space anti-virus protected file system
8 Copyright (C) 2008-2019 Krzysztof Burghardt
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25 #include "stats.hxx"
26
27 namespace clamfs {
28
Stats(time_t dumpEvery)29 Stats::Stats(time_t dumpEvery) {
30 earlyCacheHit = 0;
31 earlyCacheMiss = 0;
32 lateCacheHit = 0;
33 lateCacheMiss = 0;
34
35 whitelistHit = 0;
36 blacklistHit = 0;
37
38 tooBigFile = 0;
39
40 openCalled = 0;
41 openAllowed = 0;
42 openDenied = 0;
43
44 scanFailed = 0;
45
46 memoryStats = false;
47
48 lastdump = time(NULL);
49 every = dumpEvery;
50 }
51
~Stats()52 Stats::~Stats() {
53 }
54
dumpFilesystemStatsToLog()55 void Stats::dumpFilesystemStatsToLog() {
56 rLog(Info, "--- begin of filesystem statistics ---");
57 rLog(Info, "Early cache hit: %llu", earlyCacheHit);
58 rLog(Info, "Early cache miss: %llu", earlyCacheMiss);
59 rLog(Info, "Late cache hit: %llu", lateCacheHit);
60 rLog(Info, "Late cache miss: %llu", lateCacheMiss);
61 rLog(Info, "Whitelist hit: %llu", whitelistHit);
62 rLog(Info, "Blacklist hit: %llu", blacklistHit);
63 rLog(Info, "Files bigger than maximal-size: %llu", tooBigFile);
64 rLog(Info, "open() function called %llu times (allowed: %llu, denied: %llu)",
65 openCalled, openAllowed, openDenied);
66 rLog(Info, "Scan failed %llu times", scanFailed);
67 rLog(Info, "--- end of filesystem statistics ---");
68 }
69
dumpMemoryStatsToLog()70 void Stats::dumpMemoryStatsToLog() {
71 rLog(Info, "--- begin of memory statistics ---");
72 #ifdef HAVE_MALLINFO
73 struct mallinfo mi = mallinfo();
74 rLog(Info, "Non-mmapped space allocated (arena): %d", mi.arena);
75 rLog(Info, "Number of free chunks (ordblks): %d", mi.ordblks);
76 rLog(Info, "Number of free fastbin blocks (smblks): %d", mi.smblks);
77 rLog(Info, "Number of mmapped regions (hblks): %d", mi.hblks);
78 rLog(Info, "Space allocated in mmapped regions (hblkhd): %d", mi.hblkhd);
79 rLog(Info, "Maximum total allocated space (usmblks): %d", mi.usmblks);
80 rLog(Info, "Space in freed fastbin blocks (fsmblks): %d", mi.fsmblks);
81 rLog(Info, "Total allocated space (uordblks): %d", mi.uordblks);
82 rLog(Info, "Total free space (fordblks): %d", mi.fordblks);
83 rLog(Info, "Top-most, releasable space (keepcost): %d", mi.keepcost);
84 #else
85 rLog(Warn, "mallinfo() not available");
86 #endif
87 rLog(Info, "--- end of memory statistics ---");
88 }
89
periodicDumpToLog()90 void Stats::periodicDumpToLog() {
91 if (!every)
92 return;
93
94 time_t current = time(NULL);
95 if ((current - lastdump) > every) {
96 dumpFilesystemStatsToLog();
97 if (memoryStats)
98 dumpMemoryStatsToLog();
99 lastdump = current;
100 }
101 }
102
103 } /* namespace clamfs */
104
105 /* EoF */
106