mirror of
https://github.com/bspeice/qadapt
synced 2024-11-24 14:58:12 -05:00
Final cleanup, time to commit
This commit is contained in:
parent
8bc768e40b
commit
901e7941a2
@ -5,12 +5,17 @@ authors = ["Bradlee Speice <bradlee@speice.io>"]
|
|||||||
description = "The Quick And Dirty Allocation Profiling Tool"
|
description = "The Quick And Dirty Allocation Profiling Tool"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
categories = ["allocator", "nostd"]
|
categories = [
|
||||||
|
"development-tools",
|
||||||
|
"development-tools::debugging",
|
||||||
|
"development-tools::profiling",
|
||||||
|
"development-tools::testing",
|
||||||
|
"memory-management"
|
||||||
|
]
|
||||||
repository = "https://github.com/bspeice/qadapt.git"
|
repository = "https://github.com/bspeice/qadapt.git"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
log = "0.4"
|
|
||||||
spin = "0.4"
|
spin = "0.4"
|
||||||
thread-id = "3.3"
|
thread-id = "3.3"
|
||||||
|
|
||||||
|
15
README.md
15
README.md
@ -1,7 +1,14 @@
|
|||||||
The Quick And Dirty Allocation Profiling Tool
|
The Quick And Dirty Allocation Profiling Tool
|
||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
A simple attempt at an allocator that can let you know if allocations
|
This allocator is a helper for writing high-performance code that is allocation/drop free;
|
||||||
are happening in places you didn't intend. This is primarily used for
|
for functions annotated with `#[allocate_panic]`, QADAPT will detect when allocations/drops
|
||||||
guaranteeing that performance-critical code doesn't trigger an allocation
|
happen during their execution (and execution of any functions they call) and throw a
|
||||||
while running.
|
thread panic if this occurs.
|
||||||
|
|
||||||
|
Because QADAPT panics on allocation and is rather slow (for an allocator) it is **strongly**
|
||||||
|
recommended that QADAPT (the allocator) be used only in code tests. Functions annotated with
|
||||||
|
`#[allocate_panic]` will have no side effects if the QADAPT allocator is not being used,
|
||||||
|
so the attribute is safe to leave everywhere.
|
||||||
|
|
||||||
|
Currently this crate is Nightly-only, but will work once `const fn` is in Stable.
|
@ -1,17 +1,17 @@
|
|||||||
//! Helper macros to use with the QADAPT allocator system
|
//! Helper macros to use with the QADAPT allocator system
|
||||||
//!
|
//!
|
||||||
//! This crate is intended for managing the QADAPT allocator,
|
//! This crate is intended for managing the QADAPT allocator,
|
||||||
//! and is unusable on its own.
|
//! and is unusable on its own.
|
||||||
//!
|
//!
|
||||||
// TODO: This causes issues, but I can't track down why
|
// TODO: This causes issues, but I can't track down why
|
||||||
// #![deny(missing_docs)]
|
// #![deny(missing_docs)]
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::Delimiter;
|
||||||
use proc_macro::TokenTree;
|
|
||||||
use proc_macro::Spacing;
|
use proc_macro::Spacing;
|
||||||
use proc_macro::Span;
|
use proc_macro::Span;
|
||||||
use proc_macro::Delimiter;
|
use proc_macro::TokenStream;
|
||||||
|
use proc_macro::TokenTree;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
|
|
||||||
type TT = proc_macro::TokenTree;
|
type TT = proc_macro::TokenTree;
|
||||||
@ -46,7 +46,7 @@ fn protected_group(fn_body: G) -> TokenTree {
|
|||||||
|
|
||||||
/// Set up the QADAPT allocator to trigger a panic if any allocations happen during
|
/// Set up the QADAPT allocator to trigger a panic if any allocations happen during
|
||||||
/// calls to this function.
|
/// calls to this function.
|
||||||
///
|
///
|
||||||
/// QADAPT will only track allocations in the thread that calls this function;
|
/// QADAPT will only track allocations in the thread that calls this function;
|
||||||
/// if (for example) this function receives the results of an allocation in a
|
/// if (for example) this function receives the results of an allocation in a
|
||||||
/// separate thread, QADAPT will not trigger a panic.
|
/// separate thread, QADAPT will not trigger a panic.
|
||||||
@ -61,8 +61,8 @@ pub fn allocate_panic(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
TokenTree::Group(ref g) if g.delimiter() == Delimiter::Brace => {
|
TokenTree::Group(ref g) if g.delimiter() == Delimiter::Brace => {
|
||||||
fn_body = Some(g.clone());
|
fn_body = Some(g.clone());
|
||||||
break;
|
break;
|
||||||
},
|
}
|
||||||
tt => ret.push(tt)
|
tt => ret.push(tt),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret.push(protected_group(fn_body.unwrap()));
|
ret.push(protected_group(fn_body.unwrap()));
|
||||||
|
@ -75,7 +75,7 @@ static INTERNAL_ALLOCATION: RwLock<usize> = RwLock::new(usize::max_value());
|
|||||||
|
|
||||||
/// Get the current "protection level" in QADAPT: calls to enter_protected() - exit_protected()
|
/// Get the current "protection level" in QADAPT: calls to enter_protected() - exit_protected()
|
||||||
pub fn protection_level() -> usize {
|
pub fn protection_level() -> usize {
|
||||||
PROTECTION_LEVEL.try_with(|v| *v.read() ).unwrap_or(0)
|
PROTECTION_LEVEL.try_with(|v| *v.read()).unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn claim_internal_alloc() {
|
fn claim_internal_alloc() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
extern crate qadapt;
|
extern crate qadapt;
|
||||||
|
|
||||||
use qadapt::QADAPT;
|
|
||||||
use qadapt::allocate_panic;
|
use qadapt::allocate_panic;
|
||||||
|
use qadapt::QADAPT;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static Q: QADAPT = QADAPT;
|
static Q: QADAPT = QADAPT;
|
||||||
@ -9,7 +9,8 @@ static Q: QADAPT = QADAPT;
|
|||||||
#[allocate_panic]
|
#[allocate_panic]
|
||||||
fn allocates() {
|
fn allocates() {
|
||||||
assert_eq!(::qadapt::protection_level(), 1);
|
assert_eq!(::qadapt::protection_level(), 1);
|
||||||
let mut v = Vec::new();
|
// Without boxing, release profile can actually optimize out the allocation
|
||||||
|
let mut v = Box::new(Vec::new());
|
||||||
v.push(1);
|
v.push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user