Commit [5bbfc9] Maximize Restore History

merge branch-db-1 with trunk. This change the samples file format
to use a database oriented file format. See commit on branch-db-1
and ChangeLog for further details

Phil

Philippe Elie Philippe Elie 2002-04-24

1 2 > >> (Page 1 of 2)
added libdb
added libdb/.cvsignore
added libdb/ChangeLog
added libdb/Makefile
added libdb/Makefile.in
added libdb/db-debug.c
added libdb/db-insert.c
added libdb/db-manage.c
added libdb/db-travel.c
added libdb/db.h
changed ChangeLog
changed Makefile.in
changed configure.in
changed dae
changed dae/Makefile.in
changed dae/opd_proc.c
changed dae/opd_util.h
changed dae/oprofiled.h
changed oprof_report
changed oprof_report/Makefile.in
changed oprof_report/oprof_report.cpp
changed pp
changed pp/Makefile.in
changed pp/op_merge.cpp
changed pp/op_time.cpp
changed pp/opf_container.cpp
changed pp/opf_filter.cpp
changed pp/oprofpp.cpp
changed pp/oprofpp.h
changed pp/oprofpp_util.cpp
changed util
copied util/shared_ptr.h -> libdb/db-test.c
libdb
Directory.
libdb/.cvsignore Diff Switch to side-by-side view
Loading...
libdb/ChangeLog Diff Switch to side-by-side view
Loading...
libdb/Makefile Diff Switch to side-by-side view
Loading...
libdb/Makefile.in Diff Switch to side-by-side view
Loading...
libdb/db-debug.c Diff Switch to side-by-side view
Loading...
libdb/db-insert.c Diff Switch to side-by-side view
Loading...
libdb/db-manage.c Diff Switch to side-by-side view
Loading...
libdb/db-travel.c Diff Switch to side-by-side view
Loading...
libdb/db.h Diff Switch to side-by-side view
Loading...
ChangeLog Diff Switch to side-by-side view
Loading...
Makefile.in Diff Switch to side-by-side view
Loading...
configure.in Diff Switch to side-by-side view
Loading...
dae
Directory.
dae/Makefile.in Diff Switch to side-by-side view
Loading...
dae/opd_proc.c Diff Switch to side-by-side view
Loading...
dae/opd_util.h Diff Switch to side-by-side view
Loading...
dae/oprofiled.h Diff Switch to side-by-side view
Loading...
oprof_report
Directory.
oprof_report/Makefile.in Diff Switch to side-by-side view
Loading...
oprof_report/oprof_report.cpp Diff Switch to side-by-side view
Loading...
pp
Directory.
pp/Makefile.in Diff Switch to side-by-side view
Loading...
pp/op_merge.cpp Diff Switch to side-by-side view
Loading...
pp/op_time.cpp Diff Switch to side-by-side view
Loading...
pp/opf_container.cpp Diff Switch to side-by-side view
Loading...
pp/opf_filter.cpp Diff Switch to side-by-side view
Loading...
pp/oprofpp.cpp Diff Switch to side-by-side view
Loading...
pp/oprofpp.h Diff Switch to side-by-side view
Loading...
pp/oprofpp_util.cpp Diff Switch to side-by-side view
Loading...
util
Directory.
util/shared_ptr.h to libdb/db-test.c
--- a/util/shared_ptr.h
+++ b/libdb/db-test.c
@@ -1,102 +1,176 @@
-/* COPYRIGHT (C) 2001 Philippe Elie
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * first written by P.Elie
- */
+#include <sys/resource.h>
+#include <stdlib.h>
+#include <stdio.h>
 
-#ifndef SHARED_PTR_H
-#define SHARED_PTR_H
+#include "db.h"
 
-/**
- * A non intrusive shared pointer ala Copliend w/o invariant
- * for the Letter internal class and assuming than object is never nil.
- *
- * can be improved if neccessary by using a specialized allocator
- * for the letter pointer
- * unecessary operator for now are commented out.
- * don't add conversion operator to T* please, rather add 
- * explicit T& getter if necessary (or uncomment the T& conversion ?)
- */
-template<class T> class SharedPtr
+#define TEST_FILENAME "test-db.dat"
+
+static int nr_error;
+
+static double user_time(void)
 {
-public:
-	explicit SharedPtr(T * object) : letter(new Letter(object)) {}
-	SharedPtr(const SharedPtr & src);
-	~SharedPtr() { letter->release(); }
+  struct rusage  usage;
 
-	SharedPtr & operator=(const SharedPtr & rhs);
-	// a hole for bug ?
-//	SharedPtr & operator=(T* object);
+  getrusage(RUSAGE_SELF, &usage);
 
-	T* operator->() { return letter->object; }
-	const T* operator->() const { return letter->object; }
-
-	// conversion to T* are dangerous can we allow conversion to T& ?
-	T& operator *() { return *letter->object; }
-	const T& operator *() const { return *letter->object; }
-
-private:
-	// Take care, this class have no invariant between public member call.
-	// Invariant are maintained between public calls of SharedPtr. Safety
-	// is provided only through the private decl of Letter.
-	struct Letter
-	{
-		explicit Letter(T* object_) : object(object_), ref_count(1) {}
-		~Letter() { delete object; }
-
-		void addRef()  { ref_count++; }
-		void release() { if (--ref_count == 0) delete this; }
-
-		T*  object;
-		int ref_count;
-	};
-
-	Letter * letter;
-};
-
-template <class T>
-inline SharedPtr<T>::SharedPtr(const SharedPtr & src)
-	:
-	letter(src.letter)
-{
-	letter->addRef();
+  return usage.ru_utime.tv_sec + (usage.ru_utime.tv_usec / 1000000.0);
 }
 
-template<class T>
-SharedPtr<T>& SharedPtr<T>::operator=(const SharedPtr<T>& rhs)
+/* create nr item randomly created with nr_unique_item distinct items */
+static void speed_test(size_t nr_item, size_t nr_unique_item)
 {
-	rhs.letter->addRef();
-	letter->release();
-	letter = rhs.letter;
+	size_t i;
+	double begin, end;
+	db_tree_t tree;
 
-	return *this;
+	db_open(&tree, TEST_FILENAME, 128);
+	begin = user_time();
+	for (i = 0 ; i < nr_item ; ++i) {
+		db_insert(&tree, (random() % nr_unique_item) + 1, 1);
+	}
+	end = user_time();
+	db_close(&tree);
+
+	remove(TEST_FILENAME);
+
+	fprintf(stderr, "nr item: %d, unique item: %d, elapsed: %f\n",
+		nr_item, nr_unique_item, end - begin);
 }
 
-#if 0
-// original implementation have this operator but that now look like bad
-// at my eyes and I don't remember if a it's needed.
-template<class T>
-SharedPtr<T>& SharedPtr<T>::operator=(T* object)
+static void do_speed_test(void)
 {
-	if (letter->object != object) {
-		letter->release();
-		letter = new Letter(object);  // assume object non null.
+	int i, j;
+
+	for (i = 1000 ; i <= 1000000 ; i *= 10) {
+		for (j = 100 ; j <= i / 10 ; j *= 10) {
+			speed_test(i, j);
+		}
+	}
+}
+
+static int test(size_t nr_item, size_t nr_unique_item)
+{
+	size_t i;
+	db_tree_t tree;
+	int ret;
+
+	db_open(&tree, TEST_FILENAME, 128);
+
+
+	for (i = 0 ; i < nr_item ; ++i) {
+		db_insert(&tree, (random() % nr_unique_item) + 1, 1);
 	}
 
-	return *this;
+	ret = db_check_tree(&tree);
+
+	db_close(&tree);
+
+	remove(TEST_FILENAME);
+
+	return ret;
 }
-#endif
 
-#endif /* !SHARED_PTR_H */
+static void do_test(void)
+{
+	int i, j;
+
+	for (i = 1000 ; i <= 1000000 ; i *= 10) {
+		for (j = 100 ; j <= i / 10 ; j *= 10) {
+			if (test(i, j)) {
+				printf("%s:%d failure for %d %d\n",
+				       __FILE__, __LINE__, i, j);
+				nr_error++;
+			} else {
+				printf("test() ok %d %d\n", i, j);
+			}
+		}
+	}
+}
+
+
+static db_key_t range_first, range_last;
+static db_key_t last_key_found;
+static void call_back(db_key_t key, db_value_t info, void * data)
+{
+	if (&info) {} if (&data) {}	/* suppress unused parameters */
+
+	if (key <= last_key_found) {
+		printf("%x %x\n", key, last_key_found);
+		nr_error++;
+	}
+
+	if (key < range_first || key >= range_last) {
+		printf("%x %x %x\n", key, range_first, range_last);
+		nr_error++;
+	}
+
+	last_key_found = key;
+}
+
+static int callback_test(size_t nr_item, size_t nr_unique_item)
+{
+	size_t i;
+	db_tree_t tree;
+	db_key_t first_key, last_key;
+	int old_nr_error = nr_error;
+
+	db_open(&tree, TEST_FILENAME, 128);
+
+	for (i = 0 ; i < nr_item ; ++i) {
+		db_insert(&tree, (random() % nr_unique_item) + 1, 1);
+	}
+
+
+	last_key = (db_key_t)-1;
+	first_key = 0;
+	
+	for ( ; first_key < last_key ; last_key /= 2) {
+
+		last_key_found = first_key == 0 ? first_key : first_key - 1;
+		range_first = first_key;
+		range_last = last_key;
+
+		db_travel(&tree, first_key, last_key, call_back, 0);
+
+		first_key = first_key == 0 ? 1 : first_key * 2;
+	}
+
+	db_close(&tree);
+
+	remove(TEST_FILENAME);
+
+	return old_nr_error == nr_error ? 0 : 1;
+}
+
+static void do_callback_test(void)
+{
+	int i, j;
+	for (i = 1000 ; i <= 1000000 ; i *= 10) {
+		for (j = 100 ; j <= i / 10 ; j *= 10)
+			if (callback_test(i, j)) {
+				printf("%s:%d failure for %d %d\n",
+				       __FILE__, __LINE__, i, j);
+				nr_error++;
+			} else {
+				printf("callback_test() ok %d %d\n", i, j);
+			}
+	}
+}
+
+int main(void)
+{
+	do_test();
+
+	do_callback_test();
+
+	do_speed_test();
+
+	if (nr_error) {
+		printf("%d error occured\n", nr_error);
+	} else {
+		printf("no error occur\n");
+	}
+
+	return 0;
+}
1 2 > >> (Page 1 of 2)