Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
memory-metrics.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef IMPALA_UTIL_MEM_METRICS_H
16 #define IMPALA_UTIL_MEM_METRICS_H
17 
18 #include "util/metrics.h"
19 
20 #include <boost/thread/mutex.hpp>
21 #include <boost/bind.hpp>
22 #include <google/malloc_extension.h>
23 
24 #include "util/debug-util.h"
25 #include "gen-cpp/Frontend_types.h"
26 
27 namespace impala {
28 
29 class Thread;
30 
32 class TcmallocMetric : public UIntGauge {
33  public:
36 
42 
46 
51 
55  class PhysicalBytesMetric : public UIntGauge {
56  public:
57  PhysicalBytesMetric(const std::string& key)
58  : UIntGauge(key, TUnit::BYTES) { }
59 
60  private:
61  virtual void CalculateValue() {
62  value_ = TOTAL_BYTES_RESERVED->value() - PAGEHEAP_UNMAPPED_BYTES->value();
63  }
64  };
65 
67 
68  TcmallocMetric(const std::string& key, const std::string& tcmalloc_var)
69  : UIntGauge(key, TUnit::BYTES), tcmalloc_var_(tcmalloc_var) { }
70 
71  private:
73  const std::string tcmalloc_var_;
74 
75  virtual void CalculateValue() {
76  MallocExtension::instance()->GetNumericProperty(tcmalloc_var_.c_str(), &value_);
77  }
78 };
79 
84 class JvmMetric : public IntGauge {
85  public:
88  static Status InitMetrics(MetricGroup* metrics);
89 
90  protected:
93  virtual void CalculateValue();
94 
95  private:
98  MAX,
106  };
107 
109  JvmMetric(const std::string& key, const std::string& mempool_name, JvmMetricType type);
110 
112  std::string mempool_name_;
113 
117 };
118 
121 Status RegisterMemoryMetrics(MetricGroup* metrics, bool register_jvm_metrics);
122 
123 }
124 
125 #endif
JvmMetric(const std::string &key, const std::string &mempool_name, JvmMetricType type)
Private constructor to ensure only InitMetrics() can create JvmMetrics.
const std::string tcmalloc_var_
Name of the tcmalloc property this metric should fetch.
Status RegisterMemoryMetrics(MetricGroup *metrics, bool register_jvm_metrics)
MetricGroups may be organised hierarchically as a tree.
Definition: metrics.h:200
static TcmallocMetric * PAGEHEAP_UNMAPPED_BYTES
JvmMetricType metric_type_
static PhysicalBytesMetric * PHYSICAL_BYTES_RESERVED
static Status InitMetrics(MetricGroup *metrics)
static TcmallocMetric * PAGEHEAP_FREE_BYTES
TcmallocMetric(const std::string &key, const std::string &tcmalloc_var)
virtual void CalculateValue()
std::string mempool_name_
The name of the memory pool, defined by the Jvm.
virtual void CalculateValue()
Specialised metric which exposes numeric properties from tcmalloc.
static TcmallocMetric * TOTAL_BYTES_RESERVED
static TcmallocMetric * BYTES_IN_USE
Number of bytes allocated by tcmalloc, currently used by the application.
JvmMetricType
Each names one of the fields in TJvmMemoryPool.