]> git.cworth.org Git - apitrace/blob - common/trace_fast_callset.hpp
Rename trim::CallSet to trace::FastCallSet
[apitrace] / common / trace_fast_callset.hpp
1 /*********************************************************************
2  *
3  * Copyright 2012 Intel Corporation
4  * Copyright 2012 VMware, Inc.
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person
8  * obtaining a copy of this software and associated documentation
9  * files (the "Software"), to deal in the Software without
10  * restriction, including without limitation the rights to use, copy,
11  * modify, merge, publish, distribute, sublicense, and/or sell copies
12  * of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  *
27  *********************************************************************/
28
29 #ifndef _TRACE_FAST_CALLSET_HPP_
30 #define _TRACE_FAST_CALLSET_HPP_
31
32 #include "trace_model.hpp"
33
34 namespace trace {
35
36 /* A set of call numbers.
37  *
38  * This was originally designed as a more efficient replacement for
39  * std::set<unsigned> which was used heavily within the trim code's
40  * TraceAnalyzer. This is quite similar to the trace::CallSet with the
41  * following differences:
42  *
43  *   Simplifications:
44  *
45  *      * There is no support here for the 'step' and 'freq' features
46  *        supported by trace::CallSet.
47  *
48  *   Sophistications:
49  *
50  *      * This callset is implemented with a skip list for
51  *        (probabilistically) logarithmic lookup times for
52  *        out-of-order lookups.
53  *
54  *      * This callset optimizes the addition of new calls which are
55  *        within or adjacent to existing ranges, (by either doing
56  *        nothing, expanding the limits of an existing range, or also
57  *        merging two or more ranges).
58  *
59  * It would not be impossible to extend this code to support the
60  * missing features of trace::CallSet, (though the 'step' and 'freq'
61  * features would prevent some range-extending and merging
62  * optimizations in some cases).
63  */
64
65 class FastCallRange {
66 public:
67     CallNo first;
68     CallNo last;
69     int level;
70     FastCallRange **next;
71
72     FastCallRange(CallNo first, CallNo last, int level);
73
74     bool contains(CallNo call_no);
75 };
76
77 class FastCallSet {
78 public:
79     FastCallRange head;
80     int max_level;
81
82     FastCallSet();
83
84     void add(CallNo first, CallNo last);
85
86     void add(CallNo call_no);
87
88     bool contains(CallNo call_no);
89 };
90
91 } /* namespace trace */
92
93 #endif /* _TRACE_FAST_CALLSET_HPP_ */