/Users/deen/code/yugabyte-db/src/yb/server/tcmalloc_metrics.cc
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | #include "yb/server/tcmalloc_metrics.h" |
33 | | |
34 | | #include <glog/logging.h> |
35 | | #ifdef TCMALLOC_ENABLED |
36 | | #include <gperftools/malloc_extension.h> |
37 | | #endif |
38 | | |
39 | | #include "yb/gutil/bind.h" |
40 | | |
41 | | #include "yb/util/metrics.h" |
42 | | |
43 | | #ifndef TCMALLOC_ENABLED |
44 | | #define TCM_ASAN_MSG " (Disabled - no tcmalloc in this build)" |
45 | | #else |
46 | | #define TCM_ASAN_MSG |
47 | | #endif |
48 | | |
49 | | // As of this writing, we expose all of the un-deprecated tcmalloc status metrics listed at: |
50 | | // http://gperftools.googlecode.com/svn/trunk/doc/tcmalloc.html |
51 | | |
52 | | METRIC_DEFINE_gauge_uint64(server, generic_current_allocated_bytes, |
53 | | "Heap Memory Usage", yb::MetricUnit::kBytes, |
54 | | "Number of bytes used by the application. This will not typically match the memory " |
55 | | "use reported by the OS, because it does not include TCMalloc overhead or memory " |
56 | | "fragmentation." TCM_ASAN_MSG); |
57 | | |
58 | | METRIC_DEFINE_gauge_uint64(server, generic_heap_size, |
59 | | "Reserved Heap Memory", yb::MetricUnit::kBytes, |
60 | | "Bytes of system memory reserved by TCMalloc." TCM_ASAN_MSG); |
61 | | |
62 | | METRIC_DEFINE_gauge_uint64(server, tcmalloc_pageheap_free_bytes, |
63 | | "Free Heap Memory", yb::MetricUnit::kBytes, |
64 | | "Number of bytes in free, mapped pages in page heap. These bytes can be used to " |
65 | | "fulfill allocation requests. They always count towards virtual memory usage, and " |
66 | | "unless the underlying memory is swapped out by the OS, they also count towards " |
67 | | "physical memory usage." TCM_ASAN_MSG); |
68 | | |
69 | | METRIC_DEFINE_gauge_uint64(server, tcmalloc_pageheap_unmapped_bytes, |
70 | | "Unmapped Heap Memory", yb::MetricUnit::kBytes, |
71 | | "Number of bytes in free, unmapped pages in page heap. These are bytes that have " |
72 | | "been released back to the OS, possibly by one of the MallocExtension \"Release\" " |
73 | | "calls. They can be used to fulfill allocation requests, but typically incur a page " |
74 | | "fault. They always count towards virtual memory usage, and depending on the OS, " |
75 | | "typically do not count towards physical memory usage." TCM_ASAN_MSG); |
76 | | |
77 | | METRIC_DEFINE_gauge_uint64(server, tcmalloc_max_total_thread_cache_bytes, |
78 | | "Thread Cache Memory Limit", yb::MetricUnit::kBytes, |
79 | | "A limit to how much memory TCMalloc dedicates for small objects. Higher numbers " |
80 | | "trade off more memory use for -- in some situations -- improved efficiency." TCM_ASAN_MSG); |
81 | | |
82 | | METRIC_DEFINE_gauge_uint64(server, tcmalloc_current_total_thread_cache_bytes, |
83 | | "Thread Cache Memory Usage", yb::MetricUnit::kBytes, |
84 | | "A measure of some of the memory TCMalloc is using (for small objects)." TCM_ASAN_MSG); |
85 | | |
86 | | #undef TCM_ASAN_MSG |
87 | | |
88 | | namespace yb { |
89 | | namespace tcmalloc { |
90 | | |
91 | 91.9k | static uint64_t GetTCMallocPropValue(const char* prop) { |
92 | 91.9k | size_t value = 0; |
93 | | #ifdef TCMALLOC_ENABLED |
94 | | if (!MallocExtension::instance()->GetNumericProperty(prop, &value)) { |
95 | | LOG(DFATAL) << "Failed to get value of numeric tcmalloc property: " << prop; |
96 | | } |
97 | | #endif |
98 | 91.9k | return value; |
99 | 91.9k | } |
100 | | |
101 | 26.3k | void RegisterMetrics(const scoped_refptr<MetricEntity>& entity) { |
102 | 26.3k | entity->NeverRetire( |
103 | 26.3k | METRIC_generic_current_allocated_bytes.InstantiateFunctionGauge( |
104 | 26.3k | entity, Bind(GetTCMallocPropValue, Unretained("generic.current_allocated_bytes")))); |
105 | 26.3k | entity->NeverRetire( |
106 | 26.3k | METRIC_generic_heap_size.InstantiateFunctionGauge( |
107 | 26.3k | entity, Bind(GetTCMallocPropValue, Unretained("generic.heap_size")))); |
108 | 26.3k | entity->NeverRetire( |
109 | 26.3k | METRIC_tcmalloc_pageheap_free_bytes.InstantiateFunctionGauge( |
110 | 26.3k | entity, Bind(GetTCMallocPropValue, Unretained("tcmalloc.pageheap_free_bytes")))); |
111 | 26.3k | entity->NeverRetire( |
112 | 26.3k | METRIC_tcmalloc_pageheap_unmapped_bytes.InstantiateFunctionGauge( |
113 | 26.3k | entity, Bind(GetTCMallocPropValue, Unretained("tcmalloc.pageheap_unmapped_bytes")))); |
114 | 26.3k | entity->NeverRetire( |
115 | 26.3k | METRIC_tcmalloc_max_total_thread_cache_bytes.InstantiateFunctionGauge( |
116 | 26.3k | entity, Bind(GetTCMallocPropValue, Unretained("tcmalloc.max_total_thread_cache_bytes")))); |
117 | 26.3k | entity->NeverRetire( |
118 | 26.3k | METRIC_tcmalloc_current_total_thread_cache_bytes.InstantiateFunctionGauge( |
119 | 26.3k | entity, Bind(GetTCMallocPropValue, |
120 | 26.3k | Unretained("tcmalloc.current_total_thread_cache_bytes")))); |
121 | 26.3k | } |
122 | | |
123 | | } // namespace tcmalloc |
124 | | } // namespace yb |