]> git.cworth.org Git - apitrace/commitdiff
Rename trim::CallSet to trace::FastCallSet
authorCarl Worth <cworth@cworth.org>
Mon, 11 Mar 2013 20:05:52 +0000 (13:05 -0700)
committerCarl Worth <cworth@cworth.org>
Fri, 12 Apr 2013 21:30:38 +0000 (14:30 -0700)
This is in preparation for being able to use this code to optimize the common
cases in trace::CallSet, (callsets without step or freq).

CMakeLists.txt
cli/CMakeLists.txt
cli/cli_trim.cpp
cli/trace_analyzer.cpp
cli/trace_analyzer.hpp
cli/trim_callset.cpp [deleted file]
cli/trim_callset.hpp [deleted file]
common/trace_callset.hpp
common/trace_fast_callset.cpp [new file with mode: 0644]
common/trace_fast_callset.hpp [new file with mode: 0644]
common/trace_model.hpp

index 9394282c591062bdc931a054a3c01b6a4d3941d4..ac046f51266e469184860c78fe4fa7975d758de5 100644 (file)
@@ -299,6 +299,7 @@ endif ()
 add_library (common STATIC
     common/trace_callset.cpp
     common/trace_dump.cpp
 add_library (common STATIC
     common/trace_callset.cpp
     common/trace_dump.cpp
+    common/trace_fast_callset.cpp
     common/trace_file.cpp
     common/trace_file_read.cpp
     common/trace_file_write.cpp
     common/trace_file.cpp
     common/trace_file_read.cpp
     common/trace_file_write.cpp
index 3165f7da662abf4bf8007f50ea474f8d3bb626de..689374dc5333ade934d45ea2a398e57d7182cec5 100644 (file)
@@ -24,7 +24,6 @@ add_executable (apitrace
     cli_trim.cpp
     cli_resources.cpp
     trace_analyzer.cpp
     cli_trim.cpp
     cli_resources.cpp
     trace_analyzer.cpp
-    trim_callset.cpp
 )
 
 target_link_libraries (apitrace
 )
 
 target_link_libraries (apitrace
index 6694737a479a7181216e3138cec88684ac661029..342e66b02e831c2b22a5d9a63d4a17e98c9a48d1 100644 (file)
@@ -203,7 +203,7 @@ trim_trace(const char *filename, struct trim_options *options)
     trace::ParseBookmark beginning;
     trace::Parser p;
     TraceAnalyzer analyzer(options->trim_flags);
     trace::ParseBookmark beginning;
     trace::Parser p;
     TraceAnalyzer analyzer(options->trim_flags);
-    trim::CallSet *required;
+    trace::FastCallSet *required;
     unsigned frame;
     int call_range_first, call_range_last;
 
     unsigned frame;
     int call_range_first, call_range_last;
 
index 80ec15e0a646ef5114522fa6356207ee73f9a6fc..f98eaa75abb16d0b7acd732563e1c7b699e4e8b2 100644 (file)
@@ -760,7 +760,7 @@ TraceAnalyzer::require(trace::Call *call)
 /* Return a set of all the required calls, (both those calls added
  * explicitly with require() and those implicitly depended
  * upon. */
 /* Return a set of all the required calls, (both those calls added
  * explicitly with require() and those implicitly depended
  * upon. */
-trim::CallSet *
+trace::FastCallSet *
 TraceAnalyzer::get_required(void)
 {
     return &required;
 TraceAnalyzer::get_required(void)
 {
     return &required;
index 6e9140a78a1db75c99a808f6e455f8a365ec8c71..3e4013bcd07fcfe6fd0806f936a22132508a3e06 100644 (file)
@@ -29,7 +29,7 @@
 #include <GL/glext.h>
 
 #include "trace_callset.hpp"
 #include <GL/glext.h>
 
 #include "trace_callset.hpp"
-#include "trim_callset.hpp"
+#include "trace_fast_callset.hpp"
 #include "trace_parser.hpp"
 
 typedef unsigned TrimFlags;
 #include "trace_parser.hpp"
 
 typedef unsigned TrimFlags;
@@ -59,7 +59,7 @@ private:
 
     std::map<GLenum, unsigned> texture_map;
 
 
     std::map<GLenum, unsigned> texture_map;
 
-    trim::CallSet required;
+    trace::FastCallSet required;
 
     bool transformFeedbackActive;
     bool framebufferObjectActive;
 
     bool transformFeedbackActive;
     bool framebufferObjectActive;
@@ -110,5 +110,5 @@ public:
     /* Return a set of all the required calls, (both those calls added
      * explicitly with require() and those implicitly depended
      * upon. */
     /* Return a set of all the required calls, (both those calls added
      * explicitly with require() and those implicitly depended
      * upon. */
-    trim::CallSet *get_required(void);
+    trace::FastCallSet *get_required(void);
 };
 };
diff --git a/cli/trim_callset.cpp b/cli/trim_callset.cpp
deleted file mode 100644 (file)
index 69ed818..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/*********************************************************************
- *
- * Copyright 2006 Keith Packard and Carl Worth
- * Copyright 2012 Intel Corporation
- * Copyright 2012 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- *********************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits>
-
-#include "trim_callset.hpp"
-
-using namespace trim;
-
-#define MAX_LEVEL 16
-
-CallRange::CallRange(CallNo first, CallNo last, int level)
-{
-    this->first = first;
-    this->last = last;
-    this->level = level;
-
-    next = new CallRange*[level];
-}
-
-bool
-CallRange::contains(CallNo call_no)
-{
-    return (first <= call_no && last >= call_no);
-}
-
-CallSet::CallSet(): head(0, 0, MAX_LEVEL)
-{
-    head.first = std::numeric_limits<CallNo>::max();
-    head.last = std::numeric_limits<CallNo>::min();
-
-    for (int i = 0; i < MAX_LEVEL; i++)
-        head.next[i] = NULL;
-
-    max_level = 0;
-}
-
-/*
- * Generate a random level number, distributed
- * so that each level is 1/4 as likely as the one before
- *
- * Note that level numbers run 1 <= level < MAX_LEVEL
- */
-static int
-random_level (void)
-{
-    /* tricky bit -- each bit is '1' 75% of the time */
-    long int bits = random() | random();
-    int        level = 1;
-
-    while (level < MAX_LEVEL)
-    {
-       if (bits & 1)
-           break;
-        level++;
-       bits >>= 1;
-    }
-
-    return level;
-}
-
-void
-CallSet::add(CallNo first, CallNo last)
-{
-    CallRange **update[MAX_LEVEL];
-    CallRange *node, *next;
-    int i, level;
-
-    /* Find node immediately before insertion point. */
-    node = &head;
-    for (i = max_level - 1; i >= 0; i--) {
-        while (node->next[i] && first > node->next[i]->last) {
-            node = node->next[i];
-        }
-        update[i] = &node->next[i];
-    }
-
-    /* Can we contain first by expanding tail of current range by 1? */
-    if (node != &head && node->last == first - 1) {
-
-        node->last = last;
-        goto MERGE_NODE_WITH_SUBSEQUENT_COVERED_NODES;
-
-    }
-
-    /* Current range could not contain first, look at next. */
-
-    node = node->next[0];
-
-    if (node) {
-        /* Do nothing if new range is already entirely contained. */
-        if (node->first <= first && node->last >= last) {
-            return;
-        }
-
-        /* If last is already included, we can simply expand
-         * node->first to fully include the range. */
-        if (node->first <= last && node->last >= last) {
-            node->first = first;
-            return;
-        }
-
-        /* This is our candidate node if first is contained */
-        if (node->first <= first && node->last >= first) {
-            node->last = last;
-            goto MERGE_NODE_WITH_SUBSEQUENT_COVERED_NODES;
-        }
-    }
-
-    /* Not possible to expand any existing node, so create a new one. */
-
-    level = random_level();
-
-    /* Handle first node of this level. */
-    if (level > max_level) {
-        level = max_level + 1;
-        update[max_level] = &head.next[max_level];
-        max_level = level;
-    }
-
-    node = new CallRange(first, last, level);
-
-    /* Perform insertion into all lists. */
-    for (i = 0; i < level; i++) {
-        node->next[i] = *update[i];
-        *update[i] = node;
-    }
-
-MERGE_NODE_WITH_SUBSEQUENT_COVERED_NODES:
-    next = node->next[0];
-    while (next && next->first <= node->last + 1) {
-        if (next->last > node->last)
-            node->last = next->last;
-
-        /* Delete node 'next' */
-        for (i = 0; i < node->level && i < next->level; i++) {
-            node->next[i] = next->next[i];
-        }
-
-        for (; i < next->level; i++) {
-            *update[i] = next->next[i];
-        }
-
-        delete next;
-
-        next = node->next[0];
-    }
-}
-
-void
-CallSet::add(CallNo call_no)
-{
-    this->add(call_no, call_no);
-}
-
-bool
-CallSet::contains(CallNo call_no)
-{
-    CallRange *node;
-    int i;
-
-    node = &head;
-    for (i = max_level - 1; i >= 0; i--) {
-        while (node->next[i] && call_no > node->next[i]->last) {
-            node = node->next[i];
-        }
-    }
-
-    node = node->next[0];
-
-    if (node == NULL)
-        return false;
-
-    return node->contains(call_no);
-}
diff --git a/cli/trim_callset.hpp b/cli/trim_callset.hpp
deleted file mode 100644 (file)
index fb2c92a..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*********************************************************************
- *
- * Copyright 2012 Intel Corporation
- * Copyright 2012 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- *********************************************************************/
-
-#ifndef _TRIM_CALLSET_HPP_
-#define _TRIM_CALLSET_HPP_
-
-namespace trim {
-
-/* A set of call numbers.
- *
- * This is designed as a more efficient replacement for
- * std::set<unsigned> which is used heavily within the trim code's
- * TraceAnalyzer. This is quite similar to the trace::CallSet with the
- * following differences:
- *
- *   Simplifications:
- *
- *     * There is no support here for the 'step' and 'freq' features
- *       supported by trace::CallSet.
- *
- *   Sophistications:
- *
- *     * This callset is implemented with a skip list for
- *       (probabilistically) logarithmic lookup times for
- *       out-of-order lookups.
- *
- *     * This callset optimizes the addition of new calls which are
- *        within or adjacent to existing ranges, (by either doing
- *        nothing, expanding the limits of an existing range, or also
- *        merging two ranges). This keeps the length of the list down
- *        when succesively adding individual calls that could be
- *        efficiently expressed with a range.
- *
- * It would not be impossible to extend this code to support the
- * missing features of trace::CallSet, (though the 'step' and 'freq'
- * features would prevent some range-extending and merging
- * optimizations in some cases). Currently, trace::CallSet is not used
- * in any performance-critical areas, so it may not be important to
- * provide the performance imrpovements to it.
- */
-
-typedef unsigned CallNo;
-
-class CallRange {
-public:
-    CallNo first;
-    CallNo last;
-    int level;
-    CallRange **next;
-
-    CallRange(CallNo first, CallNo last, int level);
-
-    bool contains(CallNo call_no);
-};
-
-class CallSet {
-public:
-    CallRange head;
-    int max_level;
-
-    CallSet();
-
-    void add(CallNo first, CallNo last);
-
-    void add(CallNo call_no);
-
-    bool contains(CallNo call_no);
-};
-
-} /* namespace trim */
-
-#endif /* _TRIM_CALLSET_HPP_ */
index 4a4a52d397c6cef90804acfb0f16b5a7c931a6cc..a2f82134c558972eca41c090d660f4470a8105f1 100644 (file)
 
 namespace trace {
 
 
 namespace trace {
 
-
-    // Should match Call::no
-    typedef unsigned CallNo;
-
-
     // Aliases for call flags
     enum {
         FREQUENCY_NONE         = 0,
     // Aliases for call flags
     enum {
         FREQUENCY_NONE         = 0,
diff --git a/common/trace_fast_callset.cpp b/common/trace_fast_callset.cpp
new file mode 100644 (file)
index 0000000..d7c4edc
--- /dev/null
@@ -0,0 +1,202 @@
+/*********************************************************************
+ *
+ * Copyright 2006 Keith Packard and Carl Worth
+ * Copyright 2012 Intel Corporation
+ * Copyright 2012 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ *********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits>
+
+#include "trace_fast_callset.hpp"
+
+using namespace trace;
+
+#define MAX_LEVEL 16
+
+FastCallRange::FastCallRange(CallNo first, CallNo last, int level)
+{
+    this->first = first;
+    this->last = last;
+    this->level = level;
+
+    next = new FastCallRange*[level];
+}
+
+bool
+FastCallRange::contains(CallNo call_no)
+{
+    return (first <= call_no && last >= call_no);
+}
+
+FastCallSet::FastCallSet(): head(0, 0, MAX_LEVEL)
+{
+    head.first = std::numeric_limits<CallNo>::max();
+    head.last = std::numeric_limits<CallNo>::min();
+
+    for (int i = 0; i < MAX_LEVEL; i++)
+        head.next[i] = NULL;
+
+    max_level = 0;
+}
+
+/*
+ * Generate a random level number, distributed
+ * so that each level is 1/4 as likely as the one before
+ *
+ * Note that level numbers run 1 <= level < MAX_LEVEL
+ */
+static int
+random_level (void)
+{
+    /* tricky bit -- each bit is '1' 75% of the time */
+    long int bits = random() | random();
+    int        level = 1;
+
+    while (level < MAX_LEVEL)
+    {
+       if (bits & 1)
+           break;
+        level++;
+       bits >>= 1;
+    }
+
+    return level;
+}
+
+void
+FastCallSet::add(CallNo first, CallNo last)
+{
+    FastCallRange **update[MAX_LEVEL];
+    FastCallRange *node, *next;
+    int i, level;
+
+    /* Find node immediately before insertion point. */
+    node = &head;
+    for (i = max_level - 1; i >= 0; i--) {
+        while (node->next[i] && first > node->next[i]->last) {
+            node = node->next[i];
+        }
+        update[i] = &node->next[i];
+    }
+
+    /* Can we contain first by expanding tail of current range by 1? */
+    if (node != &head && node->last == first - 1) {
+
+        node->last = last;
+        goto MERGE_NODE_WITH_SUBSEQUENT_COVERED_NODES;
+
+    }
+
+    /* Current range could not contain first, look at next. */
+    node = node->next[0];
+
+    if (node) {
+        /* Do nothing if new range is already entirely contained. */
+        if (node->first <= first && node->last >= last) {
+            return;
+        }
+
+        /* If last is already included, we can simply expand
+         * node->first to fully include the range. */
+        if (node->first <= last && node->last >= last) {
+            node->first = first;
+            return;
+        }
+
+        /* This is our candidate node if first is contained */
+        if (node->first <= first && node->last >= first) {
+            node->last = last;
+            goto MERGE_NODE_WITH_SUBSEQUENT_COVERED_NODES;
+        }
+    }
+
+    /* Not possible to expand any existing node, so create a new one. */
+
+    level = random_level();
+
+    /* Handle first node of this level. */
+    if (level > max_level) {
+        level = max_level + 1;
+        update[max_level] = &head.next[max_level];
+        max_level = level;
+    }
+
+    node = new FastCallRange(first, last, level);
+
+    /* Perform insertion into all lists. */
+    for (i = 0; i < level; i++) {
+        node->next[i] = *update[i];
+        *update[i] = node;
+    }
+
+MERGE_NODE_WITH_SUBSEQUENT_COVERED_NODES:
+    next = node->next[0];
+    while (next && next->first <= node->last + 1) {
+        if (next->last > node->last)
+            node->last = next->last;
+
+        /* Delete node 'next' */
+        for (i = 0; i < node->level && i < next->level; i++) {
+            node->next[i] = next->next[i];
+        }
+
+        for (; i < next->level; i++) {
+            *update[i] = next->next[i];
+        }
+
+        delete next;
+
+        next = node->next[0];
+    }
+}
+
+void
+FastCallSet::add(CallNo call_no)
+{
+    this->add(call_no, call_no);
+}
+
+bool
+FastCallSet::contains(CallNo call_no)
+{
+    FastCallRange *node;
+    int i;
+
+    node = &head;
+    for (i = max_level - 1; i >= 0; i--) {
+        while (node->next[i] && call_no > node->next[i]->last) {
+            node = node->next[i];
+        }
+    }
+
+    node = node->next[0];
+
+    if (node == NULL)
+        return false;
+
+    return node->contains(call_no);
+}
diff --git a/common/trace_fast_callset.hpp b/common/trace_fast_callset.hpp
new file mode 100644 (file)
index 0000000..22893ab
--- /dev/null
@@ -0,0 +1,93 @@
+/*********************************************************************
+ *
+ * Copyright 2012 Intel Corporation
+ * Copyright 2012 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ *********************************************************************/
+
+#ifndef _TRACE_FAST_CALLSET_HPP_
+#define _TRACE_FAST_CALLSET_HPP_
+
+#include "trace_model.hpp"
+
+namespace trace {
+
+/* A set of call numbers.
+ *
+ * This was originally designed as a more efficient replacement for
+ * std::set<unsigned> which was used heavily within the trim code's
+ * TraceAnalyzer. This is quite similar to the trace::CallSet with the
+ * following differences:
+ *
+ *   Simplifications:
+ *
+ *     * There is no support here for the 'step' and 'freq' features
+ *       supported by trace::CallSet.
+ *
+ *   Sophistications:
+ *
+ *     * This callset is implemented with a skip list for
+ *       (probabilistically) logarithmic lookup times for
+ *       out-of-order lookups.
+ *
+ *     * This callset optimizes the addition of new calls which are
+ *        within or adjacent to existing ranges, (by either doing
+ *        nothing, expanding the limits of an existing range, or also
+ *        merging two or more ranges).
+ *
+ * It would not be impossible to extend this code to support the
+ * missing features of trace::CallSet, (though the 'step' and 'freq'
+ * features would prevent some range-extending and merging
+ * optimizations in some cases).
+ */
+
+class FastCallRange {
+public:
+    CallNo first;
+    CallNo last;
+    int level;
+    FastCallRange **next;
+
+    FastCallRange(CallNo first, CallNo last, int level);
+
+    bool contains(CallNo call_no);
+};
+
+class FastCallSet {
+public:
+    FastCallRange head;
+    int max_level;
+
+    FastCallSet();
+
+    void add(CallNo first, CallNo last);
+
+    void add(CallNo call_no);
+
+    bool contains(CallNo call_no);
+};
+
+} /* namespace trace */
+
+#endif /* _TRACE_FAST_CALLSET_HPP_ */
index 95582253190687446a4c0d98e529047c33e98155..93363219cdb271930104e35dfbecd3629da89251 100644 (file)
 namespace trace {
 
 
 namespace trace {
 
 
+// Should match Call::no
+typedef unsigned CallNo;
+
+
 typedef unsigned Id;
 
 
 typedef unsigned Id;