1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* test-profile.c Program that does basic message-response for timing; doesn't really use glib bindings
4 * Copyright (C) 2003, 2004 Red Hat Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <dbus/dbus-glib-lowlevel.h>
32 #include <sys/socket.h>
34 #include <netinet/in.h>
38 #ifndef HAVE_SOCKLEN_T
42 #define _DBUS_ZERO(object) (memset (&(object), '\0', sizeof ((object))))
43 #define _DBUS_MAX_SUN_PATH_LENGTH 99
45 /* Note that if you set threads > 1 you get a bogus profile since the
46 * clients start blocking on the server, so the client write() will go
47 * higher in the profile the larger the number of threads.
49 #define N_CLIENT_THREADS 1
50 /* It seems like at least 750000 or so iterations reduces the variability to sane levels */
51 #define N_ITERATIONS 750000
52 #define N_PROGRESS_UPDATES 20
53 /* Don't make PAYLOAD_SIZE too huge because it gets used as a static buffer size */
54 #define PAYLOAD_SIZE 0
56 #define ECHO_SERVICE "org.freedesktop.EchoTestServer"
57 #define ECHO_PATH "/org/freedesktop/EchoTest"
58 #define ECHO_INTERFACE "org.freedesktop.EchoTest"
59 #define ECHO_PING_METHOD "Ping"
61 static const char *messages_address;
62 static const char *plain_sockets_address;
63 static unsigned char *payload;
64 static int echo_call_size;
65 static int echo_return_size;
67 typedef struct ProfileRunVTable ProfileRunVTable;
71 const ProfileRunVTable *vtable;
78 const ProfileRunVTable *vtable;
84 struct ProfileRunVTable
87 gboolean fake_malloc_overhead;
88 void* (* init_server) (ServerData *sd);
89 void (* stop_server) (ServerData *sd,
91 void* (* client_thread_func) (void *data); /* Data has to be the vtable */
93 /* this is so different runs show up in the profiler with
96 void (* main_loop_run_func) (GMainLoop *loop);
99 /* Note, this is all crack-a-rific; it isn't using DBusGProxy and thus is
103 send_echo_method_call (DBusConnection *connection)
105 DBusMessage *message;
106 const char *hello = "Hello World!";
107 dbus_int32_t i32 = 123456;
109 message = dbus_message_new_method_call (ECHO_SERVICE,
113 dbus_message_append_args (message,
114 DBUS_TYPE_STRING, &hello,
115 DBUS_TYPE_INT32, &i32,
117 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
118 &payload, PAYLOAD_SIZE,
122 dbus_connection_send (connection, message, NULL);
123 dbus_message_unref (message);
124 dbus_connection_flush (connection);
128 send_echo_method_return (DBusConnection *connection,
129 DBusMessage *call_message)
131 DBusMessage *message;
133 message = dbus_message_new_method_return (call_message);
135 dbus_connection_send (connection, message, NULL);
136 dbus_message_unref (message);
137 dbus_connection_flush (connection);
140 static DBusHandlerResult
141 with_or_without_bus_client_filter (DBusConnection *connection,
142 DBusMessage *message,
145 if (dbus_message_is_signal (message,
146 DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
149 g_printerr ("Client thread disconnected\n");
152 else if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
155 if (cd->iterations >= N_ITERATIONS)
157 g_printerr ("\nCompleted %d iterations\n", N_ITERATIONS);
158 g_main_loop_quit (cd->loop);
160 else if (cd->iterations % (N_ITERATIONS/N_PROGRESS_UPDATES) == 0)
162 g_printerr ("%d%% ", (int) (cd->iterations/(double)N_ITERATIONS * 100.0));
165 send_echo_method_call (connection);
166 return DBUS_HANDLER_RESULT_HANDLED;
169 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
172 static DBusHandlerResult
173 no_bus_client_filter (DBusConnection *connection,
174 DBusMessage *message,
177 ClientData *cd = user_data;
179 return with_or_without_bus_client_filter (connection, message, cd);
183 no_bus_thread_func (void *data)
186 GMainContext *context;
187 DBusConnection *connection;
190 g_printerr ("Starting client thread %p\n", g_thread_self());
192 dbus_error_init (&error);
193 connection = dbus_connection_open (messages_address, &error);
194 if (connection == NULL)
196 g_printerr ("could not open connection: %s\n", error.message);
197 dbus_error_free (&error);
201 context = g_main_context_new ();
204 cd.loop = g_main_loop_new (context, FALSE);
206 if (!dbus_connection_add_filter (connection,
207 no_bus_client_filter, &cd, NULL))
208 g_error ("no memory");
211 dbus_connection_setup_with_g_main (connection, context);
213 g_printerr ("Client thread sending message to prime pingpong\n");
214 send_echo_method_call (connection);
215 g_printerr ("Client thread sent message\n");
217 g_printerr ("Client thread entering main loop\n");
218 g_main_loop_run (cd.loop);
219 g_printerr ("Client thread %p exiting main loop\n",
222 dbus_connection_disconnect (connection);
224 g_main_loop_unref (cd.loop);
225 g_main_context_unref (context);
230 static DBusHandlerResult
231 no_bus_server_filter (DBusConnection *connection,
232 DBusMessage *message,
235 ServerData *sd = user_data;
237 if (dbus_message_is_signal (message,
238 DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
241 g_printerr ("Client disconnected from server\n");
243 if (sd->n_clients == 0)
244 g_main_loop_quit (sd->loop);
246 else if (dbus_message_is_method_call (message,
251 send_echo_method_return (connection, message);
252 return DBUS_HANDLER_RESULT_HANDLED;
255 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
259 no_bus_new_connection_callback (DBusServer *server,
260 DBusConnection *new_connection,
263 ServerData *sd = user_data;
265 dbus_connection_ref (new_connection);
266 dbus_connection_setup_with_g_main (new_connection, NULL);
268 if (!dbus_connection_add_filter (new_connection,
269 no_bus_server_filter, sd, NULL))
270 g_error ("no memory");
274 /* FIXME we leak the handler */
278 no_bus_init_server (ServerData *sd)
283 dbus_error_init (&error);
284 server = dbus_server_listen ("unix:tmpdir="DBUS_TEST_SOCKET_DIR,
288 g_printerr ("Could not start server: %s\n",
293 messages_address = dbus_server_get_address (server);
295 dbus_server_set_new_connection_function (server,
296 no_bus_new_connection_callback,
299 dbus_server_setup_with_g_main (server, NULL);
305 no_bus_stop_server (ServerData *sd,
308 g_printerr ("The following g_warning is because we try to call g_source_remove_poll() after g_source_destroy() in dbus-gmain.c, I think we need to add a source free func that clears out the watch/timeout funcs\n");
310 dbus_server_unref (server);
314 no_bus_main_loop_run (GMainLoop *loop)
316 g_main_loop_run (loop);
319 static const ProfileRunVTable no_bus_vtable = {
320 "dbus direct without bus",
330 const ProfileRunVTable *vtable;
332 GHashTable *client_names;
333 DBusConnection *connection;
336 static DBusHandlerResult
337 with_bus_client_filter (DBusConnection *connection,
338 DBusMessage *message,
341 ClientData *cd = user_data;
343 return with_or_without_bus_client_filter (connection, message, cd);
347 with_bus_thread_func (void *data)
350 DBusConnection *connection;
353 GMainContext *context;
355 g_printerr ("Starting client thread %p\n", g_thread_self());
357 address = g_getenv ("DBUS_SESSION_BUS_ADDRESS");
360 g_printerr ("DBUS_SESSION_BUS_ADDRESS not set\n");
364 dbus_error_init (&error);
365 connection = dbus_connection_open (address, &error);
366 if (connection == NULL)
368 g_printerr ("could not open connection to bus: %s\n", error.message);
369 dbus_error_free (&error);
373 if (!dbus_bus_register (connection, &error))
375 g_printerr ("could not register with bus: %s\n", error.message);
376 dbus_error_free (&error);
380 context = g_main_context_new ();
383 cd.loop = g_main_loop_new (context, FALSE);
385 if (!dbus_connection_add_filter (connection,
386 with_bus_client_filter, &cd, NULL))
387 g_error ("no memory");
389 dbus_connection_setup_with_g_main (connection, context);
391 g_printerr ("Client thread sending message to prime pingpong\n");
392 send_echo_method_call (connection);
393 g_printerr ("Client thread sent message\n");
395 g_printerr ("Client thread entering main loop\n");
396 g_main_loop_run (cd.loop);
397 g_printerr ("Client thread %p exiting main loop\n",
400 dbus_connection_disconnect (connection);
402 g_main_loop_unref (cd.loop);
403 g_main_context_unref (context);
408 static DBusHandlerResult
409 with_bus_server_filter (DBusConnection *connection,
410 DBusMessage *message,
413 WithBusServer *server = user_data;
415 if (dbus_message_is_signal (message,
416 DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
419 g_printerr ("Server disconnected from message bus\n");
422 else if (dbus_message_has_sender (message,
423 DBUS_SERVICE_ORG_FREEDESKTOP_DBUS) &&
424 dbus_message_is_signal (message,
425 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
426 "ServiceOwnerChanged"))
428 const char *service_name, *old_owner, *new_owner;
435 dbus_error_init (&error);
436 if (!dbus_message_get_args (message,
438 DBUS_TYPE_STRING, &service_name,
439 DBUS_TYPE_STRING, &old_owner,
440 DBUS_TYPE_STRING, &new_owner,
443 g_printerr ("dbus_message_get_args(): %s\n", error.message);
447 if (g_hash_table_lookup (server->client_names,
449 *old_owner != '\0' &&
452 g_hash_table_remove (server->client_names,
454 server->sd->n_clients -= 1;
455 if (server->sd->n_clients == 0)
456 g_main_loop_quit (server->sd->loop);
459 else if (dbus_message_is_method_call (message,
465 sender = dbus_message_get_sender (message);
467 if (!g_hash_table_lookup (server->client_names,
470 g_printerr ("First message from new client %s on bus\n", sender);
472 g_hash_table_replace (server->client_names,
474 GINT_TO_POINTER (1));
475 server->sd->n_clients += 1;
478 server->sd->handled += 1;
479 send_echo_method_return (connection, message);
480 return DBUS_HANDLER_RESULT_HANDLED;
483 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
487 with_bus_init_server (ServerData *sd)
489 DBusGConnection *gconnection;
490 DBusConnection *connection;
493 WithBusServer *server;
496 server = g_new0 (WithBusServer, 1);
498 server->vtable = sd->vtable;
501 s = g_getenv ("DBUS_TEST_GLIB_RUN_TEST_SCRIPT");
505 g_printerr ("You have to run with_bus mode with the run-test.sh script\n");
509 /* Note that we use the standard global bus connection for the
510 * server, and the clients open their own connections so they can
511 * have their own main loops and because I'm not sure "talking to
512 * yourself" really works yet
515 gconnection = dbus_g_bus_get (DBUS_BUS_SESSION, &gerror);
516 if (gconnection == NULL)
518 g_printerr ("could not open connection to bus: %s\n", gerror->message);
519 g_error_free (gerror);
523 server->client_names = g_hash_table_new_full (g_str_hash, g_str_equal,
526 connection = dbus_g_connection_get_connection (gconnection);
528 dbus_bus_acquire_service (connection,
530 0, NULL); /* ignore errors because we suck */
532 rule = g_strdup_printf ("type='signal',sender='%s',member='%s'",
533 DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
534 "ServiceOwnerChanged");
536 /* ignore errors because we suck */
537 dbus_bus_add_match (connection, rule, NULL);
541 if (!dbus_connection_add_filter (connection,
542 with_bus_server_filter, server, NULL))
543 g_error ("no memory");
545 server->connection = connection;
546 server->client_names = g_hash_table_new_full (g_str_hash, g_str_equal,
553 with_bus_stop_server (ServerData *sd,
556 WithBusServer *server = serverv;
558 dbus_connection_remove_filter (server->connection,
559 with_bus_server_filter, server);
561 g_hash_table_destroy (server->client_names);
562 dbus_connection_unref (server->connection);
568 with_bus_main_loop_run (GMainLoop *loop)
570 g_main_loop_run (loop);
573 static const ProfileRunVTable with_bus_vtable = {
576 with_bus_init_server,
577 with_bus_stop_server,
578 with_bus_thread_func,
579 with_bus_main_loop_run
585 const ProfileRunVTable *vtable;
588 unsigned int source_id;
592 read_and_drop_on_floor (int fd,
594 gboolean fake_malloc_overhead)
600 char not_allocated[512+PAYLOAD_SIZE];
602 g_assert (count < (int) sizeof(not_allocated));
604 if (fake_malloc_overhead)
606 allocated = g_malloc (count);
617 while (bytes_read < count)
621 val = read (fd, buf + bytes_read, count - bytes_read);
629 g_printerr ("read() failed thread %p: %s\n",
630 g_thread_self(), strerror (errno));
640 if (fake_malloc_overhead)
644 g_printerr ("%p read %d bytes from fd %d\n",
645 g_thread_self(), bytes_read, fd);
652 gboolean fake_malloc_overhead)
658 char not_allocated[512+PAYLOAD_SIZE];
660 g_assert (count < (int) sizeof(not_allocated));
662 if (fake_malloc_overhead)
666 allocated = g_malloc (count);
669 /* Write some stuff into the allocated buffer to simulate
670 * creating some sort of data
675 allocated[i] = (char) i;
687 while (bytes_written < count)
691 val = write (fd, buf + bytes_written, count - bytes_written);
699 g_printerr ("write() failed thread %p: %s\n",
700 g_thread_self(), strerror (errno));
706 bytes_written += val;
710 if (fake_malloc_overhead)
714 g_printerr ("%p wrote %d bytes to fd %d\n",
715 g_thread_self(), bytes_written, fd);
720 plain_sockets_talk_to_client_watch (GIOChannel *source,
721 GIOCondition condition,
724 PlainSocketServer *server = data;
725 int client_fd = g_io_channel_unix_get_fd (source);
727 if (condition & G_IO_HUP)
729 g_printerr ("Client disconnected from server\n");
730 server->sd->n_clients -= 1;
731 if (server->sd->n_clients == 0)
732 g_main_loop_quit (server->sd->loop);
734 return FALSE; /* remove watch */
736 else if (condition & G_IO_IN)
738 server->sd->handled += 1;
740 read_and_drop_on_floor (client_fd, echo_call_size, server->vtable->fake_malloc_overhead);
741 write_junk (client_fd, echo_return_size, server->vtable->fake_malloc_overhead);
745 g_printerr ("Unexpected IO condition in server thread\n");
753 plain_sockets_new_client_watch (GIOChannel *source,
754 GIOCondition condition,
758 struct sockaddr addr;
761 PlainSocketServer *server = data;
763 if (!(condition & G_IO_IN))
765 g_printerr ("Unexpected IO condition on server socket\n");
769 addrlen = sizeof (addr);
772 client_fd = accept (server->listen_fd, &addr, &addrlen);
780 g_printerr ("Failed to accept() connection from client: %s\n",
786 channel = g_io_channel_unix_new (client_fd);
787 g_io_add_watch (channel,
788 G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL | G_IO_PRI,
789 plain_sockets_talk_to_client_watch,
791 g_io_channel_unref (channel);
793 server->sd->n_clients += 1;
799 plain_sockets_init_server (ServerData *sd)
801 PlainSocketServer *server;
802 struct sockaddr_un addr;
803 static char path[] = "/tmp/dbus-test-profile-XXXXXX";
807 server = g_new0 (PlainSocketServer, 1);
809 server->vtable = sd->vtable; /* for convenience */
815 *p = 'a' + (int) (26.0*rand()/(RAND_MAX+1.0));
819 g_printerr ("Socket is %s\n", path);
821 server->listen_fd = socket (PF_UNIX, SOCK_STREAM, 0);
823 if (server->listen_fd < 0)
825 g_printerr ("Failed to create socket: %s",
831 addr.sun_family = AF_UNIX;
833 #ifdef HAVE_ABSTRACT_SOCKETS
834 /* remember that abstract names aren't nul-terminated so we rely
835 * on sun_path being filled in with zeroes above.
837 addr.sun_path[0] = '\0'; /* this is what says "use abstract" */
838 strncpy (&addr.sun_path[1], path, _DBUS_MAX_SUN_PATH_LENGTH - 2);
839 /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */
840 #else /* HAVE_ABSTRACT_SOCKETS */
844 if (stat (path, &sb) == 0 &&
845 S_ISSOCK (sb.st_mode))
849 strncpy (addr.sun_path, path, _DBUS_MAX_SUN_PATH_LENGTH - 1);
850 #endif /* ! HAVE_ABSTRACT_SOCKETS */
852 if (bind (server->listen_fd, (struct sockaddr*) &addr, sizeof (addr)) < 0)
854 g_printerr ("Failed to bind socket \"%s\": %s",
855 path, strerror (errno));
859 if (listen (server->listen_fd, 30 /* backlog */) < 0)
861 g_printerr ("Failed to listen on socket \"%s\": %s",
862 path, strerror (errno));
866 plain_sockets_address = path;
868 channel = g_io_channel_unix_new (server->listen_fd);
870 g_io_add_watch (channel,
871 G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL | G_IO_PRI,
872 plain_sockets_new_client_watch,
874 g_io_channel_unref (channel);
880 plain_sockets_stop_server (ServerData *sd,
883 PlainSocketServer *server = server_v;
885 g_source_remove (server->source_id);
887 close (server->listen_fd);
893 if (stat (plain_sockets_address, &sb) == 0 &&
894 S_ISSOCK (sb.st_mode))
895 unlink (plain_sockets_address);
900 plain_sockets_client_side_watch (GIOChannel *source,
901 GIOCondition condition,
904 ClientData *cd = data;
905 int fd = g_io_channel_unix_get_fd (source);
907 if (condition & G_IO_IN)
909 read_and_drop_on_floor (fd, echo_return_size, cd->vtable->fake_malloc_overhead);
911 else if (condition & G_IO_OUT)
914 if (cd->iterations >= N_ITERATIONS)
916 g_printerr ("\nCompleted %d iterations\n", N_ITERATIONS);
917 g_main_loop_quit (cd->loop);
919 else if (cd->iterations % (N_ITERATIONS/N_PROGRESS_UPDATES) == 0)
921 g_printerr ("%d%% ", (int) (cd->iterations/(double)N_ITERATIONS * 100.0));
924 write_junk (fd, echo_call_size, cd->vtable->fake_malloc_overhead);
928 g_printerr ("Unexpected IO condition in client thread\n");
936 plain_sockets_thread_func (void *data)
938 GMainContext *context;
941 struct sockaddr_un addr;
945 g_printerr ("Starting client thread %p\n",
948 fd = socket (PF_UNIX, SOCK_STREAM, 0);
952 g_printerr ("Failed to create socket: %s",
958 addr.sun_family = AF_UNIX;
960 #ifdef HAVE_ABSTRACT_SOCKETS
961 /* remember that abstract names aren't nul-terminated so we rely
962 * on sun_path being filled in with zeroes above.
964 addr.sun_path[0] = '\0'; /* this is what says "use abstract" */
965 strncpy (&addr.sun_path[1], plain_sockets_address, _DBUS_MAX_SUN_PATH_LENGTH - 2);
966 /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */
967 #else /* HAVE_ABSTRACT_SOCKETS */
968 strncpy (addr.sun_path, plain_sockets_address, _DBUS_MAX_SUN_PATH_LENGTH - 1);
969 #endif /* ! HAVE_ABSTRACT_SOCKETS */
971 if (connect (fd, (struct sockaddr*) &addr, sizeof (addr)) < 0)
973 g_printerr ("Failed to connect to socket %s: %s",
974 plain_sockets_address, strerror (errno));
978 context = g_main_context_new ();
981 cd.loop = g_main_loop_new (context, FALSE);
983 channel = g_io_channel_unix_new (fd);
985 gsource = g_io_create_watch (channel,
987 G_IO_ERR | G_IO_HUP | G_IO_NVAL | G_IO_PRI);
989 g_source_set_callback (gsource,
990 (GSourceFunc)plain_sockets_client_side_watch,
993 g_source_attach (gsource, context);
995 g_io_channel_unref (channel);
997 g_printerr ("Client thread writing to prime pingpong\n");
998 write_junk (fd, echo_call_size, cd.vtable->fake_malloc_overhead);
999 g_printerr ("Client thread done writing primer\n");
1001 g_printerr ("Client thread entering main loop\n");
1002 g_main_loop_run (cd.loop);
1003 g_printerr ("Client thread %p exiting main loop\n",
1006 g_source_destroy (gsource);
1010 g_main_loop_unref (cd.loop);
1011 g_main_context_unref (context);
1017 plain_sockets_main_loop_run (GMainLoop *loop)
1019 g_main_loop_run (loop);
1022 static const ProfileRunVTable plain_sockets_vtable = {
1025 plain_sockets_init_server,
1026 plain_sockets_stop_server,
1027 plain_sockets_thread_func,
1028 plain_sockets_main_loop_run
1031 static const ProfileRunVTable plain_sockets_with_malloc_vtable = {
1032 "plain sockets with malloc overhead",
1034 plain_sockets_init_server,
1035 plain_sockets_stop_server,
1036 plain_sockets_thread_func,
1037 plain_sockets_main_loop_run
1041 do_profile_run (const ProfileRunVTable *vtable)
1049 g_printerr ("Profiling %s\n", vtable->name);
1053 sd.loop = g_main_loop_new (NULL, FALSE);
1056 server = (* vtable->init_server) (&sd);
1058 for (i = 0; i < N_CLIENT_THREADS; i++)
1060 g_thread_create (vtable->client_thread_func, (void*) vtable, FALSE, NULL);
1063 timer = g_timer_new ();
1065 g_printerr ("Server thread %p entering main loop\n",
1067 (* vtable->main_loop_run_func) (sd.loop);
1068 g_printerr ("Server thread %p exiting main loop\n",
1071 secs = g_timer_elapsed (timer, NULL);
1072 g_timer_destroy (timer);
1074 g_printerr ("%s: %g seconds, %d round trips, %f seconds per pingpong\n",
1075 vtable->name, secs, sd.handled, secs/sd.handled);
1077 (* vtable->stop_server) (&sd, server);
1079 g_main_loop_unref (sd.loop);
1085 print_result (const ProfileRunVTable *vtable,
1089 g_printerr (" %g times slower for %s (%g seconds, %f per iteration)\n",
1090 seconds/baseline, vtable->name,
1091 seconds, seconds / N_ITERATIONS);
1095 main (int argc, char *argv[])
1097 g_thread_init (NULL);
1098 dbus_g_thread_init ();
1100 #ifndef DBUS_DISABLE_ASSERT
1101 g_printerr ("You should probably --disable-asserts before you profile as they have noticeable overhead\n");
1104 #if DBUS_ENABLE_VERBOSE_MODE
1105 g_printerr ("You should probably --disable-verbose-mode before you profile as verbose has noticeable overhead\n");
1108 payload = g_malloc (PAYLOAD_SIZE);
1110 /* The actual size of the DBusMessage on the wire, as of Nov 23 2004,
1111 * without the payload
1113 echo_call_size = 140 + PAYLOAD_SIZE;
1114 echo_return_size = 32;
1116 if (argc > 1 && strcmp (argv[1], "plain_sockets") == 0)
1117 do_profile_run (&plain_sockets_vtable);
1118 else if (argc > 1 && strcmp (argv[1], "plain_sockets_with_malloc") == 0)
1119 do_profile_run (&plain_sockets_with_malloc_vtable);
1120 else if (argc > 1 && strcmp (argv[1], "no_bus") == 0)
1121 do_profile_run (&no_bus_vtable);
1122 else if (argc > 1 && strcmp (argv[1], "with_bus") == 0)
1123 do_profile_run (&with_bus_vtable);
1124 else if (argc > 1 && strcmp (argv[1], "all") == 0)
1126 double e1, e2, e3, e4;
1128 e1 = do_profile_run (&plain_sockets_vtable);
1129 e2 = do_profile_run (&plain_sockets_with_malloc_vtable);
1130 e3 = do_profile_run (&no_bus_vtable);
1131 e4 = do_profile_run (&with_bus_vtable);
1133 g_printerr ("Baseline plain sockets time %g seconds for %d iterations\n",
1135 print_result (&plain_sockets_vtable, e1, e1);
1136 print_result (&plain_sockets_with_malloc_vtable, e2, e1);
1137 print_result (&no_bus_vtable, e3, e1);
1138 print_result (&with_bus_vtable, e4, e1);
1142 g_printerr ("Specify profile type plain_sockets, plain_sockets_with_malloc, no_bus, with_bus, all\n");
1146 /* Make valgrind happy */