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



commit 24116bed1b702ae48ac5567dc7539219b64d28d7
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             |  164 ++++++++++++++++++++
 4 files changed, 184 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 5cc281b..1302ff7 100644
--- a/tests/functional-tests/Makefile.am
+++ b/tests/functional-tests/Makefile.am
@@ -72,7 +72,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
 
@@ -167,9 +168,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 		\
@@ -205,6 +219,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)		\
@@ -214,6 +229,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..76e570d
--- /dev/null
+++ b/tests/functional-tests/class-signal-performance-test.vala
@@ -0,0 +1,164 @@
+/*
+ * 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.
+
+// Testreport of Aug 25, 2010 by Philip
+// ------------------------------------
+// On Aug 25 the difference between using tracker-store on master and the
+// tracker-store of class-signal, and then letting this wait until all 10000
+// (in case of max_signals = 10000) insert queries' signals arrived (you'll
+// have in total 20002 events in the signals in both tracker-store versions)
+// was: 20s for class-signals (new class signal) and 23s for master (old class
+// signals). Measured using this performance test.
+//
+// Memory usage of class-signal (new class signal)'s tracker-store:
+// Low: VmRSS: 8860 Kb -- Max: VmRSS: 14116 kB
+//
+// Memory usage of master (old class signal)'s tracker-store:
+// Low: VmRSS: 8868 Kb -- Max: VmRSS: 14060 kB
+
+
+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]