-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tikv_alloc: abstract some new jemalloc code (#4411)
* tikv_alloc: abstract some new jemalloc code This renames the jealloc_metrics module to allocator_metrics, does similar for the code inside it. It implements a no-op fetch_stats method for the system allocator. It marks the jemalloc-sys and jemalloc-ctl crates as optional, so that they might not be compiled when jemalloc is disabled. It's not actually possible disable the jemalloc features in this PR because there is no way to turn off the default-features of the tikv_alloc crate. A followup in #4207 will make it possible. It also moves a `mod` to after some `use` statements. Signed-off-by: Brian Anderson <andersrb@gmail.com>
- Loading branch information
1 parent
fc6b483
commit ac11703
Showing
6 changed files
with
90 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2017 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use prometheus::core::{Collector, Desc}; | ||
use prometheus::proto::MetricFamily; | ||
use prometheus::{IntGaugeVec, Opts, Result}; | ||
|
||
use tikv_alloc; | ||
|
||
pub fn monitor_allocator_stats<S: Into<String>>(namespace: S) -> Result<()> { | ||
prometheus::register(Box::new(AllocStatsCollector::new(namespace)?)) | ||
} | ||
|
||
struct AllocStatsCollector { | ||
descs: Vec<Desc>, | ||
metrics: IntGaugeVec, | ||
} | ||
|
||
impl AllocStatsCollector { | ||
fn new<S: Into<String>>(namespace: S) -> Result<AllocStatsCollector> { | ||
let stats = IntGaugeVec::new( | ||
Opts::new("allocator_stats", "Allocator stats").namespace(namespace.into()), | ||
&["type"], | ||
)?; | ||
Ok(AllocStatsCollector { | ||
descs: stats.desc().into_iter().cloned().collect(), | ||
metrics: stats, | ||
}) | ||
} | ||
} | ||
|
||
impl Collector for AllocStatsCollector { | ||
fn desc(&self) -> Vec<&Desc> { | ||
self.descs.iter().collect() | ||
} | ||
|
||
fn collect(&self) -> Vec<MetricFamily> { | ||
if let Ok(Some(stats)) = tikv_alloc::fetch_stats() { | ||
for stat in stats { | ||
self.metrics.with_label_values(&[stat.0]).set(stat.1 as i64); | ||
} | ||
} | ||
self.metrics.collect() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters