| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/process/process_metrics.h" | |
| 6 | |
| 7 #include <mach/task.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 | |
| 11 namespace base { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 bool GetTaskInfo(task_basic_info_64* task_info_data) { | |
| 16 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT; | |
| 17 kern_return_t kr = task_info(mach_task_self(), | |
| 18 TASK_BASIC_INFO_64, | |
| 19 reinterpret_cast<task_info_t>(task_info_data), | |
| 20 &count); | |
| 21 return kr == KERN_SUCCESS; | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 ProcessMetrics::ProcessMetrics(ProcessHandle process) {} | |
| 27 | |
| 28 ProcessMetrics::~ProcessMetrics() {} | |
| 29 | |
| 30 // static | |
| 31 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { | |
| 32 return new ProcessMetrics(process); | |
| 33 } | |
| 34 | |
| 35 double ProcessMetrics::GetCPUUsage() { | |
| 36 NOTIMPLEMENTED(); | |
| 37 return 0; | |
| 38 } | |
| 39 | |
| 40 size_t ProcessMetrics::GetPagefileUsage() const { | |
| 41 task_basic_info_64 task_info_data; | |
| 42 if (!GetTaskInfo(&task_info_data)) | |
| 43 return 0; | |
| 44 return task_info_data.virtual_size; | |
| 45 } | |
| 46 | |
| 47 size_t ProcessMetrics::GetWorkingSetSize() const { | |
| 48 task_basic_info_64 task_info_data; | |
| 49 if (!GetTaskInfo(&task_info_data)) | |
| 50 return 0; | |
| 51 return task_info_data.resident_size; | |
| 52 } | |
| 53 | |
| 54 size_t GetMaxFds() { | |
| 55 static const rlim_t kSystemDefaultMaxFds = 256; | |
| 56 rlim_t max_fds; | |
| 57 struct rlimit nofile; | |
| 58 if (getrlimit(RLIMIT_NOFILE, &nofile)) { | |
| 59 // Error case: Take a best guess. | |
| 60 max_fds = kSystemDefaultMaxFds; | |
| 61 } else { | |
| 62 max_fds = nofile.rlim_cur; | |
| 63 } | |
| 64 | |
| 65 if (max_fds > INT_MAX) | |
| 66 max_fds = INT_MAX; | |
| 67 | |
| 68 return static_cast<size_t>(max_fds); | |
| 69 } | |
| 70 | |
| 71 void SetFdLimit(unsigned int max_descriptors) { | |
| 72 // Unimplemented. | |
| 73 } | |
| 74 | |
| 75 size_t GetPageSize() { | |
| 76 return getpagesize(); | |
| 77 } | |
| 78 | |
| 79 // Bytes committed by the system. | |
| 80 size_t GetSystemCommitCharge() { | |
| 81 NOTIMPLEMENTED(); | |
| 82 return 0; | |
| 83 } | |
| 84 | |
| 85 } // namespace base | |
| OLD | NEW |