[Telepathy-commits] [telepathy-mission-control/master] Update to new timestamps version

Alberto Mardegan alberto.mardegan at nokia.com
Mon Jan 12 04:02:25 PST 2009


---
 src/Makefile.am      |    2 +-
 src/mcd-connection.c |    4 +-
 src/mcd-dispatcher.c |   10 ++--
 src/sp_timestamp.h   |  110 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/timestamps.h     |   69 -------------------------------
 5 files changed, 118 insertions(+), 77 deletions(-)
 create mode 100644 src/sp_timestamp.h
 delete mode 100644 src/timestamps.h

diff --git a/src/Makefile.am b/src/Makefile.am
index e6aa50d..dcb50dc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -86,7 +86,7 @@ mission_control_include_HEADERS = \
 	mcd-account-priv.h \
 	mcd-enum-types.h \
 	mcd-misc.h \
-	timestamps.h
+	sp_timestamp.h
 
 BUILT_SOURCES = \
 	_gen/all.xml \
diff --git a/src/mcd-connection.c b/src/mcd-connection.c
index 0d02a85..7899270 100644
--- a/src/mcd-connection.c
+++ b/src/mcd-connection.c
@@ -57,7 +57,7 @@
 #include "mcd-channel.h"
 #include "mcd-provisioning-factory.h"
 #include "mcd-misc.h"
-#include "timestamps.h"
+#include "sp_timestamp.h"
 
 #include "_gen/interfaces.h"
 #include "_gen/gtypes.h"
@@ -1225,7 +1225,7 @@ on_new_channels (TpConnection *proxy, const GPtrArray *channels,
                                                                channels))
         return;
 
-    timestamp ("NewChannels received");
+    sp_timestamp ("NewChannels received");
     for (i = 0; i < channels->len; i++)
     {
         GValueArray *va;
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index e5c582b..f377671 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -60,7 +60,7 @@
 #include <libmcclient/mc-errors.h>
 
 #include <string.h>
-#include "timestamps.h"
+#include "sp_timestamp.h"
 
 #define MCD_DISPATCHER_PRIV(dispatcher) (MCD_DISPATCHER (dispatcher)->priv)
 
@@ -1280,7 +1280,7 @@ mcd_dispatcher_run_handlers (McdDispatcherContext *context)
     GList *channels;
     GList *unhandled = NULL;
 
-    timestamp ("run handlers");
+    sp_timestamp ("run handlers");
     mcd_dispatcher_context_ref (context);
 
     /* call mcd_dispatcher_run_handler until there are no unhandled channels */
@@ -1340,7 +1340,7 @@ mcd_dispatcher_run_observers (McdDispatcherContext *context)
     GHashTableIter iter;
     McdClient *client;
 
-    timestamp ("run observers");
+    sp_timestamp ("run observers");
     channels = context->channels;
     observer_info = NULL;
 
@@ -1438,7 +1438,7 @@ mcd_dispatcher_run_approvers (McdDispatcherContext *context)
     McdClient *client;
 
     g_return_if_fail (context->operation != NULL);
-    timestamp ("run approvers");
+    sp_timestamp ("run approvers");
 
     /* we temporarily increment this count and decrement it at the end of the
      * function, to make sure it won't become 0 while we are still invoking
@@ -1687,7 +1687,7 @@ _mcd_dispatcher_enter_state_machine (McdDispatcher *dispatcher,
     {
         g_debug ("entering state machine for context %p", context);
 
-        timestamp ("invoke internal filters");
+        sp_timestamp ("invoke internal filters");
 	priv->state_machine_list =
 	    g_slist_prepend (priv->state_machine_list, context);
 	mcd_dispatcher_context_process (context, TRUE);
diff --git a/src/sp_timestamp.h b/src/sp_timestamp.h
new file mode 100644
index 0000000..7406ccc
--- /dev/null
+++ b/src/sp_timestamp.h
@@ -0,0 +1,110 @@
+/*
+ * Macro / inline function to add/mark "timestamps" to program in a
+ * way that can be found from LTT traces.  This helps in pinpointing
+ * when something interesting starts or ends in the trace. Strace can
+ * be used to get timings for these measurement points.
+ * 
+ * Copyright (C) 2008 by Nokia Corporation
+ *
+ * Contact: Eero Tamminen <eero.tamminen at nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * version 2 as published by the Free Software Foundation. 
+ *
+ * This program 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.
+ * 
+ * usage:
+ *	#include "sp_timestamp.h"
+ * ...
+ *	sp_timestamp("something-interesting-started");
+ * 
+ * To enable timestamping when building the code in Scratchbox,
+ * do this before build:
+ *	export SBOX_EXTRA_COMPILER_ARGS="-DSP_TIMESTAMP_CREATE=1"
+ * 
+ * You can see the timestamps when running the software with:
+ *	strace -f -tt -e trace=open,execve ./binary 2>&1 | grep /tmp/stamps
+ * 
+ * If the programs are already running, give the program IDs which
+ * strace should attach to with the "-p PID" argument instead of
+ * a program name.
+ * 
+ * 
+ * Implementation differences to Federico's Gnome app stracing tool:
+ *     http://www.gnome.org/~federico/news-2006-03.html#timeline-tools
+ * - Lower level C-library functions are used instead of Glib
+ * - Gets process name from /proc/PID/cmdline instead of Gtk
+ *   specific functions (macro version uses just __FILE__)
+ * - Uses open() syscall instead of access() because LTT doesn't
+ *   record filename used by access() and because programs do
+ *   use open() less (ptrace has its own overhead)
+ * - Files are in /tmp which on Maemo is tmpfs (in RAM)
+ */
+#ifndef SP_TIMESTAMP_H
+#define SP_TIMESTAMP_H
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#ifndef SP_TIMESTAMP_CREATE
+# define sp_timestamp(step)
+#else
+
+# ifdef SP_TIMESTAMP_MACRO
+/* low overhead macro adding code filename to measurement filename */
+#  define sp_timestamp(step) { int _tmp_fd; \
+	_tmp_fd = open("/tmp/stamps/" __FILE__ ":" step, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); \
+	if (_tmp_fd >=0) close(_tmp_fd); }
+
+# else
+
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+/* higher overhead Linux specific function that adds program name
+ */
+static inline void sp_timestamp(const char *step)
+{
+#define SP_TIMESTAMP_PATH "/tmp/stamps/"
+	int fd, count, offset;
+	char filename[256], *cmdname;
+
+	/* get process command name */
+	snprintf(filename, sizeof(filename), "/proc/%d/cmdline", getpid());
+	fd = open(filename, O_RDONLY);
+	assert(fd >= 0);
+
+	strcpy(filename, SP_TIMESTAMP_PATH);
+	offset = sizeof(SP_TIMESTAMP_PATH)-1;
+	count = read(fd, filename+offset, sizeof(filename)-offset);
+	assert(count > 0);
+	close(fd);
+
+	/* take basename of the command name */
+	cmdname = strrchr(filename+offset, '/');
+	memmove(filename+offset, cmdname+1, strlen(cmdname));
+	offset += strlen(filename+offset);
+	
+	/* add step name */
+	assert(sizeof(filename) > offset + 1 + strlen(step) + 1);
+	filename[offset++] = ':';
+	filename[offset] = '\0';
+	strcat(filename+offset, step);
+	
+	fd = open(filename, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
+	if (fd >= 0) {
+		close(fd);
+	}
+#undef SP_TIMESTAMP_PATH
+}
+# endif
+
+#endif
+
+#endif /* SP_TIMESTAMP_H */
diff --git a/src/timestamps.h b/src/timestamps.h
deleted file mode 100644
index 9bbe4cf..0000000
--- a/src/timestamps.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/* vi: set et sw=4 ts=4 cino=t0,(0: */
-/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of mission-control
- *
- * Copyright (C) 2008 Nokia Corporation. 
- *
- * Contact: Alberto Mardegan  <alberto.mardegan at nokia.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * version 2.1 as published by the Free Software Foundation.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-/*
- * Macro to add/mark "timestamps" to program in a way that can be found
- * from LTT traces.  This helps in pinpointing when something interesting
- * starts or ends in the trace.
- * 
- * Use like this:
- *	#include "timestamps.h"
- * ...
- *	timestamp("something-interesting-start");
- * 
- * To enable timestamping when building the code in Scratchbox,
- * do this before build:
- *	export SBOX_EXTRA_COMPILER_ARGS="-DCREATE_TIMESTAMPS=1"
- * 
- * If you don't have LTT, you can see the timestamps when running
- * the software with:
- *	strace -f -tt -e open ./binary 2>&1 | grep /tmp/stamps|cut -d, -f1
- * ir if program is already running, give "-p PID" for strace
- * to attach to it instead.
- * 
- * Although less useful due to bad granularity, if you (re-)create
- * /tmp/stamps directory before the test:
- * 	rm -r /tmp/tests/
- * 	mkdir -p /tmp/tests
- * you can afterwards see the timestamps with 1 sec granularity
- * (and see their order):
- *	ls -clrt /tmp/stamps/|awk '{print $8, $9}'
- */
-#ifndef TIMESTAMPS_H
-#define TIMESTAMPS_H
-
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#ifdef CREATE_TIMESTAMPS
-# define timestamp(step) { int _tmp_fd; \
-	_tmp_fd = open("/tmp/stamps/" __FILE__ ":" step, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); \
-	if (_tmp_fd >=0) close(_tmp_fd); }
-#else
-# define timestamp(step)
-#endif
-
-#endif /* TIMESTAMPS_H */
-- 
1.5.6.5




More information about the Telepathy-commits mailing list