hythmbox-2.98/tests/bench-rhythmdb-load.c

No issues found

  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  Copyright (C) 2007 James Livingston
  4  *
  5  *  This program is free software; you can redistribute it and/or modify
  6  *  it under the terms of the GNU General Public License as published by
  7  *  the Free Software Foundation; either version 2, or (at your option)
  8  *  any later version.
  9  *
 10  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 11  *  GStreamer plugins to be used and distributed together with GStreamer
 12  *  and Rhythmbox. This permission is above and beyond the permissions granted
 13  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 14  *  you may extend this exception to your version of the code, but you are not
 15  *  obligated to do so. If you do not wish to do so, delete this exception
 16  *  statement from your version.
 17  *
 18  *  This program is distributed in the hope that it will be useful,
 19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 21  *  GNU General Public License for more details.
 22  *
 23  *  You should have received a copy of the GNU General Public License
 24  *  along with this program; if not, write to the Free Software
 25  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 26  *
 27  */
 28 
 29 
 30 #include "config.h"
 31 
 32 #include <gtk/gtk.h>
 33 #include <string.h>
 34 #include <locale.h>
 35 
 36 #include "rb-debug.h"
 37 #include "rb-file-helpers.h"
 38 #include "rb-util.h"
 39 
 40 #include "rhythmdb.h"
 41 #include "rhythmdb-tree.h"
 42 #include "rb-podcast-entry-types.h"
 43 
 44 /* test utils */
 45 gboolean waiting, signaled;
 46 char *sig_name;
 47 
 48 
 49 static void
 50 mark_signal (void)
 51 {
 52 	if (signaled) {
 53 		rb_debug ("got signal '%s' multiple times", sig_name);
 54 	} else {
 55 		rb_debug ("got signal '%s'", sig_name);
 56 		signaled = TRUE;
 57 		if (waiting)
 58 			gtk_main_quit ();
 59 	}
 60 }
 61 
 62 static void
 63 set_waiting_signal (GObject *o, const char *name)
 64 {
 65 	signaled = FALSE;
 66 	waiting = FALSE;
 67 	sig_name = g_strdup (name);
 68 	g_signal_connect (o, sig_name, G_CALLBACK (mark_signal), NULL);
 69 }
 70 
 71 static void wait_for_signal (void)
 72 {
 73 	if (!signaled) {
 74 		rb_debug ("waiting for signal '%s'", sig_name);
 75 		waiting = TRUE;
 76 		gtk_main ();
 77 	} else {
 78 		rb_debug ("no need to wait for signal '%s', already received", sig_name);
 79 	}
 80 
 81 	g_free (sig_name);
 82 	sig_name = NULL;
 83 }
 84 
 85 
 86 int 
 87 main (int argc, char **argv)
 88 {
 89 	RhythmDB *db;
 90 	char *name;
 91 	int i;
 92 
 93 	if (argc < 2) {
 94 		name = g_build_filename (rb_user_data_dir(), "rhythmdb.xml", NULL);
 95 		g_print ("using %s\n", name);
 96 	} else {
 97 		name = g_strdup (argv[1]);
 98 	}
 99 
100 	rb_profile_start ("load test");
101 
102 	rb_threads_init ();
103 	setlocale (LC_ALL, NULL);
104 	gtk_init (&argc, &argv);
105 	rb_debug_init (FALSE);
106 	rb_refstring_system_init ();
107 	rb_file_helpers_init (TRUE);
108 
109 	GDK_THREADS_ENTER ();
110 
111 	db = rhythmdb_tree_new ("test");
112 	g_object_set (G_OBJECT (db), "name", name, NULL);
113 	g_free (name);
114 
115 	for (i = 1; i <= 10; i++) {
116 		int j;
117 		rb_profile_start ("10 rhythmdb loads");
118 		for (j = 1; j <= 10; j++) {
119 			set_waiting_signal (G_OBJECT (db), "load-complete");
120 			rhythmdb_load (db);
121 			wait_for_signal ();
122 
123 			rhythmdb_entry_delete_by_type (db, RHYTHMDB_ENTRY_TYPE_SONG);
124 			rhythmdb_entry_delete_by_type (db, rhythmdb_entry_type_get_by_name (db, "iradio"));
125 			rhythmdb_entry_delete_by_type (db, RHYTHMDB_ENTRY_TYPE_PODCAST_FEED);
126 			rhythmdb_entry_delete_by_type (db, RHYTHMDB_ENTRY_TYPE_PODCAST_POST);
127 		}
128 		rb_profile_end ("10 rhythmdb loads");
129 		g_print ("completed %d loads\n", i * 10);
130 	}
131 
132 	rhythmdb_shutdown (db);
133 	g_object_unref (G_OBJECT (db));
134 	db = NULL;
135 
136 	
137 	rb_file_helpers_shutdown ();
138         rb_refstring_system_shutdown ();
139 
140 
141 	rb_profile_end ("load test");
142 	return 0;
143 }