-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for memory usage in worse-case scenario
- Loading branch information
Showing
6 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub use gix_testtools::Result; | ||
|
||
mod file; | ||
mod mem; | ||
mod parse; | ||
mod source; | ||
mod value; |
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 @@ | ||
*.config -text -eof |
Binary file not shown.
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,33 @@ | ||
use bytesize::ByteSize; | ||
use cap::Cap; | ||
use std::alloc; | ||
use std::time::Instant; | ||
|
||
#[global_allocator] | ||
static ALLOCATOR: Cap<alloc::System> = Cap::new(alloc::System, usize::max_value()); | ||
|
||
#[test] | ||
fn usage() { | ||
let before = ALLOCATOR.allocated(); | ||
let start = Instant::now(); | ||
let config = gix_config::File::from_bytes_no_includes( | ||
include_bytes!("fixtures/fuzzed/mem-amplification.config"), | ||
gix_config::file::Metadata::from(gix_config::Source::User), | ||
Default::default(), | ||
) | ||
.unwrap(); | ||
let after = ALLOCATOR.allocated(); | ||
let used = after - before; | ||
let elapsed = start.elapsed().as_secs_f32(); | ||
eprintln!( | ||
"used mem: {}B for {} sections, took {elapsed:.02}s [total-mem: {total}, peak-mem: {peak}]", | ||
ByteSize(used as u64), | ||
config.sections().count(), | ||
total = ByteSize(ALLOCATOR.total_allocated() as u64), | ||
peak = ByteSize(ALLOCATOR.max_allocated() as u64), | ||
); | ||
assert!( | ||
used < 60 * 1024 * 1024, | ||
"we should now start using more memory than anticipated, to keep mem-amplification low" | ||
); | ||
} |