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 15 SystemInfo::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 __get_system_info_etc(B_MEMORY_INFO, &fMemoryInfo, 28 sizeof(system_memory_info)); 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 41 SystemInfo::~SystemInfo() 42 { 43 } 44 45 46 uint64 47 SystemInfo::CachedMemory() const 48 { 49 #ifdef __HAIKU__ 50 return (uint64)fSystemInfo.cached_pages * B_PAGE_SIZE; 51 #else 52 return 0LL; 53 #endif 54 } 55 56 57 uint64 58 SystemInfo::UsedMemory() const 59 { 60 return (uint64)fSystemInfo.used_pages * B_PAGE_SIZE; 61 } 62 63 64 uint64 65 SystemInfo::MaxMemory() const 66 { 67 return (uint64)fSystemInfo.max_pages * B_PAGE_SIZE; 68 } 69 70 71 uint32 72 SystemInfo::PageFaults() const 73 { 74 return fMemoryInfo.page_faults; 75 } 76 77 78 uint64 79 SystemInfo::UsedSwapSpace() const 80 { 81 return fMemoryInfo.max_swap_space - fMemoryInfo.free_swap_space; 82 } 83 84 85 uint64 86 SystemInfo::MaxSwapSpace() const 87 { 88 return fMemoryInfo.max_swap_space; 89 } 90 91 92 uint32 93 SystemInfo::UsedSemaphores() const 94 { 95 return fSystemInfo.used_sems; 96 } 97 98 99 uint32 100 SystemInfo::MaxSemaphores() const 101 { 102 return fSystemInfo.max_sems; 103 } 104 105 106 uint32 107 SystemInfo::UsedPorts() const 108 { 109 return fSystemInfo.used_ports; 110 } 111 112 113 uint32 114 SystemInfo::MaxPorts() const 115 { 116 return fSystemInfo.max_ports; 117 } 118 119 120 uint32 121 SystemInfo::UsedThreads() const 122 { 123 return fSystemInfo.used_threads; 124 } 125 126 127 uint32 128 SystemInfo::MaxThreads() const 129 { 130 return fSystemInfo.max_threads; 131 } 132 133 134 uint32 135 SystemInfo::UsedTeams() const 136 { 137 return fSystemInfo.used_teams; 138 } 139 140 141 uint32 142 SystemInfo::MaxTeams() const 143 { 144 return fSystemInfo.max_teams; 145 } 146 147 148 void 149 SystemInfo::_RetrieveNetwork() 150 { 151 if (fRetrievedNetwork) 152 return; 153 154 fBytesReceived = 0; 155 fBytesSent = 0; 156 fRetrievedNetwork = true; 157 158 BNetworkRoster& roster = BNetworkRoster::Default(); 159 160 BNetworkInterface interface; 161 uint32 cookie = 0; 162 while (roster.GetNextInterface(&cookie, interface) == B_OK) { 163 ifreq_stats stats; 164 if (interface.GetStats(stats) == B_OK) { 165 fBytesReceived += stats.receive.bytes; 166 fBytesSent += stats.send.bytes; 167 } 168 } 169 } 170 171 172 uint64 173 SystemInfo::NetworkReceived() 174 { 175 _RetrieveNetwork(); 176 return fBytesReceived; 177 } 178 179 180 uint64 181 SystemInfo::NetworkSent() 182 { 183 _RetrieveNetwork(); 184 return fBytesSent; 185 } 186 187 188 uint32 189 SystemInfo::UsedRunningApps() const 190 { 191 return fRunningApps; 192 } 193 194 195 uint32 196 SystemInfo::MaxRunningApps() const 197 { 198 return fSystemInfo.max_teams; 199 } 200 201 202 uint32 203 SystemInfo::ClipboardSize() const 204 { 205 return fClipboardSize; 206 } 207 208 209 uint32 210 SystemInfo::ClipboardTextSize() const 211 { 212 return fClipboardTextSize; 213 } 214 215 216 uint32 217 SystemInfo::MediaNodes() const 218 { 219 return fMediaNodes; 220 } 221 222 223 uint32 224 SystemInfo::MediaConnections() const 225 { 226 return fMediaConnections; 227 } 228 229 230 uint32 231 SystemInfo::MediaBuffers() const 232 { 233 return fMediaBuffers; 234 } 235 236 237