OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/process/process_metrics.h" | 5 #include "base/process/process_metrics.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <sys/resource.h> | 10 #include <sys/resource.h> |
11 #include <sys/time.h> | 11 #include <sys/time.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 | 16 |
| 17 #if defined(OS_MACOSX) |
| 18 #include <malloc/malloc.h> |
| 19 #else |
| 20 #include <malloc.h> |
| 21 #endif |
| 22 |
17 namespace base { | 23 namespace base { |
18 | 24 |
19 int64_t TimeValToMicroseconds(const struct timeval& tv) { | 25 int64_t TimeValToMicroseconds(const struct timeval& tv) { |
20 int64_t ret = tv.tv_sec; // Avoid (int * int) integer overflow. | 26 int64_t ret = tv.tv_sec; // Avoid (int * int) integer overflow. |
21 ret *= Time::kMicrosecondsPerSecond; | 27 ret *= Time::kMicrosecondsPerSecond; |
22 ret += tv.tv_usec; | 28 ret += tv.tv_usec; |
23 return ret; | 29 return ret; |
24 } | 30 } |
25 | 31 |
26 ProcessMetrics::~ProcessMetrics() { } | 32 ProcessMetrics::~ProcessMetrics() { } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 82 } |
77 } else { | 83 } else { |
78 PLOG(INFO) << "Failed to get file descriptor limit"; | 84 PLOG(INFO) << "Failed to get file descriptor limit"; |
79 } | 85 } |
80 } | 86 } |
81 | 87 |
82 size_t GetPageSize() { | 88 size_t GetPageSize() { |
83 return getpagesize(); | 89 return getpagesize(); |
84 } | 90 } |
85 | 91 |
| 92 size_t ProcessMetrics::GetMallocUsage() { |
| 93 #if defined(OS_MACOSX) || defined(OS_IOS) |
| 94 malloc_statistics_t stats = {0}; |
| 95 malloc_zone_statistics(nullptr, &stats); |
| 96 return stats.size_in_use; |
| 97 #elif defined(OS_LINUX) || defined(OS_ANDROID) |
| 98 struct mallinfo minfo = mallinfo(); |
| 99 #if defined(USE_TCMALLOC) |
| 100 return minfo.uordblks; |
| 101 #else |
| 102 return minfo.hblkhd + minfo.arena; |
| 103 #endif |
| 104 #endif |
| 105 } |
| 106 |
86 } // namespace base | 107 } // namespace base |
OLD | NEW |