[anjuta/sdb-core-trans] symbol-db: created bechmark/symbol-db
- From: Massimo Cora' <mcora src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/sdb-core-trans] symbol-db: created bechmark/symbol-db
- Date: Thu, 8 Jul 2010 20:59:20 +0000 (UTC)
commit c727337f1bdbe011f537e7e9739f2ba7ec152124
Author: Massimo Corà <mcora src gnome org>
Date: Thu Jul 8 01:04:23 2010 +0200
symbol-db: created bechmark/symbol-db
plugins/symbol-db/benchmark/symbol-db/Makefile.am | 32 +++++
plugins/symbol-db/benchmark/symbol-db/README | 14 ++
plugins/symbol-db/benchmark/symbol-db/benchmark.c | 139 ++++++++++++++++++++
.../benchmark/symbol-db/populate-test-dir.sh | 8 +
4 files changed, 193 insertions(+), 0 deletions(-)
---
diff --git a/plugins/symbol-db/benchmark/symbol-db/Makefile.am b/plugins/symbol-db/benchmark/symbol-db/Makefile.am
new file mode 100644
index 0000000..910cff6
--- /dev/null
+++ b/plugins/symbol-db/benchmark/symbol-db/Makefile.am
@@ -0,0 +1,32 @@
+noinst_PROGRAMS = \
+ benchmark
+
+
+AM_CPPFLAGS = $(LIBANJUTA_CFLAGS) \
+ $(PLUGIN_SYMBOL_DB_CFLAGS) \
+ -DDEBUG
+
+benchmark_SOURCES = \
+ benchmark.c
+
+
+benchmark_LDFLAGS = \
+ $(LIBANJUTA_LIBS) \
+ $(ANJUTA_LIBS) \
+ $(PLUGIN_SYMBOL_DB_LIBS)
+
+benchmark_LDADD = ../../libanjuta-symbol-db.la
+
+
+## File created by the gnome-build tools
+
+
+
+
+
+
+
+
+
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/symbol-db/benchmark/symbol-db/README b/plugins/symbol-db/benchmark/symbol-db/README
new file mode 100644
index 0000000..610cd4c
--- /dev/null
+++ b/plugins/symbol-db/benchmark/symbol-db/README
@@ -0,0 +1,14 @@
+To have good performances tests you can run:
+
+./populate-test-dir.sh
+
+and then
+
+valgrind --tool=callgrind --collect-systime=yes \
+ --callgrind-out-file=callgrind.out ./.libs/benchmark test-dir
+
+
+The former creates ./test-dir with all the sources of Anjuta and populate a db on
+that directory.
+The latter launches callgrind which enumerates a lot of data of the execution:
+functions call, timings, number of calls, etc.
diff --git a/plugins/symbol-db/benchmark/symbol-db/benchmark.c b/plugins/symbol-db/benchmark/symbol-db/benchmark.c
new file mode 100644
index 0000000..05fcea3
--- /dev/null
+++ b/plugins/symbol-db/benchmark/symbol-db/benchmark.c
@@ -0,0 +1,139 @@
+/* Symbol db performance stress test */
+
+
+#include "../../symbol-db-engine.h"
+#include <gtk/gtk.h>
+
+static GPtrArray *
+get_source_files_by_mime (const gchar* dir, const GHashTable *mimes)
+{
+ GPtrArray* files = g_ptr_array_new();
+ GFile *file;
+ GFileEnumerator *enumerator;
+ GFileInfo* info;
+ GError *error = NULL;
+ gchar *buildable_dir;
+
+ g_return_val_if_fail (dir != NULL, NULL);
+ g_return_val_if_fail (mimes != NULL, NULL);
+
+ if ((file = g_file_new_for_commandline_arg (dir)) == NULL)
+ return NULL;
+
+ enumerator = g_file_enumerate_children (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
+ G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, &error);
+
+ if (!enumerator)
+ {
+ g_warning ("Could not enumerate: %s %s\n",
+ g_file_get_path (file),
+ error->message);
+ g_error_free (error);
+ g_object_unref (file);
+ return files;
+ }
+
+ buildable_dir = g_file_get_path (file);
+
+ for (info = g_file_enumerator_next_file (enumerator, NULL, NULL); info != NULL;
+ info = g_file_enumerator_next_file (enumerator, NULL, NULL))
+ {
+ const gchar *mime_type = g_file_info_get_content_type (info);
+ if (!mime_type)
+ continue;
+ if (g_hash_table_lookup ((GHashTable*)mimes, mime_type) != NULL)
+ {
+ g_ptr_array_add (files, g_build_filename (buildable_dir, g_file_info_get_name (info), NULL));
+ }
+ }
+
+ g_free (buildable_dir);
+ g_object_unref (enumerator);
+ g_object_unref (file);
+
+ return files;
+}
+
+static void on_single_file_scan_end (SymbolDBEngine* engine, GPtrArray* files)
+{
+ static int i = 0;
+ g_message ("Finished [%d]: %s", i, (gchar*)g_ptr_array_index (files, i));
+ i++;
+}
+
+static void
+on_scan_end (SymbolDBEngine* engine, gpointer user_data)
+{
+ g_message ("on_scan_end ()");
+ symbol_db_engine_close_db (engine);
+ g_object_unref (engine);
+ exit(0);
+}
+
+int main (int argc, char** argv)
+{
+ SymbolDBEngine* engine;
+ GPtrArray* files;
+ GPtrArray* languages = g_ptr_array_new();
+ gchar* root_dir;
+ GFile *g_dir;
+ GHashTable *mimes;
+ int i;
+
+ gtk_init(&argc, &argv);
+ g_thread_init (NULL);
+ gda_init ();
+
+ if (argc != 2)
+ {
+ g_message ("Usage: benchmark <source_directory>");
+ return 1;
+ }
+
+ g_dir = g_file_new_for_path (argv[1]);
+ if (g_dir == NULL)
+ {
+ g_warning ("%s doesn't exist", argv[1]);
+ return -1;
+ }
+
+ root_dir = g_file_get_path (g_dir);
+
+ engine = symbol_db_engine_new_full ("anjuta-tags", "benchmark-db");
+
+ if (symbol_db_engine_open_db (engine, root_dir, root_dir) == DB_OPEN_STATUS_FATAL)
+ {
+ g_message ("Could not open database: %s", root_dir);
+ return -1;
+ }
+
+ symbol_db_engine_add_new_project (engine, NULL, root_dir);
+
+ mimes = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (mimes, "text/x-csrc", "text/x-csrc");
+ g_hash_table_insert (mimes, "text/x-chdr", "text/x-chdr");
+ g_hash_table_insert (mimes, "text/x-c++src", "text/x-c++src");
+ g_hash_table_insert (mimes, "text/x-c+++hdr", "text/x-c++hdr");
+
+ files = get_source_files_by_mime (root_dir, mimes);
+ g_hash_table_destroy (mimes);
+
+ for (i = 0; i < files->len; i++)
+ g_ptr_array_add (languages, "C");
+
+ g_signal_connect (engine, "scan-end", G_CALLBACK (on_scan_end), NULL);
+ g_signal_connect (G_OBJECT (engine), "single-file-scan-end",
+ G_CALLBACK (on_single_file_scan_end), files);
+
+ symbol_db_engine_add_new_files_full (engine, root_dir, files, languages, TRUE);
+
+ g_free (root_dir);
+ g_object_unref (g_dir);
+
+ gtk_main();
+
+ return 0;
+}
diff --git a/plugins/symbol-db/benchmark/symbol-db/populate-test-dir.sh b/plugins/symbol-db/benchmark/symbol-db/populate-test-dir.sh
new file mode 100755
index 0000000..df2fbda
--- /dev/null
+++ b/plugins/symbol-db/benchmark/symbol-db/populate-test-dir.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+TEST_DIR=./test-dir
+rm -fr $TEST_DIR
+mkdir $TEST_DIR
+for i in `find ../../../ -name "*.[c|h]"`; do
+cp $i $TEST_DIR
+done;
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]