btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / activitymonitor / SystemInfo.cpp
blob482fa694c1088461e3d9d444123afc6e6d0d2a38
1 /*
2 * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "SystemInfo.h"
9 #include <NetworkInterface.h>
10 #include <NetworkRoster.h>
12 #include "SystemInfoHandler.h"
15 SystemInfo::SystemInfo(SystemInfoHandler* handler)
17 fTime(system_time()),
18 fRetrievedNetwork(false),
19 fRunningApps(0),
20 fClipboardSize(0),
21 fClipboardTextSize(0),
22 fMediaNodes(0),
23 fMediaConnections(0),
24 fMediaBuffers(0)
26 get_system_info(&fSystemInfo);
27 fCPUInfos = new cpu_info[fSystemInfo.cpu_count];
28 get_cpu_info(0, fSystemInfo.cpu_count, fCPUInfos);
30 if (handler != NULL) {
31 fRunningApps = handler->RunningApps();
32 fClipboardSize = handler->ClipboardSize();
33 fClipboardTextSize = handler->ClipboardTextSize();
34 fMediaNodes = handler->MediaNodes();
35 fMediaConnections = handler->MediaConnections();
36 fMediaBuffers = handler->MediaBuffers();
41 SystemInfo::~SystemInfo()
43 delete[] fCPUInfos;
47 uint64
48 SystemInfo::CachedMemory() const
50 #ifdef __HAIKU__
51 return fSystemInfo.cached_pages * B_PAGE_SIZE;
52 #else
53 return 0LL;
54 #endif
58 uint64
59 SystemInfo::BlockCacheMemory() const
61 return fSystemInfo.block_cache_pages * B_PAGE_SIZE;
65 uint64
66 SystemInfo::UsedMemory() const
68 return fSystemInfo.used_pages * B_PAGE_SIZE;
72 uint64
73 SystemInfo::MaxMemory() const
75 return fSystemInfo.max_pages * B_PAGE_SIZE;
79 uint32
80 SystemInfo::PageFaults() const
82 return fSystemInfo.page_faults;
86 uint64
87 SystemInfo::UsedSwapSpace() const
89 return (fSystemInfo.max_swap_pages - fSystemInfo.free_swap_pages)
90 * B_PAGE_SIZE;
94 uint64
95 SystemInfo::MaxSwapSpace() const
97 return fSystemInfo.max_swap_pages * B_PAGE_SIZE;
101 uint32
102 SystemInfo::UsedSemaphores() const
104 return fSystemInfo.used_sems;
108 uint32
109 SystemInfo::MaxSemaphores() const
111 return fSystemInfo.max_sems;
115 uint32
116 SystemInfo::UsedPorts() const
118 return fSystemInfo.used_ports;
122 uint32
123 SystemInfo::MaxPorts() const
125 return fSystemInfo.max_ports;
129 uint32
130 SystemInfo::UsedThreads() const
132 return fSystemInfo.used_threads;
136 uint32
137 SystemInfo::MaxThreads() const
139 return fSystemInfo.max_threads;
143 uint32
144 SystemInfo::UsedTeams() const
146 return fSystemInfo.used_teams;
150 uint32
151 SystemInfo::MaxTeams() const
153 return fSystemInfo.max_teams;
157 void
158 SystemInfo::_RetrieveNetwork()
160 if (fRetrievedNetwork)
161 return;
163 fBytesReceived = 0;
164 fBytesSent = 0;
165 fRetrievedNetwork = true;
167 BNetworkRoster& roster = BNetworkRoster::Default();
169 BNetworkInterface interface;
170 uint32 cookie = 0;
171 while (roster.GetNextInterface(&cookie, interface) == B_OK) {
172 ifreq_stats stats;
173 if (interface.GetStats(stats) == B_OK) {
174 fBytesReceived += stats.receive.bytes;
175 fBytesSent += stats.send.bytes;
181 uint64
182 SystemInfo::NetworkReceived()
184 _RetrieveNetwork();
185 return fBytesReceived;
189 uint64
190 SystemInfo::NetworkSent()
192 _RetrieveNetwork();
193 return fBytesSent;
197 uint32
198 SystemInfo::UsedRunningApps() const
200 return fRunningApps;
204 uint32
205 SystemInfo::MaxRunningApps() const
207 return fSystemInfo.max_teams;
211 uint32
212 SystemInfo::ClipboardSize() const
214 return fClipboardSize;
218 uint32
219 SystemInfo::ClipboardTextSize() const
221 return fClipboardTextSize;
225 uint32
226 SystemInfo::MediaNodes() const
228 return fMediaNodes;
232 uint32
233 SystemInfo::MediaConnections() const
235 return fMediaConnections;
239 uint32
240 SystemInfo::MediaBuffers() const
242 return fMediaBuffers;