From: Philippe E. <ph...@us...> - 2002-12-03 01:58:01
|
Update of /cvsroot/oprofile/oprofile/pp In directory sc8-pr-cvs1:/tmp/cvs-serv28058/pp Modified Files: op_merge.cpp samples_file.cpp samples_file.h Log Message: merge from db-branch-1 to head removing module hash table and change implementation of samples files to use a hash table. regards, Phil Index: op_merge.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/op_merge.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- op_merge.cpp 1 Dec 2002 06:17:36 -0000 1.32 +++ op_merge.cpp 3 Dec 2002 01:57:58 -0000 1.33 @@ -186,14 +186,16 @@ samples_db_t dest; - db_open(&dest, filename.c_str(), DB_RDWR, sizeof(struct opd_header)); + db_open(&dest, filename.c_str(), DB_RDWR, + sizeof(struct opd_header)); for (++it ; it != filenames.end() ; ++it) { samples_db_t src; - db_open(&src, it->c_str(), DB_RDONLY, sizeof(struct opd_header)); + db_open(&src, it->c_str(), DB_RDONLY, + sizeof(struct opd_header)); - db_travel(&src, 0, ~0, copy_callback, &dest); + samples_db_travel(&src, 0, ~0, copy_callback, &dest); db_close(&src); } @@ -221,4 +223,3 @@ return EXIT_SUCCESS; } - Index: samples_file.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/samples_file.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- samples_file.cpp 1 Dec 2002 06:17:36 -0000 1.24 +++ samples_file.cpp 3 Dec 2002 01:57:58 -0000 1.25 @@ -40,6 +40,8 @@ "mismatch ?" << endl; exit(EXIT_FAILURE); } + + build_ordered_samples(); } samples_file_t::~samples_file_t() @@ -76,19 +78,30 @@ } } -static void samples_db_callback(db_key_t, db_value_t value, void * data) +void samples_file_t::build_ordered_samples() { - u32 * count = (u32 *)data; + db_node_nr_t node_nr, pos; + db_node_t * node = db_get_iterator(&samples_db, &node_nr); - *count += value; + for ( pos = 0 ; pos < node_nr ; ++pos) { + if (node[pos].key) { + ordered_samples_t::value_type val(node[pos].key, + node[pos].value); + ordered_samples.insert(val); + } + } } u32 samples_file_t::count(uint start, uint end) const { u32 count = 0; - db_travel(&samples_db, start - start_offset, end - start_offset, - samples_db_callback, &count); + ordered_samples_t::const_iterator first, last; + first = ordered_samples.lower_bound(start - start_offset); + last = ordered_samples.lower_bound(end - start_offset); + for ( ; first != last ; ++first) { + count += first->second; + } return count; } Index: samples_file.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/samples_file.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- samples_file.h 1 Dec 2002 06:17:36 -0000 1.20 +++ samples_file.h 3 Dec 2002 01:57:58 -0000 1.21 @@ -13,8 +13,9 @@ #define SAMPLES_FILE_H #include <string> +#include <map> -#include "db.h" +#include "db-hash.h" #include "op_types.h" #include "op_hw_config.h" #include "utility.h" @@ -80,9 +81,23 @@ void set_start_offset(u32 start_offset_) { start_offset = start_offset_; } + private: + /// storage type for samples sorted by eip + typedef std::map<db_key_t, db_value_t> ordered_samples_t; + /// helper to build ordered samples by eip + void build_ordered_samples(); + /// the underlying db object samples_db_t samples_db; + + /** + * Samples are stored in hash table, iterating over hash table don't + * provide any ordering, the above count() interface rely on samples + * ordered by eip. This map is only a temporary storage where samples + * are ordered by eip. + */ + ordered_samples_t ordered_samples; /** * For the kernel and kernel modules, this value is non-zero and |