Commit [3a440b] Maximize Restore History

initial stab at diffing profiles

John Levon John Levon 2005-04-12

1 2 > >> (Page 1 of 2)
added libpp/diff_container.cpp
changed libpp/Makefile.am
changed libpp/format_flags.h
changed libpp/format_output.cpp
changed libpp/format_output.h
changed libpp/profile_spec.cpp
changed libpp/profile_spec.h
changed libpp/symbol.h
changed libpp/symbol_functors.cpp
changed libpp/symbol_sort.cpp
changed libpp/symbol_sort.h
changed libutil++/Makefile.am
changed libutil++/string_manip.cpp
changed libutil++/string_manip.h
changed pp/.cvsignore
changed pp/common_option.cpp
changed pp/common_option.h
changed pp/opannotate.cpp
changed pp/opannotate_options.cpp
changed pp/opannotate_options.h
changed pp/oparchive.cpp
copied libpp/count_array.cpp -> libutil++/growable_vector.h
copied libpp/count_array.h -> libpp/diff_container.h
libpp/diff_container.cpp Diff Switch to side-by-side view
Loading...
libpp/Makefile.am Diff Switch to side-by-side view
Loading...
libpp/format_flags.h Diff Switch to side-by-side view
Loading...
libpp/format_output.cpp Diff Switch to side-by-side view
Loading...
libpp/format_output.h Diff Switch to side-by-side view
Loading...
libpp/profile_spec.cpp Diff Switch to side-by-side view
Loading...
libpp/profile_spec.h Diff Switch to side-by-side view
Loading...
libpp/symbol.h Diff Switch to side-by-side view
Loading...
libpp/symbol_functors.cpp Diff Switch to side-by-side view
Loading...
libpp/symbol_sort.cpp Diff Switch to side-by-side view
Loading...
libpp/symbol_sort.h Diff Switch to side-by-side view
Loading...
libutil++/Makefile.am Diff Switch to side-by-side view
Loading...
libutil++/string_manip.cpp Diff Switch to side-by-side view
Loading...
libutil++/string_manip.h Diff Switch to side-by-side view
Loading...
pp/.cvsignore Diff Switch to side-by-side view
Loading...
pp/common_option.cpp Diff Switch to side-by-side view
Loading...
pp/common_option.h Diff Switch to side-by-side view
Loading...
pp/opannotate.cpp Diff Switch to side-by-side view
Loading...
pp/opannotate_options.cpp Diff Switch to side-by-side view
Loading...
pp/opannotate_options.h Diff Switch to side-by-side view
Loading...
pp/oparchive.cpp Diff Switch to side-by-side view
Loading...
libpp/count_array.cpp to libutil++/growable_vector.h
--- a/libpp/count_array.cpp
+++ b/libutil++/growable_vector.h
@@ -1,65 +1,93 @@
 /**
- * @file count_array.cpp
- * Container for holding sample counts
+ * @file growable_vector.h
+ * Auto-expanding vector type
  *
  * @remark Copyright 2002 OProfile authors
  * @remark Read the file COPYING
  *
+ * @author John Levon
  * @author Philippe Elie
- * @author John Levon
  */
 
+#ifndef GROWABLE_VECTOR_H
+#define GROWABLE_VECTOR_H
+
+#include <vector>
 #include <algorithm>
 #include <functional>
 
-#include "count_array.h"
+/**
+ * A simple growable vector template.
+ */
+template <typename T> class growable_vector {
+public:
+	typedef std::vector<T> container_type;
+	typedef typename container_type::size_type size_type;
 
-using namespace std;
- 
-u32 count_array_t::operator[](size_type index) const
-{
-	if (index >= container.size())
-		return 0;
-	return container[index];
-}
+	/// return current size of vector
+	size_type size() const {
+		return container.size();
+	}
 
+	/**
+	 * Index into the vector for a value. An out of
+	 * bounds index will return a default-constructed value.
+	 */
+	T operator[](size_type index) const {
+		if (index >= container.size())
+			return 0;
+		return container[index];
+	}
 
-u32 & count_array_t::operator[](size_type index)
-{
-	if (index >= container.size())
-		container.resize(index + 1);
-	return container[index];
-}
+	/**
+	 * Index into the vector for a value. If the index is larger than
+	 * the current max index, the array is expanded, default-filling
+	 * any intermediary gaps.
+	 */
+	T & operator[](size_type index) {
+		if (index >= container.size())
+			container.resize(index + 1);
+		return container[index];
+	}
 
+	/**
+	 * vectorized += operator
+	 */
+	growable_vector<T> & operator+=(growable_vector<T> const & rhs) {
+		if (rhs.container.size() > container.size())
+			container.resize(rhs.container.size());
 
-count_array_t & count_array_t::operator+=(count_array_t const & rhs)
-{
-	if (rhs.container.size() > container.size())
-		container.resize(rhs.container.size());
+		size_type min_size = min(container.size(), rhs.container.size());
+		for (size_type i = 0 ; i < min_size; ++i)
+			container[i] += rhs.container[i];
 
-	size_type min_size = min(container.size(), rhs.container.size());
-	for (size_type i = 0 ; i < min_size; ++i)
-		container[i] += rhs.container[i];
+		return *this;
+	}
 
-	return *this;
-}
+	/**
+	 * vectorized -= operator, overflow shouldn't occur during substraction
+	 * (iow: for each components lhs[i] >= rhs[i]
+	 */
+	growable_vector<T> & operator-=(growable_vector<T> const & rhs) {
+		if (rhs.container.size() > container.size())
+			container.resize(rhs.container.size());
 
+		size_type min_size = min(container.size(), rhs.container.size());
+		for (size_type i = 0 ; i < min_size; ++i)
+			container[i] -= rhs.container[i];
 
-count_array_t & count_array_t::operator-=(count_array_t const & rhs)
-{
-	if (rhs.container.size() > container.size())
-		container.resize(rhs.container.size());
+		return *this;
+	}
 
-	size_type min_size = min(container.size(), rhs.container.size());
-	for (size_type i = 0 ; i < min_size; ++i)
-		container[i] -= rhs.container[i];
+	/// return true if all elements have the default constructed value
+	bool zero() const {
+		return std::find_if(container.begin(), container.end(),
+	                            std::bind2nd(std::not_equal_to<T>(), T( )))
+                	== container.end();
+	}
 
-	return *this;
-}
+private:
+	container_type container;
+};
 
-
-bool count_array_t::zero() const
-{
-	return find_if(container.begin(), container.end(),
-	               bind2nd(not_equal_to<int>(), 0)) == container.end();
-}
+#endif // GROWABLE_VECTOR_H
libpp/count_array.h to libpp/diff_container.h
--- a/libpp/count_array.h
+++ b/libpp/diff_container.h
@@ -1,60 +1,46 @@
 /**
- * @file count_array.h
- * Container for holding sample counts
+ * @file diff_container.h
+ * Container for diffed symbols
  *
- * @remark Copyright 2002 OProfile authors
+ * @remark Copyright 2005 OProfile authors
  * @remark Read the file COPYING
  *
+ * @author Philippe Elie
  * @author John Levon
- * @author Philippe Elie
  */
 
-#ifndef COUNT_ARRAY_H
-#define COUNT_ARRAY_H
+#ifndef DIFF_CONTAINER_H
+#define DIFF_CONTAINER_H
 
-#include "op_types.h"
-#include <vector>
+#include "profile_container.h"
+#include "symbol.h"
 
 /**
- * A simple container of sample counts for a set of profile classes.
- * This is used by opreport for side-by-side, describing the sample
- * counts for a row of output. For example a report with two events
- * would use two profile classes, one for each event.
+ * Store two profiles for diffing.
  */
-class count_array_t {
+class diff_container : noncopyable {
 public:
-	typedef std::vector<u32> container_type;
-	typedef container_type::size_type size_type;
+	/// populate the collection of diffed symbols
+	diff_container(profile_container const & pc1,
+	               profile_container const & pc2);
 
-	/**
-	 * Index into the classes for a count value. An out of
-	 * bounds index will return a value of zero.
-	 */
-	u32 operator[](size_type index) const;
+	~diff_container() {}
+ 
+	/// return a collection of diffed symbols
+	diff_collection const get_symbols() const;
 
-	/**
-	 * Index into the classes for a count value. If the index
-	 * is larger than the current max index, the array is expanded,
-	 * zero-filling any intermediary gaps.
-	 */
-	u32 & operator[](size_type index);
-
-	/// return true if all values are zero
-	bool zero() const;
-
-	/**
-	 * vectorized += operator
-	 */
-	count_array_t & operator+=(count_array_t const & rhs);
-
-	/**
-	 * vectorized -= operator, overflow shouldn't occur during substraction
-	 * (iow: for each components lhs[i] >= rhs[i]
-	 */
-	count_array_t & operator-=(count_array_t const & rhs);
+	/// total count for 'new' profile
+	count_array_t const samples_count() const;
 
 private:
-	container_type container;
+	/// the diffed symbols
+	diff_collection syms;
+
+	/// samples count for pc1
+	count_array_t total1;
+
+	/// samples count for pc2
+	count_array_t total2;
 };
 
-#endif // COUNT_ARRAY_H
+#endif /* !DIFF_CONTAINER_H */
1 2 > >> (Page 1 of 2)