]> git.cworth.org Git - apitrace/blob - cli/trim_callset.hpp
fb2c92a4747b3bb14af915e14b7b8d754fdc1e4e
[apitrace] / cli / trim_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 _TRIM_CALLSET_HPP_
30 #define _TRIM_CALLSET_HPP_
31
32 namespace trim {
33
34 /* A set of call numbers.
35  *
36  * This is designed as a more efficient replacement for
37  * std::set<unsigned> which is used heavily within the trim code's
38  * TraceAnalyzer. This is quite similar to the trace::CallSet with the
39  * following differences:
40  *
41  *   Simplifications:
42  *
43  *      * There is no support here for the 'step' and 'freq' features
44  *        supported by trace::CallSet.
45  *
46  *   Sophistications:
47  *
48  *      * This callset is implemented with a skip list for
49  *        (probabilistically) logarithmic lookup times for
50  *        out-of-order lookups.
51  *
52  *      * This callset optimizes the addition of new calls which are
53  *        within or adjacent to existing ranges, (by either doing
54  *        nothing, expanding the limits of an existing range, or also
55  *        merging two ranges). This keeps the length of the list down
56  *        when succesively adding individual calls that could be
57  *        efficiently expressed with a range.
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). Currently, trace::CallSet is not used
63  * in any performance-critical areas, so it may not be important to
64  * provide the performance imrpovements to it.
65  */
66
67 typedef unsigned CallNo;
68
69 class CallRange {
70 public:
71     CallNo first;
72     CallNo last;
73     int level;
74     CallRange **next;
75
76     CallRange(CallNo first, CallNo last, int level);
77
78     bool contains(CallNo call_no);
79 };
80
81 class CallSet {
82 public:
83     CallRange head;
84     int max_level;
85
86     CallSet();
87
88     void add(CallNo first, CallNo last);
89
90     void add(CallNo call_no);
91
92     bool contains(CallNo call_no);
93 };
94
95 } /* namespace trim */
96
97 #endif /* _TRIM_CALLSET_HPP_ */