1/* 2 * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7#include "SystemInfo.h" 8 9#include <NetworkInterface.h> 10#include <NetworkRoster.h> 11 12#include "SystemInfoHandler.h" 13 14 15SystemInfo::SystemInfo(SystemInfoHandler* handler) 16 : 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) 25{ 26 get_system_info(&fSystemInfo); 27 fCPUInfos = new cpu_info[fSystemInfo.cpu_count]; 28 get_cpu_info(0, fSystemInfo.cpu_count, fCPUInfos); 29 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(); 37 } 38} 39 40 41SystemInfo::~SystemInfo() 42{ 43 delete[] fCPUInfos; 44} 45 46 47uint64 48SystemInfo::CachedMemory() const 49{ 50#ifdef __HAIKU__ 51 return fSystemInfo.cached_pages * B_PAGE_SIZE; 52#else 53 return 0LL; 54#endif 55} 56 57 58uint64 59SystemInfo::BlockCacheMemory() const 60{ 61 return fSystemInfo.block_cache_pages * B_PAGE_SIZE; 62} 63 64 65uint64 66SystemInfo::UsedMemory() const 67{ 68 return fSystemInfo.used_pages * B_PAGE_SIZE; 69} 70 71 72uint64 73SystemInfo::MaxMemory() const 74{ 75 return fSystemInfo.max_pages * B_PAGE_SIZE; 76} 77 78 79uint32 80SystemInfo::PageFaults() const 81{ 82 return fSystemInfo.page_faults; 83} 84 85 86uint64 87SystemInfo::UsedSwapSpace() const 88{ 89 return (fSystemInfo.max_swap_pages - fSystemInfo.free_swap_pages) 90 * B_PAGE_SIZE; 91} 92 93 94uint64 95SystemInfo::MaxSwapSpace() const 96{ 97 return fSystemInfo.max_swap_pages * B_PAGE_SIZE; 98} 99 100 101uint32 102SystemInfo::UsedSemaphores() const 103{ 104 return fSystemInfo.used_sems; 105} 106 107 108uint32 109SystemInfo::MaxSemaphores() const 110{ 111 return fSystemInfo.max_sems; 112} 113 114 115uint32 116SystemInfo::UsedPorts() const 117{ 118 return fSystemInfo.used_ports; 119} 120 121 122uint32 123SystemInfo::MaxPorts() const 124{ 125 return fSystemInfo.max_ports; 126} 127 128 129uint32 130SystemInfo::UsedThreads() const 131{ 132 return fSystemInfo.used_threads; 133} 134 135 136uint32 137SystemInfo::MaxThreads() const 138{ 139 return fSystemInfo.max_threads; 140} 141 142 143uint32 144SystemInfo::UsedTeams() const 145{ 146 return fSystemInfo.used_teams; 147} 148 149 150uint32 151SystemInfo::MaxTeams() const 152{ 153 return fSystemInfo.max_teams; 154} 155 156 157void 158SystemInfo::_RetrieveNetwork() 159{ 160 if (fRetrievedNetwork) 161 return; 162 163 fBytesReceived = 0; 164 fBytesSent = 0; 165 fRetrievedNetwork = true; 166 167 BNetworkRoster& roster = BNetworkRoster::Default(); 168 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; 176 } 177 } 178} 179 180 181uint64 182SystemInfo::NetworkReceived() 183{ 184 _RetrieveNetwork(); 185 return fBytesReceived; 186} 187 188 189uint64 190SystemInfo::NetworkSent() 191{ 192 _RetrieveNetwork(); 193 return fBytesSent; 194} 195 196 197uint32 198SystemInfo::UsedRunningApps() const 199{ 200 return fRunningApps; 201} 202 203 204uint32 205SystemInfo::MaxRunningApps() const 206{ 207 return fSystemInfo.max_teams; 208} 209 210 211uint32 212SystemInfo::ClipboardSize() const 213{ 214 return fClipboardSize; 215} 216 217 218uint32 219SystemInfo::ClipboardTextSize() const 220{ 221 return fClipboardTextSize; 222} 223 224 225uint32 226SystemInfo::MediaNodes() const 227{ 228 return fMediaNodes; 229} 230 231 232uint32 233SystemInfo::MediaConnections() const 234{ 235 return fMediaConnections; 236} 237 238 239uint32 240SystemInfo::MediaBuffers() const 241{ 242 return fMediaBuffers; 243} 244 245 246