2019-02-18 23:26:22 -07:00
|
|
|
use crate::{influxdb, submit};
|
2019-02-27 20:57:01 -08:00
|
|
|
use log::*;
|
2018-11-16 08:45:59 -08:00
|
|
|
use solana_sdk::timing;
|
2018-07-17 15:26:10 -07:00
|
|
|
use std::env;
|
2018-05-30 21:24:21 -07:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
|
2018-11-15 22:27:16 -08:00
|
|
|
const DEFAULT_LOG_RATE: usize = 1000;
|
2019-04-25 16:58:49 -07:00
|
|
|
const DEFAULT_METRICS_RATE: usize = 1;
|
2019-08-08 17:05:06 -04:00
|
|
|
const DEFAULT_METRICS_HIGH_RATE: usize = 10;
|
|
|
|
|
|
|
|
/// Use default metrics high rate
|
|
|
|
pub const HIGH_RATE: usize = 999_999;
|
2018-07-10 12:37:39 -07:00
|
|
|
|
2018-05-30 21:24:21 -07:00
|
|
|
pub struct Counter {
|
|
|
|
pub name: &'static str,
|
2018-07-10 15:14:59 -07:00
|
|
|
/// total accumulated value
|
2018-05-30 21:24:21 -07:00
|
|
|
pub counts: AtomicUsize,
|
|
|
|
pub times: AtomicUsize,
|
2018-07-10 15:14:59 -07:00
|
|
|
/// last accumulated value logged
|
|
|
|
pub lastlog: AtomicUsize,
|
2018-07-17 15:26:10 -07:00
|
|
|
pub lograte: AtomicUsize,
|
2019-04-25 16:58:49 -07:00
|
|
|
pub metricsrate: AtomicUsize,
|
2018-12-13 16:40:00 -08:00
|
|
|
pub point: Option<influxdb::Point>,
|
2018-05-30 21:24:21 -07:00
|
|
|
}
|
|
|
|
|
2019-02-18 23:26:22 -07:00
|
|
|
#[macro_export]
|
2018-05-30 21:24:21 -07:00
|
|
|
macro_rules! create_counter {
|
2019-04-25 16:58:49 -07:00
|
|
|
($name:expr, $lograte:expr, $metricsrate:expr) => {
|
2019-05-10 08:33:58 -07:00
|
|
|
$crate::counter::Counter {
|
2018-05-30 21:24:21 -07:00
|
|
|
name: $name,
|
2019-02-13 20:04:20 -08:00
|
|
|
counts: std::sync::atomic::AtomicUsize::new(0),
|
|
|
|
times: std::sync::atomic::AtomicUsize::new(0),
|
|
|
|
lastlog: std::sync::atomic::AtomicUsize::new(0),
|
|
|
|
lograte: std::sync::atomic::AtomicUsize::new($lograte),
|
2019-04-25 16:58:49 -07:00
|
|
|
metricsrate: std::sync::atomic::AtomicUsize::new($metricsrate),
|
2018-12-13 16:40:00 -08:00
|
|
|
point: None,
|
2018-05-30 21:24:21 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-18 23:26:22 -07:00
|
|
|
#[macro_export]
|
2018-05-30 21:24:21 -07:00
|
|
|
macro_rules! inc_counter {
|
2018-11-13 16:55:14 -08:00
|
|
|
($name:expr, $level:expr, $count:expr) => {
|
2019-05-17 17:34:05 -07:00
|
|
|
unsafe {
|
|
|
|
if log_enabled!($level) {
|
|
|
|
$name.inc($level, $count)
|
|
|
|
}
|
|
|
|
};
|
2018-05-30 21:24:21 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-17 14:14:57 -07:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! inc_counter_info {
|
|
|
|
($name:expr, $count:expr) => {
|
2019-05-17 17:34:05 -07:00
|
|
|
unsafe {
|
|
|
|
if log_enabled!(log::Level::Info) {
|
|
|
|
$name.inc(log::Level::Info, $count)
|
|
|
|
}
|
|
|
|
};
|
2019-04-17 14:14:57 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-18 23:26:22 -07:00
|
|
|
#[macro_export]
|
2018-08-06 18:35:45 +00:00
|
|
|
macro_rules! inc_new_counter {
|
2019-04-25 16:58:49 -07:00
|
|
|
($name:expr, $count:expr, $level:expr, $lograte:expr, $metricsrate:expr) => {{
|
2019-05-17 17:34:05 -07:00
|
|
|
if log_enabled!($level) {
|
|
|
|
static mut INC_NEW_COUNTER: $crate::counter::Counter =
|
|
|
|
create_counter!($name, $lograte, $metricsrate);
|
2019-07-14 13:37:55 -07:00
|
|
|
static INIT_HOOK: std::sync::Once = std::sync::Once::new();
|
2019-05-17 17:34:05 -07:00
|
|
|
unsafe {
|
|
|
|
INIT_HOOK.call_once(|| {
|
|
|
|
INC_NEW_COUNTER.init();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
inc_counter!(INC_NEW_COUNTER, $level, $count);
|
2018-12-13 16:40:00 -08:00
|
|
|
}
|
2018-07-16 18:33:50 -07:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2019-05-17 07:00:06 -07:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! inc_new_counter_error {
|
|
|
|
($name:expr, $count:expr) => {{
|
|
|
|
inc_new_counter!($name, $count, log::Level::Error, 0, 0);
|
|
|
|
}};
|
|
|
|
($name:expr, $count:expr, $lograte:expr) => {{
|
|
|
|
inc_new_counter!($name, $count, log::Level::Error, $lograte, 0);
|
|
|
|
}};
|
|
|
|
($name:expr, $count:expr, $lograte:expr, $metricsrate:expr) => {{
|
|
|
|
inc_new_counter!($name, $count, log::Level::Error, $lograte, $metricsrate);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! inc_new_counter_warn {
|
|
|
|
($name:expr, $count:expr) => {{
|
|
|
|
inc_new_counter!($name, $count, log::Level::Warn, 0, 0);
|
|
|
|
}};
|
|
|
|
($name:expr, $count:expr, $lograte:expr) => {{
|
|
|
|
inc_new_counter!($name, $count, log::Level::Warn, $lograte, 0);
|
|
|
|
}};
|
|
|
|
($name:expr, $count:expr, $lograte:expr, $metricsrate:expr) => {{
|
|
|
|
inc_new_counter!($name, $count, log::Level::Warn, $lograte, $metricsrate);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2019-02-18 23:26:22 -07:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! inc_new_counter_info {
|
|
|
|
($name:expr, $count:expr) => {{
|
2019-04-25 16:58:49 -07:00
|
|
|
inc_new_counter!($name, $count, log::Level::Info, 0, 0);
|
2019-02-18 23:26:22 -07:00
|
|
|
}};
|
|
|
|
($name:expr, $count:expr, $lograte:expr) => {{
|
2019-04-25 16:58:49 -07:00
|
|
|
inc_new_counter!($name, $count, log::Level::Info, $lograte, 0);
|
|
|
|
}};
|
|
|
|
($name:expr, $count:expr, $lograte:expr, $metricsrate:expr) => {{
|
|
|
|
inc_new_counter!($name, $count, log::Level::Info, $lograte, $metricsrate);
|
2019-02-18 23:26:22 -07:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2019-05-17 07:00:06 -07:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! inc_new_counter_debug {
|
|
|
|
($name:expr, $count:expr) => {{
|
|
|
|
inc_new_counter!($name, $count, log::Level::Debug, 0, 0);
|
|
|
|
}};
|
|
|
|
($name:expr, $count:expr, $lograte:expr) => {{
|
|
|
|
inc_new_counter!($name, $count, log::Level::Debug, $lograte, 0);
|
|
|
|
}};
|
|
|
|
($name:expr, $count:expr, $lograte:expr, $metricsrate:expr) => {{
|
|
|
|
inc_new_counter!($name, $count, log::Level::Debug, $lograte, $metricsrate);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2019-08-08 17:05:06 -04:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! inc_new_high_rate_counter_error {
|
|
|
|
($name:expr, $count:expr) => {{
|
|
|
|
inc_new_counter!(
|
|
|
|
$name,
|
|
|
|
$count,
|
|
|
|
log::Level::Error,
|
|
|
|
0,
|
|
|
|
$crate::counter::HIGH_RATE
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! inc_new_high_rate_counter_warn {
|
|
|
|
($name:expr, $count:expr) => {{
|
|
|
|
inc_new_counter!(
|
|
|
|
$name,
|
|
|
|
$count,
|
|
|
|
log::Level::Warn,
|
|
|
|
0,
|
|
|
|
$crate::counter::HIGH_RATE
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! inc_new_high_rate_counter_info {
|
|
|
|
($name:expr, $count:expr) => {{
|
|
|
|
inc_new_counter!(
|
|
|
|
$name,
|
|
|
|
$count,
|
|
|
|
log::Level::Info,
|
|
|
|
0,
|
|
|
|
$crate::counter::HIGH_RATE
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! inc_new_high_rate_counter_debug {
|
|
|
|
($name:expr, $count:expr) => {{
|
|
|
|
inc_new_counter!(
|
|
|
|
$name,
|
|
|
|
$count,
|
|
|
|
log::Level::Debug,
|
|
|
|
0,
|
|
|
|
$crate::counter::HIGH_RATE
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2018-05-30 21:24:21 -07:00
|
|
|
impl Counter {
|
2019-08-08 17:05:06 -04:00
|
|
|
fn default_metrics_high_rate() -> usize {
|
|
|
|
let v = env::var("SOLANA_METRICS_HIGH_RATE")
|
|
|
|
.map(|x| x.parse().unwrap_or(0))
|
|
|
|
.unwrap_or(0);
|
|
|
|
if v == 0 {
|
|
|
|
DEFAULT_METRICS_HIGH_RATE
|
|
|
|
} else {
|
|
|
|
v
|
|
|
|
}
|
|
|
|
}
|
2018-07-17 15:26:10 -07:00
|
|
|
fn default_log_rate() -> usize {
|
2018-11-15 22:27:16 -08:00
|
|
|
let v = env::var("SOLANA_DEFAULT_LOG_RATE")
|
|
|
|
.map(|x| x.parse().unwrap_or(DEFAULT_LOG_RATE))
|
|
|
|
.unwrap_or(DEFAULT_LOG_RATE);
|
2018-07-17 15:26:10 -07:00
|
|
|
if v == 0 {
|
2018-11-15 22:27:16 -08:00
|
|
|
DEFAULT_LOG_RATE
|
2018-07-17 15:26:10 -07:00
|
|
|
} else {
|
|
|
|
v
|
|
|
|
}
|
|
|
|
}
|
2018-12-13 16:40:00 -08:00
|
|
|
pub fn init(&mut self) {
|
|
|
|
self.point = Some(
|
2019-05-10 08:33:58 -07:00
|
|
|
influxdb::Point::new(&self.name)
|
2018-12-13 16:40:00 -08:00
|
|
|
.add_field("count", influxdb::Value::Integer(0))
|
|
|
|
.to_owned(),
|
|
|
|
);
|
2019-08-08 17:05:06 -04:00
|
|
|
self.lograte
|
|
|
|
.compare_and_swap(0, Self::default_log_rate(), Ordering::Relaxed);
|
|
|
|
self.metricsrate.compare_and_swap(
|
|
|
|
HIGH_RATE,
|
|
|
|
Self::default_metrics_high_rate(),
|
|
|
|
Ordering::Relaxed,
|
|
|
|
);
|
|
|
|
self.metricsrate
|
|
|
|
.compare_and_swap(0, DEFAULT_METRICS_RATE, Ordering::Relaxed);
|
2018-12-13 16:40:00 -08:00
|
|
|
}
|
2018-11-13 16:55:14 -08:00
|
|
|
pub fn inc(&mut self, level: log::Level, events: usize) {
|
2018-05-30 21:24:21 -07:00
|
|
|
let counts = self.counts.fetch_add(events, Ordering::Relaxed);
|
|
|
|
let times = self.times.fetch_add(1, Ordering::Relaxed);
|
2019-08-08 17:05:06 -04:00
|
|
|
let lograte = self.lograte.load(Ordering::Relaxed);
|
|
|
|
let metricsrate = self.metricsrate.load(Ordering::Relaxed);
|
|
|
|
|
2018-11-15 22:27:16 -08:00
|
|
|
if times % lograte == 0 && times > 0 && log_enabled!(level) {
|
2019-04-17 14:14:57 -07:00
|
|
|
log!(level,
|
2018-11-15 22:27:16 -08:00
|
|
|
"COUNTER:{{\"name\": \"{}\", \"counts\": {}, \"samples\": {}, \"now\": {}, \"events\": {}}}",
|
|
|
|
self.name,
|
|
|
|
counts + events,
|
|
|
|
times,
|
|
|
|
timing::timestamp(),
|
|
|
|
events,
|
|
|
|
);
|
|
|
|
}
|
2019-04-25 16:58:49 -07:00
|
|
|
|
|
|
|
if times % metricsrate == 0 && times > 0 {
|
|
|
|
let lastlog = self.lastlog.load(Ordering::Relaxed);
|
|
|
|
let prev = self
|
|
|
|
.lastlog
|
|
|
|
.compare_and_swap(lastlog, counts, Ordering::Relaxed);
|
|
|
|
if prev == lastlog {
|
|
|
|
if let Some(ref mut point) = self.point {
|
|
|
|
point
|
|
|
|
.fields
|
|
|
|
.entry("count".to_string())
|
|
|
|
.and_modify(|v| {
|
|
|
|
*v = influxdb::Value::Integer(counts as i64 - lastlog as i64)
|
|
|
|
})
|
|
|
|
.or_insert(influxdb::Value::Integer(0));
|
|
|
|
}
|
|
|
|
if let Some(ref mut point) = self.point {
|
2019-05-16 22:27:05 -07:00
|
|
|
submit(point.to_owned(), level);
|
2019-04-25 16:58:49 -07:00
|
|
|
}
|
2018-12-13 16:40:00 -08:00
|
|
|
}
|
2018-05-30 21:24:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2019-08-08 17:05:06 -04:00
|
|
|
use crate::counter::{Counter, DEFAULT_LOG_RATE, DEFAULT_METRICS_HIGH_RATE, HIGH_RATE};
|
2018-08-06 18:35:45 +00:00
|
|
|
use log::Level;
|
2019-05-17 17:34:05 -07:00
|
|
|
use log::*;
|
2019-07-02 17:35:03 -07:00
|
|
|
use serial_test_derive::serial;
|
2018-07-17 15:26:10 -07:00
|
|
|
use std::env;
|
2019-02-13 20:04:20 -08:00
|
|
|
use std::sync::atomic::Ordering;
|
2019-07-14 13:37:55 -07:00
|
|
|
use std::sync::{Once, RwLock};
|
2018-07-31 12:37:39 -07:00
|
|
|
|
|
|
|
fn get_env_lock() -> &'static RwLock<()> {
|
|
|
|
static mut ENV_LOCK: Option<RwLock<()>> = None;
|
2019-07-14 13:37:55 -07:00
|
|
|
static INIT_HOOK: Once = Once::new();
|
2018-07-31 12:37:39 -07:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
INIT_HOOK.call_once(|| {
|
|
|
|
ENV_LOCK = Some(RwLock::new(()));
|
|
|
|
});
|
|
|
|
&ENV_LOCK.as_ref().unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 21:24:21 -07:00
|
|
|
#[test]
|
2019-07-02 17:35:03 -07:00
|
|
|
#[serial]
|
2018-05-30 21:24:21 -07:00
|
|
|
fn test_counter() {
|
2019-05-17 17:34:05 -07:00
|
|
|
env_logger::Builder::from_env(env_logger::Env::new().default_filter_or("solana=info"))
|
2019-07-02 17:35:03 -07:00
|
|
|
.try_init()
|
|
|
|
.ok();
|
2018-07-31 12:37:39 -07:00
|
|
|
let _readlock = get_env_lock().read();
|
2019-04-25 16:58:49 -07:00
|
|
|
static mut COUNTER: Counter = create_counter!("test", 1000, 1);
|
2019-08-08 17:05:06 -04:00
|
|
|
unsafe {
|
|
|
|
COUNTER.init();
|
|
|
|
}
|
2018-05-30 21:24:21 -07:00
|
|
|
let count = 1;
|
2018-11-13 16:55:14 -08:00
|
|
|
inc_counter!(COUNTER, Level::Info, count);
|
2018-05-30 21:24:21 -07:00
|
|
|
unsafe {
|
|
|
|
assert_eq!(COUNTER.counts.load(Ordering::Relaxed), 1);
|
|
|
|
assert_eq!(COUNTER.times.load(Ordering::Relaxed), 1);
|
2018-11-15 22:27:16 -08:00
|
|
|
assert_eq!(COUNTER.lograte.load(Ordering::Relaxed), 1000);
|
2018-07-10 15:14:59 -07:00
|
|
|
assert_eq!(COUNTER.lastlog.load(Ordering::Relaxed), 0);
|
2018-05-30 21:24:21 -07:00
|
|
|
assert_eq!(COUNTER.name, "test");
|
|
|
|
}
|
2018-07-10 15:14:59 -07:00
|
|
|
for _ in 0..199 {
|
2018-11-13 16:55:14 -08:00
|
|
|
inc_counter!(COUNTER, Level::Info, 2);
|
2018-07-10 15:14:59 -07:00
|
|
|
}
|
|
|
|
unsafe {
|
2018-11-15 22:27:16 -08:00
|
|
|
assert_eq!(COUNTER.lastlog.load(Ordering::Relaxed), 397);
|
2018-07-10 15:14:59 -07:00
|
|
|
}
|
2018-11-13 16:55:14 -08:00
|
|
|
inc_counter!(COUNTER, Level::Info, 2);
|
2018-07-10 15:14:59 -07:00
|
|
|
unsafe {
|
|
|
|
assert_eq!(COUNTER.lastlog.load(Ordering::Relaxed), 399);
|
|
|
|
}
|
2018-05-30 21:24:21 -07:00
|
|
|
}
|
2019-08-08 17:05:06 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[serial]
|
|
|
|
fn test_high_rate_counter() {
|
|
|
|
env_logger::Builder::from_env(env_logger::Env::new().default_filter_or("solana=info"))
|
|
|
|
.try_init()
|
|
|
|
.ok();
|
|
|
|
let _readlock = get_env_lock().read();
|
|
|
|
static mut COUNTER: Counter = create_counter!("test", 1000, HIGH_RATE);
|
|
|
|
env::remove_var("SOLANA_METRICS_HIGH_RATE");
|
|
|
|
unsafe {
|
|
|
|
COUNTER.init();
|
|
|
|
assert_eq!(
|
|
|
|
COUNTER.metricsrate.load(Ordering::Relaxed),
|
|
|
|
DEFAULT_METRICS_HIGH_RATE
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[serial]
|
|
|
|
fn test_high_rate_counter_env() {
|
|
|
|
env_logger::Builder::from_env(env_logger::Env::new().default_filter_or("solana=info"))
|
|
|
|
.try_init()
|
|
|
|
.ok();
|
|
|
|
let _writelock = get_env_lock().write();
|
|
|
|
static mut COUNTER: Counter = create_counter!("test", 1000, HIGH_RATE);
|
|
|
|
env::set_var("SOLANA_METRICS_HIGH_RATE", "50");
|
|
|
|
unsafe {
|
|
|
|
COUNTER.init();
|
|
|
|
assert_eq!(COUNTER.metricsrate.load(Ordering::Relaxed), 50);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 18:33:50 -07:00
|
|
|
#[test]
|
2019-07-02 17:35:03 -07:00
|
|
|
#[serial]
|
2018-07-16 18:33:50 -07:00
|
|
|
fn test_inc_new_counter() {
|
2018-07-31 12:37:39 -07:00
|
|
|
let _readlock = get_env_lock().read();
|
2018-07-16 18:33:50 -07:00
|
|
|
//make sure that macros are syntactically correct
|
|
|
|
//the variable is internal to the macro scope so there is no way to introspect it
|
2019-05-10 08:33:58 -07:00
|
|
|
inc_new_counter_info!("1", 1);
|
|
|
|
inc_new_counter_info!("2", 1, 3);
|
|
|
|
inc_new_counter_info!("3", 1, 2, 1);
|
2018-07-16 18:33:50 -07:00
|
|
|
}
|
2019-08-08 17:05:06 -04:00
|
|
|
|
2018-07-17 15:26:10 -07:00
|
|
|
#[test]
|
2019-07-02 17:35:03 -07:00
|
|
|
#[serial]
|
2018-07-17 15:26:10 -07:00
|
|
|
fn test_lograte() {
|
2019-07-02 17:35:03 -07:00
|
|
|
env_logger::Builder::from_env(env_logger::Env::new().default_filter_or("solana=info"))
|
|
|
|
.try_init()
|
|
|
|
.ok();
|
2018-07-31 12:37:39 -07:00
|
|
|
let _readlock = get_env_lock().read();
|
|
|
|
assert_eq!(
|
|
|
|
Counter::default_log_rate(),
|
2018-11-15 22:27:16 -08:00
|
|
|
DEFAULT_LOG_RATE,
|
|
|
|
"default_log_rate() is {}, expected {}, SOLANA_DEFAULT_LOG_RATE environment variable set?",
|
2018-07-31 12:37:39 -07:00
|
|
|
Counter::default_log_rate(),
|
2018-11-15 22:27:16 -08:00
|
|
|
DEFAULT_LOG_RATE,
|
2018-07-31 12:37:39 -07:00
|
|
|
);
|
2019-04-25 16:58:49 -07:00
|
|
|
static mut COUNTER: Counter = create_counter!("test_lograte", 0, 1);
|
2018-07-17 15:26:10 -07:00
|
|
|
unsafe {
|
2019-08-08 17:05:06 -04:00
|
|
|
COUNTER.init();
|
2018-11-15 22:27:16 -08:00
|
|
|
assert_eq!(COUNTER.lograte.load(Ordering::Relaxed), DEFAULT_LOG_RATE);
|
2018-07-17 15:26:10 -07:00
|
|
|
}
|
|
|
|
}
|
2018-07-31 12:37:39 -07:00
|
|
|
|
2018-07-17 15:26:10 -07:00
|
|
|
#[test]
|
2019-07-02 17:35:03 -07:00
|
|
|
#[serial]
|
2018-07-17 15:26:10 -07:00
|
|
|
fn test_lograte_env() {
|
2019-07-02 17:35:03 -07:00
|
|
|
env_logger::Builder::from_env(env_logger::Env::new().default_filter_or("solana=info"))
|
|
|
|
.try_init()
|
|
|
|
.ok();
|
2018-11-15 22:27:16 -08:00
|
|
|
assert_ne!(DEFAULT_LOG_RATE, 0);
|
2018-07-31 12:37:39 -07:00
|
|
|
let _writelock = get_env_lock().write();
|
2019-04-25 16:58:49 -07:00
|
|
|
static mut COUNTER: Counter = create_counter!("test_lograte_env", 0, 1);
|
2018-11-15 22:27:16 -08:00
|
|
|
env::set_var("SOLANA_DEFAULT_LOG_RATE", "50");
|
2018-07-17 15:26:10 -07:00
|
|
|
unsafe {
|
2019-08-08 17:05:06 -04:00
|
|
|
COUNTER.init();
|
2018-07-17 15:26:10 -07:00
|
|
|
assert_eq!(COUNTER.lograte.load(Ordering::Relaxed), 50);
|
|
|
|
}
|
|
|
|
|
2019-04-25 16:58:49 -07:00
|
|
|
static mut COUNTER2: Counter = create_counter!("test_lograte_env", 0, 1);
|
2018-11-15 22:27:16 -08:00
|
|
|
env::set_var("SOLANA_DEFAULT_LOG_RATE", "0");
|
2018-07-17 15:26:10 -07:00
|
|
|
unsafe {
|
2019-08-08 17:05:06 -04:00
|
|
|
COUNTER2.init();
|
2018-11-15 22:27:16 -08:00
|
|
|
assert_eq!(COUNTER2.lograte.load(Ordering::Relaxed), DEFAULT_LOG_RATE);
|
2018-07-17 15:26:10 -07:00
|
|
|
}
|
|
|
|
}
|
2018-05-30 21:24:21 -07:00
|
|
|
}
|