xref: /haiku/headers/private/kernel/AllocationTracking.h (revision 25a7b01d15612846f332751841da3579db313082)
1 /*
2  * Copyright 2011, Michael Lotz <mmlr@mlotz.ch>.
3  * Copyright 2011, Ingo Weinhold <ingo_weinhold@gmx.de>.
4  *
5  * Distributed under the terms of the MIT License.
6  */
7 #ifndef ALLOCATION_TRACKING_H
8 #define ALLOCATION_TRACKING_H
9 
10 
11 #include <debug.h>
12 #include <tracing.h>
13 
14 
15 namespace BKernel {
16 
17 class AllocationTrackingInfo {
18 public:
19 	AbstractTraceEntryWithStackTrace*	traceEntry;
20 	bigtime_t							traceEntryTimestamp;
21 
22 public:
Init(AbstractTraceEntryWithStackTrace * entry)23 	void Init(AbstractTraceEntryWithStackTrace* entry)
24 	{
25 		traceEntry = entry;
26 		traceEntryTimestamp = entry != NULL ? entry->Time() : -1;
27 			// Note: this is a race condition, if the tracing buffer wrapped and
28 			// got overwritten once, we would access an invalid trace entry
29 			// here. Obviously this is rather unlikely.
30 	}
31 
Clear()32 	void Clear()
33 	{
34 		traceEntry = NULL;
35 		traceEntryTimestamp = 0;
36 	}
37 
IsInitialized()38 	bool IsInitialized() const
39 	{
40 		return traceEntryTimestamp != 0;
41 	}
42 
TraceEntry()43 	AbstractTraceEntryWithStackTrace* TraceEntry() const
44 	{
45 		return traceEntry;
46 	}
47 
IsTraceEntryValid()48 	bool IsTraceEntryValid() const
49 	{
50 		return tracing_is_entry_valid(traceEntry, traceEntryTimestamp);
51 	}
52 };
53 
54 }	// namespace BKernel
55 
56 
57 using BKernel::AllocationTrackingInfo;
58 
59 
60 #endif	// ALLOCATION_TRACKING_H
61