Changeset 46324 in vbox for trunk/src/VBox/Runtime/r3/linux/systemmem-linux.cpp
- Timestamp:
- May 30, 2013 12:03:16 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/linux/systemmem-linux.cpp
r45104 r46324 34 34 #include <iprt/err.h> 35 35 #include <iprt/assert.h> 36 #include <iprt/string.h> 36 37 38 #include <stdio.h> 37 39 #include <errno.h> 38 40 … … 62 64 AssertPtrReturn(pcb, VERR_INVALID_POINTER); 63 65 66 FILE *pFile = fopen("/proc/meminfo", "r"); 67 if (pFile) 68 { 69 int rc = VERR_NOT_FOUND; 70 uint64_t cbTotal = 0; 71 uint64_t cbFree = 0; 72 uint64_t cbBuffers = 0; 73 uint64_t cbCached = 0; 74 char sz[256]; 75 while (fgets(sz, sizeof(sz), pFile)) 76 { 77 if (!strncmp(sz, RT_STR_TUPLE("MemTotal:"))) 78 rc = RTStrToUInt64Ex(RTStrStripL(&sz[sizeof("MemTotal:")]), NULL, 0, &cbTotal); 79 else if (!strncmp(sz, RT_STR_TUPLE("MemFree:"))) 80 rc = RTStrToUInt64Ex(RTStrStripL(&sz[sizeof("MemFree:")]), NULL, 0, &cbFree); 81 else if (!strncmp(sz, RT_STR_TUPLE("Buffers:"))) 82 rc = RTStrToUInt64Ex(RTStrStripL(&sz[sizeof("Buffers:")]), NULL, 0, &cbBuffers); 83 else if (!strncmp(sz, RT_STR_TUPLE("Cached:"))) 84 rc = RTStrToUInt64Ex(RTStrStripL(&sz[sizeof("Cached:")]), NULL, 0, &cbCached); 85 if (RT_FAILURE(rc)) 86 break; 87 } 88 fclose(pFile); 89 if (RT_SUCCESS(rc)) 90 { 91 *pcb = (cbFree + cbBuffers + cbCached) * _1K; 92 return VINF_SUCCESS; 93 } 94 } 95 /* 96 * Fallback (e.g. /proc not mapped) to sysinfo. Less accurat because there 97 * is no information about the cached memory. 'Cached:' from above is only 98 * accessible through proc :-( 99 */ 64 100 struct sysinfo info; 65 101 int rc = sysinfo(&info); 66 102 if (rc == 0) 67 103 { 68 /** @todo Actually this is not quite correct. We would also need to add the69 * cached RAM but this information is not available in sysinfo. */70 104 *pcb = ((uint64_t)info.freeram + info.bufferram) * info.mem_unit; 71 105 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.