forked from tikv/tikv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: reduce sys_getdents syscall (tikv#7306)
Signed-off-by: Breezewish <[email protected]>
- Loading branch information
1 parent
6411ffe
commit 7d13ca0
Showing
19 changed files
with
190 additions
and
115 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
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,5 @@ | ||
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
pub fn monitor_memory() -> std::io::Result<()> { | ||
Ok(()) | ||
} |
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,76 @@ | ||
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
//! This module is a subset of rust-prometheus's process collector, without the fd collector | ||
//! to avoid memory fragmentation issues when open fd is large. | ||
use std::io::{Error, ErrorKind, Result}; | ||
|
||
use libc; | ||
use procinfo::pid as pid_info; | ||
|
||
use prometheus::core::{Collector, Desc}; | ||
use prometheus::{proto, Gauge, Opts}; | ||
|
||
/// Monitors memory of the current process. | ||
pub fn monitor_memory() -> Result<()> { | ||
let pid = unsafe { libc::getpid() }; | ||
let tc = MemoryCollector::new(pid); | ||
prometheus::register(Box::new(tc)).map_err(|e| Error::new(ErrorKind::Other, e.to_string())) | ||
} | ||
|
||
/// A collector to collect memory metrics. | ||
pub struct MemoryCollector { | ||
pid: libc::pid_t, | ||
descs: Vec<Desc>, | ||
vsize: Gauge, | ||
rss: Gauge, | ||
} | ||
|
||
impl MemoryCollector { | ||
pub fn new(pid: libc::pid_t) -> Self { | ||
let mut descs = Vec::new(); | ||
|
||
let vsize = Gauge::with_opts(Opts::new( | ||
"process_virtual_memory_bytes", | ||
"Virtual memory size in bytes.", | ||
)) | ||
.unwrap(); | ||
descs.extend(vsize.desc().into_iter().cloned()); | ||
|
||
let rss = Gauge::with_opts(Opts::new( | ||
"process_resident_memory_bytes", | ||
"Resident memory size in bytes.", | ||
)) | ||
.unwrap(); | ||
descs.extend(rss.desc().into_iter().cloned()); | ||
|
||
Self { | ||
pid, | ||
descs, | ||
vsize, | ||
rss, | ||
} | ||
} | ||
} | ||
|
||
impl Collector for MemoryCollector { | ||
fn desc(&self) -> Vec<&Desc> { | ||
self.descs.iter().collect() | ||
} | ||
|
||
fn collect(&self) -> Vec<proto::MetricFamily> { | ||
if let Ok(statm) = pid_info::statm(self.pid) { | ||
self.vsize.set(statm.size as f64 * *PAGESIZE); | ||
self.rss.set(statm.resident as f64 * *PAGESIZE); | ||
} | ||
|
||
let mut mfs = Vec::with_capacity(2); | ||
mfs.extend(self.vsize.collect()); | ||
mfs.extend(self.rss.collect()); | ||
mfs | ||
} | ||
} | ||
|
||
lazy_static! { | ||
static ref PAGESIZE: f64 = { unsafe { libc::sysconf(libc::_SC_PAGESIZE) as f64 } }; | ||
} |
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
Oops, something went wrong.