-
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.
- Loading branch information
Memfault Inc
committed
Oct 7, 2024
1 parent
3a9e0c5
commit ba4c2cd
Showing
115 changed files
with
2,890 additions
and
809 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
BUILD ID: 2370319 | ||
GIT COMMIT: 41269b2621 | ||
VERSION: 1.14.0 | ||
BUILD ID: 2534584 | ||
GIT COMMIT: e2c67955b9 | ||
VERSION: 1.15.0 |
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
Empty file.
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
Empty file.
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
Empty file.
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,84 @@ | ||
// | ||
// Copyright (c) Memfault, Inc. | ||
// See License.txt for details | ||
use chrono::Utc; | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
use memfaultd::config::{LevelMappingConfig, LevelMappingRegex}; | ||
use memfaultd::logs::log_entry::{LogData, LogEntry}; | ||
use memfaultd::logs::log_level_mapper::LogLevelMapper; | ||
|
||
const BENCH_LEVELS: &[&str] = &[ | ||
"EMERG", "ALERT", "CRIT", "ERROR", "WARN", "NOTICE", "INFO", "DEBUG", | ||
]; | ||
|
||
fn build_log_line(level: &str, message: &str) -> LogEntry { | ||
let data = LogData { | ||
message: message.to_string(), | ||
pid: None, | ||
systemd_unit: None, | ||
priority: Some(level.to_string()), | ||
original_priority: None, | ||
extra_fields: Default::default(), | ||
}; | ||
|
||
LogEntry { | ||
ts: Utc::now(), | ||
data, | ||
} | ||
} | ||
|
||
fn build_regex_string(level: &str) -> String { | ||
format!(r"\[.*\] \[{}\]:", level) | ||
} | ||
|
||
fn build_log_mapper() -> LogLevelMapper { | ||
let regex = BENCH_LEVELS | ||
.iter() | ||
.map(|level| build_regex_string(level)) | ||
.collect::<Vec<_>>(); | ||
|
||
let regex = LevelMappingRegex { | ||
emergency: Some(regex[0].clone()), | ||
alert: Some(regex[1].clone()), | ||
critical: Some(regex[2].clone()), | ||
error: Some(regex[3].clone()), | ||
warning: Some(regex[4].clone()), | ||
notice: Some(regex[5].clone()), | ||
info: Some(regex[6].clone()), | ||
debug: Some(regex[7].clone()), | ||
}; | ||
let level_config = LevelMappingConfig { | ||
enable: true, | ||
regex: Some(regex), | ||
}; | ||
|
||
LogLevelMapper::try_from(&level_config).expect("Failed to build log level mapper") | ||
} | ||
|
||
fn map_logs(num_log_lines: u64, mapper: &LogLevelMapper) { | ||
for i in 0..num_log_lines { | ||
let cur_level_idx = i % BENCH_LEVELS.len() as u64; | ||
let cur_level = BENCH_LEVELS[cur_level_idx as usize]; | ||
let mut log_line = build_log_line(cur_level, "This is a test log message"); | ||
mapper.map_log(&mut log_line).expect("Error mapping log"); | ||
} | ||
} | ||
|
||
fn log_mapper_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("Log Level Mapper"); | ||
let num_log_lines = [100, 1000]; | ||
let level_mapper = build_log_mapper(); | ||
|
||
for num in num_log_lines { | ||
group.throughput(Throughput::Elements(num)); | ||
group.bench_with_input(BenchmarkId::new("Log Level Mapper", num), &num, |b, num| { | ||
// Send metrics to preallocate the metrics hashmap | ||
b.iter(|| { | ||
map_logs(*num, &level_mapper); | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, log_mapper_benchmark); | ||
criterion_main!(benches); |
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
2 changes: 1 addition & 1 deletion
2
...__collectd_handler__tests__drops_cpu_metrics_when_builtin_system_metrics_are_enabled.snap
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
2 changes: 1 addition & 1 deletion
2
...ltd/src/collectd/snapshots/memfaultd__collectd__collectd_handler__tests__handle_push.snap
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.