Skip to content

Commit

Permalink
config: use atomics for sampler enabled
Browse files Browse the repository at this point in the history
Use atomics for the sampler enabled status.

Fixes `softnet` to be disabled by default to match other samplers
  • Loading branch information
brayniac committed Sep 3, 2019
1 parent 50056ff commit be3012c
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Fixed
- Allows memcache sampler to reconnect to the cache instance which helps to make
the sampler more resilient to transient errors
- Softnet sampler now disabled by default to be consistent with other samplers

# [1.0.1] - 2019-08-22
## Fixed
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ publish = false
edition = '2018'

[dependencies]
atomics = { git = "https://github.com/twitter/rpc-perf", branch = "master" }
bcc = { version = "0.0.10", optional = true }
clap = "2.33.0"
failure = "0.1.5"
Expand Down
3 changes: 2 additions & 1 deletion src/config/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use crate::config::*;
use crate::samplers::cpu::CpuStatistic;
use core::sync::atomic::{AtomicBool, Ordering};

use atomics::*;

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down
3 changes: 2 additions & 1 deletion src/config/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// http://www.apache.org/licenses/LICENSE-2.0

use crate::config::*;
use core::sync::atomic::{AtomicBool, Ordering};

use atomics::*;

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down
3 changes: 2 additions & 1 deletion src/config/ebpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// http://www.apache.org/licenses/LICENSE-2.0

use crate::config::*;
use core::sync::atomic::{AtomicBool, Ordering};

use atomics::*;

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down
3 changes: 2 additions & 1 deletion src/config/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// http://www.apache.org/licenses/LICENSE-2.0

use crate::config::*;
use core::sync::atomic::{AtomicUsize, Ordering};

use atomics::*;

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down
13 changes: 7 additions & 6 deletions src/config/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
// http://www.apache.org/licenses/LICENSE-2.0

use crate::config::*;

use crate::samplers::network::interface::InterfaceStatistic;
use crate::samplers::network::protocol::ProtocolStatistic;

#[derive(Clone, Debug, Deserialize)]
use atomics::*;

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Network {
#[serde(default = "default_enabled")]
enabled: bool,
enabled: AtomicBool,
#[serde(default = "default_interface_statistics")]
interface_statistics: Vec<InterfaceStatistic>,
#[serde(default = "default_protocol_statistics")]
Expand All @@ -28,8 +29,8 @@ impl Default for Network {
}
}

fn default_enabled() -> bool {
false
fn default_enabled() -> AtomicBool {
AtomicBool::new(false)
}

fn default_interface_statistics() -> Vec<InterfaceStatistic> {
Expand Down Expand Up @@ -65,7 +66,7 @@ fn default_protocol_statistics() -> Vec<ProtocolStatistic> {

impl Network {
pub fn enabled(&self) -> bool {
self.enabled
self.enabled.load(Ordering::Relaxed)
}

pub fn interface_statistics(&self) -> &[InterfaceStatistic] {
Expand Down
12 changes: 7 additions & 5 deletions src/config/perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
use crate::config::*;
use crate::samplers::perf::PerfStatistic;

#[derive(Clone, Debug, Deserialize)]
use atomics::*;

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Perf {
#[serde(default = "default_enabled")]
enabled: bool,
enabled: AtomicBool,
#[serde(default = "default_statistics")]
statistics: Vec<PerfStatistic>,
}
Expand All @@ -23,8 +25,8 @@ impl Default for Perf {
}
}

fn default_enabled() -> bool {
false
fn default_enabled() -> AtomicBool {
AtomicBool::new(false)
}

fn default_statistics() -> Vec<PerfStatistic> {
Expand Down Expand Up @@ -54,7 +56,7 @@ fn default_statistics() -> Vec<PerfStatistic> {

impl Perf {
pub fn enabled(&self) -> bool {
self.enabled
self.enabled.load(Ordering::Relaxed)
}

pub fn statistics(&self) -> &[PerfStatistic] {
Expand Down
12 changes: 7 additions & 5 deletions src/config/softnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use crate::config::*;

#[derive(Clone, Debug, Deserialize)]
use atomics::*;

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Softnet {
#[serde(default = "default_enabled")]
enabled: bool,
enabled: AtomicBool,
}

impl Default for Softnet {
Expand All @@ -19,12 +21,12 @@ impl Default for Softnet {
}
}

fn default_enabled() -> bool {
true
fn default_enabled() -> AtomicBool {
AtomicBool::new(false)
}

impl Softnet {
pub fn enabled(&self) -> bool {
self.enabled
self.enabled.load(Ordering::Relaxed)
}
}

0 comments on commit be3012c

Please sign in to comment.