1
0
mirror of https://github.com/bspeice/qadapt synced 2024-11-21 21:38:10 -05:00

Final cleanup, time to commit

This commit is contained in:
Bradlee Speice 2018-11-11 22:34:05 -05:00
parent 8bc768e40b
commit 901e7941a2
5 changed files with 30 additions and 17 deletions

View File

@ -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"

View File

@ -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.

View File

@ -7,11 +7,11 @@
// #![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;
@ -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()));

View File

@ -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() {

View File

@ -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);
} }