| OLD | NEW | 
| (Empty) |  | 
 |   1 /* | 
 |   2  *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 
 |   3  * | 
 |   4  *  Use of this source code is governed by a BSD-style license | 
 |   5  *  that can be found in the LICENSE file in the root of the source | 
 |   6  *  tree. An additional intellectual property rights grant can be found | 
 |   7  *  in the file PATENTS.  All contributing project authors may | 
 |   8  *  be found in the AUTHORS file in the root of the source tree. | 
 |   9  */ | 
 |  10  | 
 |  11 #include "webrtc/base/memory_usage.h" | 
 |  12  | 
 |  13 #if defined(WEBRTC_LINUX) | 
 |  14 #include <unistd.h> | 
 |  15 #include <cstdlib> | 
 |  16 #include <cstdio> | 
 |  17 #include <cstring> | 
 |  18 #elif defined(WEBRTC_MAC) | 
 |  19 #include <mach/mach.h> | 
 |  20 #elif defined(WEBRTC_WIN) | 
 |  21 #include <windows.h> | 
 |  22 #include <psapi.h> | 
 |  23 #endif | 
 |  24  | 
 |  25 #include "webrtc/base/logging.h" | 
 |  26  | 
 |  27 namespace rtc { | 
 |  28  | 
 |  29 int64_t GetProcessResidentSizeBytes() { | 
 |  30 #if defined(WEBRTC_LINUX) | 
 |  31   FILE* file = fopen("/proc/self/statm", "r"); | 
 |  32   if (file == nullptr) { | 
 |  33     LOG(LS_ERROR) << "Failed to open /proc/self/statm"; | 
 |  34     return -1; | 
 |  35   } | 
 |  36   int result = -1; | 
 |  37   if (fscanf(file, "%*s%d", &result) != 1) { | 
 |  38     fclose(file); | 
 |  39     LOG(LS_ERROR) << "Failed to parse /proc/self/statm"; | 
 |  40     return -1; | 
 |  41   } | 
 |  42   fclose(file); | 
 |  43   return static_cast<int64_t>(result) * sysconf(_SC_PAGESIZE); | 
 |  44 #elif defined(WEBRTC_MAC) | 
 |  45   task_basic_info_64 info; | 
 |  46   mach_msg_type_number_t info_count = TASK_BASIC_INFO_64_COUNT; | 
 |  47   if (task_info(mach_task_self(), TASK_BASIC_INFO_64, | 
 |  48                 reinterpret_cast<task_info_t>(&info), | 
 |  49                 &info_count) != KERN_SUCCESS) { | 
 |  50     LOG_ERR(LS_ERROR) << "task_info() failed"; | 
 |  51     return -1; | 
 |  52   } | 
 |  53   return info.resident_size; | 
 |  54 #elif defined(WEBRTC_WIN) | 
 |  55   PROCESS_MEMORY_COUNTERS pmc; | 
 |  56   if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)) == 0) { | 
 |  57     LOG_ERR(LS_ERROR) << "GetProcessMemoryInfo() failed"; | 
 |  58     return -1; | 
 |  59   } | 
 |  60   return pmc.WorkingSetSize; | 
 |  61 #else | 
 |  62   // Not implemented yet. | 
 |  63   static_assert(false, | 
 |  64                 "GetProcessVirtualMemoryUsageBytes() platform support not yet " | 
 |  65                 "implemented."); | 
 |  66 #endif | 
 |  67 } | 
 |  68  | 
 |  69 }  // namespace rtc | 
| OLD | NEW |