Skip to content

Commit

Permalink
prevent stats printing from interfering with cli proxy
Browse files Browse the repository at this point in the history
This makes using stats with the mux possible again:

```
periodic_stat_logging = 10
```
  • Loading branch information
wez committed Jan 13, 2020
1 parent c989485 commit bb6251f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/frontend/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ pub struct GuiFrontEnd {
connection: Rc<Connection>,
}

lazy_static::lazy_static! {
static ref USE_OPENGL: AtomicBool = AtomicBool::new(true);
}
static USE_OPENGL: AtomicBool = AtomicBool::new(true);

pub fn is_opengl_enabled() -> bool {
USE_OPENGL.load(Ordering::Acquire)
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ fn run() -> anyhow::Result<()> {
// ourselves into basically netcat.
drop(client);

crate::stats::disable_stats_printing();

let front_end = FrontEndSelection::Null.try_new()?;
let mux = Rc::new(mux::Mux::new(None));
Mux::set_mux(&mux);
Expand Down
13 changes: 13 additions & 0 deletions src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ use crate::config::configuration;
use hdrhistogram::Histogram;
use metrics::{Key, Recorder};
use std::collections::HashMap;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
use tabout::{tabulate_output, Alignment, Column};

static ENABLE_STAT_PRINT: AtomicBool = AtomicBool::new(true);

struct Inner {
histograms: HashMap<Key, Histogram<u64>>,
}
Expand All @@ -14,6 +17,12 @@ fn pctile_latency(histogram: &Histogram<u64>, p: f64) -> Duration {
Duration::from_nanos(histogram.value_at_percentile(p))
}

/// Used to prevent the stats thread from trying to write to stderr
/// when we're running in proxy mode
pub fn disable_stats_printing() {
ENABLE_STAT_PRINT.store(false, Ordering::Acquire);
}

impl Inner {
fn run(inner: Arc<Mutex<Inner>>) {
let mut last_print = Instant::now();
Expand All @@ -39,6 +48,10 @@ impl Inner {

loop {
std::thread::sleep(Duration::from_secs(10));
if !ENABLE_STAT_PRINT.load(Ordering::Acquire) {
break;
}

let seconds = configuration().periodic_stat_logging;
if seconds == 0 {
continue;
Expand Down

0 comments on commit bb6251f

Please sign in to comment.