banshee r5196 - in trunk/banshee: . tests/Performance



Author: gburt
Date: Thu Apr  9 00:00:38 2009
New Revision: 5196
URL: http://svn.gnome.org/viewvc/banshee?rev=5196&view=rev

Log:
2009-04-08  Gabriel Burt  <gabriel burt gmail com>

	* src/tests/Performance/Makefile.am: Also build an exe, useful for
	drilling into a performance problem with mono --profile.

	* src/tests/Performance/PerformanceTests.cs: Categorize tests, add
	FetchTrack, LoadTrack, and Select* tests testing relatively low level db
	operations.

Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/tests/Performance/Makefile.am
   trunk/banshee/tests/Performance/PerformanceTests.cs

Modified: trunk/banshee/tests/Performance/Makefile.am
==============================================================================
--- trunk/banshee/tests/Performance/Makefile.am	(original)
+++ trunk/banshee/tests/Performance/Makefile.am	Thu Apr  9 00:00:38 2009
@@ -1,13 +1,17 @@
 include $(top_srcdir)/build/build.environment.mk
 
 PERFORMANCE_ASSEMBLY = Performance.dll
+PERFORMANCE_EXE = Performance.exe
 
-ALL_TARGETS = $(PERFORMANCE_ASSEMBLY)
+ALL_TARGETS = $(PERFORMANCE_ASSEMBLY) $(PERFORMANCE_EXE)
 
 $(PERFORMANCE_ASSEMBLY): PerformanceTests.cs
 	$(MCS) -target:library -r:$(DIR_BIN)/Hyena.dll $(NUNIT_LIBS) $(LINK_BANSHEE_THICKCLIENT_DEPS) -out:$@ $<
 
+$(PERFORMANCE_EXE): PerformanceTests.cs
+	$(MCS) -target:exe -r:$(DIR_BIN)/Hyena.dll $(NUNIT_LIBS) $(LINK_BANSHEE_THICKCLIENT_DEPS) -out:$@ $<
+
 all: $(ALL_TARGETS)
 
-CLEANFILES = *.dll *.mdb
+CLEANFILES = *.dll *.exe *.mdb
 MAINTAINERCLEANFILES = Makefile.in

Modified: trunk/banshee/tests/Performance/PerformanceTests.cs
==============================================================================
--- trunk/banshee/tests/Performance/PerformanceTests.cs	(original)
+++ trunk/banshee/tests/Performance/PerformanceTests.cs	Thu Apr  9 00:00:38 2009
@@ -27,16 +27,19 @@
 //
 
 using System;
+using System.Data;
 using System.Threading;
 using NUnit.Framework;
 
 using Hyena;
 using Hyena.Data;
+using Hyena.Data.Sqlite;
 using Hyena.Query;
 using Hyena.CommandLine;
 
 using Banshee.Base;
 using Banshee.Collection;
+using Banshee.Collection.Database;
 using Banshee.Query;
 using Banshee.ServiceStack;
 
@@ -46,6 +49,7 @@
     public class PerformanceTests
     {
         const int NUM = 50;
+        private string select_single_command;
 
 #region Reload tests
 
@@ -63,36 +67,42 @@
         }
 
         [Test]
+        [Category ("Performance")]
         public void Reload ()
         {
             ReloadMusicLibrary ("", .25);
         }
 
         [Test]
+        [Category ("Performance")]
         public void ReloadD ()
         {
             ReloadMusicLibrary ("d", .25);
         }
 
         [Test]
+        [Category ("Performance")]
         public void ReloadDave ()
         {
             ReloadMusicLibrary ("dave");
         }
 
         [Test]
+        [Category ("Performance")]
         public void ReloadByDave ()
         {
             ReloadMusicLibrary ("by:dave");
         }
 
         [Test]
+        [Category ("Performance")]
         public void ReloadFavorites ()
         {
             ReloadMusicLibrary ("rating>3");
         }
 
         [Test]
+        [Category ("Performance")]
         public void ReloadGenreRock ()
         {
             ReloadMusicLibrary ("genre:rock");
@@ -100,7 +110,10 @@
 
 #endregion
 
+#region Access tests
+
         [Test]
+        [Category ("Performance")]
         public void ScrollLinear ()
         {
             music_library.FilterQuery = "";
@@ -117,6 +130,92 @@
             Assert.IsFalse (any_null);
         }
 
+        [Test]
+        [Category ("Performance")]
+        public void FetchTrack ()
+        {
+            var track = music_library.TrackModel[0] as DatabaseTrackInfo;
+            int track_id = track.TrackId;
+            var cmd = new HyenaSqliteCommand (select_single_command, track_id);
+            var db = ServiceManager.DbConnection;
+
+            for (int i = 0; i < NUM * 30; i++) {
+                using (IDataReader reader = db.Query (cmd)) {
+                    if (reader.Read ()) {
+                    }
+                }
+            }
+        }
+
+        [Test]
+        [Category ("Too")]
+        public void LoadTrack ()
+        {
+            var track = music_library.TrackModel[0] as DatabaseTrackInfo;
+            var provider = DatabaseTrackInfo.Provider;
+            int track_id = track.TrackId;
+            var cmd = new HyenaSqliteCommand (select_single_command, track_id);
+            var db = ServiceManager.DbConnection;
+            IDataReader reader = db.Query (cmd);
+            Assert.IsTrue (reader.Read ());
+
+            for (int i = 0; i < NUM*1000; i++) {
+                provider.Load (reader, track);
+            }
+
+            reader.Dispose ();
+        }
+
+        private void Select<T> (T val)
+        {
+            T res = default(T);
+            var cmd = new HyenaSqliteCommand ("SELECT ?", val);
+            Log.DebugFormat ("Select<T> cmd is {0}", cmd.Text);
+            var db = ServiceManager.DbConnection;
+
+            for (int i = 0; i < NUM * 250; i++) {
+                res = db.Query<T> (cmd);
+            }
+            Assert.AreEqual (val, res);
+        }
+
+        [Test]
+        [Category ("Performance")]
+        public void SelectStrings ()
+        {
+            Select ("Foo bar");
+        }
+
+        [Test]
+        [Category ("Performance")]
+        public void SelectInt ()
+        {
+            Select ((int)42);
+        }
+
+        [Test]
+        [Category ("Performance")]
+        public void SelectLong ()
+        {
+            Select ((long)42);
+        }
+
+        [Test]
+        [Category ("Performance")]
+        public void SelectDateTime ()
+        {
+            Select (new DateTime (1999, 2, 3));
+        }
+
+        [Test]
+        [Category ("Performance")]
+        public void SelectBool ()
+        {
+            Select (true);
+        }
+
+#endregion
+
 #region Sort tests
 
         private void SortMusicLibrary (QueryField field)
@@ -131,24 +230,28 @@
         }
 
         [Test]
+        [Category ("Performance")]
         public void SortTrack ()
         {
             SortMusicLibrary (BansheeQuery.TrackNumberField);
         }
 
         [Test]
+        [Category ("Performance")]
         public void SortArtist ()
         {
             SortMusicLibrary (BansheeQuery.ArtistField);
         }
 
         [Test]
+        [Category ("Performance")]
         public void SortRating ()
         {
             SortMusicLibrary (BansheeQuery.RatingField);
         }
 
         [Test]
+        [Category ("Performance")]
         public void SortLastPlayed ()
         {
             SortMusicLibrary (BansheeQuery.LastPlayedField);
@@ -170,11 +273,6 @@
                 Environment.GetEnvironmentVariable ("BANSHEE_DEV_OPTIONS") }, 0);
             Log.Debugging = false;
 
-            /*Application.IdleHandler = delegate (IdleHandler handler) { handler (); return 0; };
-            Application.TimeoutHandler = delegate (uint milliseconds, TimeoutHandler handler) {
-                new System.Threading.Timer (delegate { handler (); }, null, milliseconds, Timeout.Infinite);
-                return 0;
-            };*/
             Application.TimeoutHandler = RunTimeout;
             Application.IdleHandler = RunIdle;
             Application.IdleTimeoutRemoveHandler = IdleTimeoutRemove;
@@ -192,16 +290,25 @@
             ThreadAssist.InitializeMainThread ();
             Application.PushClient (client);
             Application.Run ();
+
             music_library = ServiceManager.SourceManager.MusicLibrary;
+
+            var provider = DatabaseTrackInfo.Provider;
+            select_single_command = String.Format (
+                    "SELECT {0} FROM {1} WHERE {2}{3}{4} = ?",
+                    provider.Select, provider.From, provider.Where,
+                    (String.IsNullOrEmpty (provider.Where) ? String.Empty : " AND "),
+                    provider.PrimaryKey
+            );
+
             client.Start ();
         }
 
         [TestFixtureTearDown]
+        [Category ("Performance")]
         public void Teardown ()
         {
-            using (new Hyena.Timer ("Stopping Banshee")) {
-                ThreadAssist.ProxyToMain (Application.Shutdown);
-            }
+            ThreadAssist.ProxyToMain (Application.Shutdown);
             main_thread.Join ();
             main_thread = null;
         }
@@ -223,6 +330,18 @@
 
 #endregion
 
+        public static void Main (string [] args)
+        {
+            var tests = new PerformanceTests ();
+            tests.Setup ();
+
+            using (new Hyena.Timer ("Performance.exe Tests")) {
+                tests.ScrollLinear ();
+            }
+
+            tests.Teardown ();
+        }
+
     }
 
     public class SortableColumn : ISortableColumn



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