1
0
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:
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"
license = "Apache-2.0"
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"
[dependencies]
libc = "0.2"
log = "0.4"
spin = "0.4"
thread-id = "3.3"

View File

@ -1,7 +1,14 @@
The Quick And Dirty Allocation Profiling Tool
=============================================
A simple attempt at an allocator that can let you know if allocations
are happening in places you didn't intend. This is primarily used for
guaranteeing that performance-critical code doesn't trigger an allocation
while running.
This allocator is a helper for writing high-performance code that is allocation/drop free;
for functions annotated with `#[allocate_panic]`, QADAPT will detect when allocations/drops
happen during their execution (and execution of any functions they call) and throw a
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)]
extern crate proc_macro;
use proc_macro::TokenStream;
use proc_macro::TokenTree;
use proc_macro::Delimiter;
use proc_macro::Spacing;
use proc_macro::Span;
use proc_macro::Delimiter;
use proc_macro::TokenStream;
use proc_macro::TokenTree;
use std::iter::FromIterator;
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 => {
fn_body = Some(g.clone());
break;
},
tt => ret.push(tt)
}
tt => ret.push(tt),
}
}
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()
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() {

View File

@ -1,7 +1,7 @@
extern crate qadapt;
use qadapt::QADAPT;
use qadapt::allocate_panic;
use qadapt::QADAPT;
#[global_allocator]
static Q: QADAPT = QADAPT;
@ -9,7 +9,8 @@ static Q: QADAPT = QADAPT;
#[allocate_panic]
fn allocates() {
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);
}