[tracker/class-signal] functional-tests: class-signal: Add performance test



commit 27fac3d2a4dd08a4d3c72daab9b5f3a5572c5070
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Aug 25 15:15:32 2010 +0200

    functional-tests: class-signal: Add performance test

 examples/class-signal/.gitignore                   |    1 +
 tests/functional-tests/.gitignore                  |    2 +
 tests/functional-tests/Makefile.am                 |   18 +++-
 .../class-signal-performance-test.vala             |  148 ++++++++++++++++++++
 4 files changed, 168 insertions(+), 1 deletions(-)
---
diff --git a/examples/class-signal/.gitignore b/examples/class-signal/.gitignore
new file mode 100644
index 0000000..9266138
--- /dev/null
+++ b/examples/class-signal/.gitignore
@@ -0,0 +1 @@
+class-signal
diff --git a/tests/functional-tests/.gitignore b/tests/functional-tests/.gitignore
index 34f2b9d..4e59827 100644
--- a/tests/functional-tests/.gitignore
+++ b/tests/functional-tests/.gitignore
@@ -1,3 +1,5 @@
+class-signal-performance-test
+class-signal-performance-test.c
 class-signal-test
 class-signal-test.c
 shared-query-test.c
diff --git a/tests/functional-tests/Makefile.am b/tests/functional-tests/Makefile.am
index c3625e4..f5789e6 100644
--- a/tests/functional-tests/Makefile.am
+++ b/tests/functional-tests/Makefile.am
@@ -66,7 +66,8 @@ noinst_PROGRAMS = busy-handling-test \
 	bus-query-test \
 	default-update-test \
 	bus-update-test \
-	class-signal-test
+	class-signal-test \
+	class-signal-performance-test
 
 busy_handling_test_VALASOURCES = busy-handling-test.vala
 
@@ -161,9 +162,22 @@ class-signal-test.vala.stamp: $(class_signal_test_VALASOURCES) $(direct_vapi_sou
 
 class_signal_test_LDADD = $(direct_query_test_LDADD)
 
+class_signal_performance_test_VALASOURCES = class-signal-performance-test.vala
+
+class_signal_performance_test_SOURCES = \
+	class-signal-performance-test.vala.stamp \
+	$(class_signal_performance_test_VALASOURCES:.vala=.c)
+
+class-signal-performance-test.vala.stamp: $(class_signal_performance_test_VALASOURCES) $(direct_vapi_sources)
+	$(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 $^
+	$(AM_V_GEN)touch $@
+
+class_signal_performance_test_LDADD = $(direct_query_test_LDADD)
+
 BUILT_SOURCES = 				\
 	busy-handling-test.vala.stamp 		\
 	class-signal-test.vala.stamp 		\
+	class-signal-performance-test.vala.stamp \
 	direct-query-test.vala.stamp 		\
 	bus-query-test.vala.stamp 		\
 	default-update-test.vala.stamp 		\
@@ -199,6 +213,7 @@ EXTRA_DIST = 					\
 	$(BUILT_SOURCES)			\
 	$(busy_handling_test_VALASOURCES)	\
 	$(class_signal_test_VALASOURCES)	\
+	$(class_signal_performance_test_VALASOURCES) \
 	$(direct_query_test_VALASOURCES)	\
 	$(default_update_test_VALASOURCES)	\
 	$(bus_query_test_VALASOURCES)		\
@@ -208,6 +223,7 @@ MAINTAINERCLEANFILES =					\
 	$(BUILT_SOURCES)				\
 	$(busy_handling_test_VALASOURCES:.vala=.c)	\
 	$(class_signal_test_VALASOURCES:.vala=.c)	\
+	$(class_signal_performance_test_VALASOURCES:.vala=.c) \
 	$(bus_query_test_VALASOURCES:.vala=.c)		\
 	$(bus_update_test_VALASOURCES:.vala=.c)		\
 	$(direct_query_test_VALASOURCES:.vala=.c)	\
diff --git a/tests/functional-tests/class-signal-performance-test.vala b/tests/functional-tests/class-signal-performance-test.vala
new file mode 100644
index 0000000..b520271
--- /dev/null
+++ b/tests/functional-tests/class-signal-performance-test.vala
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2008, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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 Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+using Tracker;
+using Tracker.Sparql;
+
+const int max_signals = 1000;
+// const int max_signals = 10000;
+const string title_data = "title";
+
+// Always start this test AFTER DOING tracker-control -r
+// The test IS NOT deleting existing resources, so you CAN'T RUN IT TWICE unless
+// you clear the database before starting it the second time.
+
+struct Event {
+	int subject_id;
+	int pred_id;
+	int object_id;
+}
+
+[DBus (name = "org.freedesktop.Tracker1.Resources")]
+private interface Resources : GLib.Object {
+	[DBus (name = "ClassSignal")]
+	public signal void class_signal (string class_name, Event[] deletes, Event[] inserts);
+
+	[DBus (name = "SparqlUpdate")]
+	public abstract async void sparql_update_async (string query) throws Sparql.Error, DBus.Error;
+}
+
+[DBus (name = "org.freedesktop.Tracker1.Resources.Class")]
+private interface ResourcesClass : GLib.Object {
+	[DBus (name = "SubjectsAdded")]
+	public signal void subjects_added (string [] subjects);
+	[DBus (name = "SubjectsChanged")]
+	public signal void subjects_changed (string [] subjects, string [] preds);
+}
+
+public class TestApp {
+	static DBus.Connection dbus_connection;
+	static Resources resources_object;
+	static ResourcesClass class_object;
+	MainLoop loop;
+	bool initialized = false;
+	Sparql.Connection con;
+	int count = 0;
+	GLib.Timer t;
+
+	public TestApp ()
+	requires (!initialized) {
+		try {
+			con = Tracker.Sparql.Connection.get();
+			dbus_connection = DBus.Bus.get (DBus.BusType.SESSION);
+			resources_object = (Resources) dbus_connection.get_object ("org.freedesktop.Tracker1",
+			                                                           "/org/freedesktop/Tracker1/Resources",
+			                                                           "org.freedesktop.Tracker1.Resources");
+
+			try {
+				class_object = (ResourcesClass) dbus_connection.get_object ("org.freedesktop.Tracker1",
+			                                                                "/org/freedesktop/Tracker1/Resources/Classes/nmm/MusicPiece",
+			                                                                "org.freedesktop.Tracker1.Resources.Class");
+			
+				class_object.subjects_added.connect (on_subjects_added);
+				class_object.subjects_changed.connect (on_subjects_changed);
+			} catch (GLib.Error e) {
+			}
+
+			resources_object.class_signal.connect (on_class_signal_received);
+			t = new GLib.Timer ();
+			
+		} catch (Sparql.Error e) {
+			warning ("Could not connect to D-Bus service: %s", e.message);
+			initialized = false;
+			return;
+		} catch (DBus.Error e) {
+			warning ("Could not connect to D-Bus service: %s", e.message);
+			initialized = false;
+			return;
+		}
+		initialized = true;
+	}
+
+	private void on_subjects_changed (string [] subjects, string [] preds) {
+		foreach (string s in subjects)
+			count++;
+
+		//if (count == 20002)
+			print ("Old class signal count=%d time=%lf\n", count, t.elapsed ());
+	}
+
+	private void on_subjects_added (string [] subjects) {
+		foreach (string s in subjects)
+			count++;
+
+		//if (count == 20002)
+			print ("Old class signal count=%d time=%lf\n", count, t.elapsed ());
+	}
+
+	private void on_class_signal_received (string class_name, Event[] deletes, Event[] inserts) {
+		foreach (Event insert in inserts)
+			count++;
+		//if (count == 20002)
+			print ("New class signal count=%d time=%lf\n", count, t.elapsed ());
+	}
+
+	private void insert_data () {
+		int i;
+
+		t.start();
+		for (i = 0; i <= max_signals; i++) {
+			string upqry = "INSERT { <%d> a nmm:MusicPiece ; nie:title '%s %d' }".printf(i, title_data, i);
+			resources_object.sparql_update_async (upqry);
+		}
+	}
+
+	private bool in_mainloop () {
+		insert_data ();
+		return false;
+	}
+
+	public int run () {
+		loop = new MainLoop (null, false);
+		Idle.add (in_mainloop);
+		loop.run ();
+		return 0;
+	}
+}
+
+int main (string[] args) {
+	TestApp app = new TestApp ();
+
+	return app.run ();
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]