bprof r13 - in trunk: . mempattern
- From: stefkost svn gnome org
- To: svn-commits-list gnome org
- Subject: bprof r13 - in trunk: . mempattern
- Date: Wed, 10 Sep 2008 12:04:15 +0000 (UTC)
Author: stefkost
Date: Wed Sep 10 12:04:15 2008
New Revision: 13
URL: http://svn.gnome.org/viewvc/bprof?rev=13&view=rev
Log:
* Makefile.am:
Dist the README.
* mempattern/mp.c:
Use tempdir() for the logs by default. Allow to have the logs anywhere
else too.
Modified:
trunk/ChangeLog
trunk/Makefile.am
trunk/mempattern/mp.c
Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am (original)
+++ trunk/Makefile.am Wed Sep 10 12:04:15 2008
@@ -1,2 +1,4 @@
SUBDIRS = mempattern
+EXTRA_DIST = README
+
Modified: trunk/mempattern/mp.c
==============================================================================
--- trunk/mempattern/mp.c (original)
+++ trunk/mempattern/mp.c Wed Sep 10 12:04:15 2008
@@ -33,6 +33,7 @@
#include <malloc.h>
#include <signal.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -41,16 +42,12 @@
#include <glib.h>
-/* FIXME: what about one env-var for the log-basename
- * MP_LOG_BASE=/tmp/mp_"
- * -> /tmp/mp_time.<pid>.log"
- * use g_get_tmp_dir() + "/mp_" as default
- */
-#define MP_TIME_LOG "/tmp/mp_time.log"
-#define MP_FRAG_LOG "/tmp/mp_frag.log"
-#define MP_USE_LOG "/tmp/mp_use.log"
-#define MP_BT_LOG "/tmp/mp_bt.log"
+/* log file names */
static gchar *mp_log_base;
+static gchar *mp_time_log_name=NULL;
+static gchar *mp_frag_log_name=NULL;
+static gchar *mp_use_log_name=NULL;
+static gchar *mp_bt_log_name=NULL;
#define MP_BACKTRACE_DEPTH 8
@@ -146,7 +143,7 @@
{
FILE *log;
- if ((log=fopen(MP_FRAG_LOG,"wt"))) {
+ if ((log=fopen(mp_frag_log_name,"wt"))) {
MpNode *cur;
guint i;
@@ -158,7 +155,10 @@
"%6"G_GSIZE_FORMAT" %lf %lf %p\n",
cur->size, cur->ts, mp_get_timestamp(), PADDED_TO_REAL(cur));
}
- fclose(log);
+ fclose (log);
+ }
+ else {
+ fprintf (stderr, "Can't open %s : %s\n", mp_frag_log_name, strerror (errno));
}
}
@@ -172,7 +172,7 @@
FILE *use_log;
if (ts >= mp_log_start) {
- if ((use_log = fopen (MP_USE_LOG, "at"))) {
+ if ((use_log = fopen (mp_use_log_name, "at"))) {
gchar ts_str[G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_dtostr(ts_str,G_ASCII_DTOSTR_BUF_SIZE,ts);
@@ -181,6 +181,9 @@
ts_str, asize/mp_usage_scale, usize/mp_usage_scale);
fclose(use_log);
}
+ else {
+ fprintf (stderr, "Can't open %s : %s\n", mp_use_log_name, strerror (errno));
+ }
}
}
@@ -249,7 +252,7 @@
else {
FILE *log;
- if ((log = fopen (MP_BT_LOG,"at"))) {
+ if ((log = fopen (mp_bt_log_name,"at"))) {
gpointer trace[MP_BACKTRACE_DEPTH];
gint i, count = backtrace (trace, MP_BACKTRACE_DEPTH);
@@ -259,6 +262,9 @@
fprintf (log,"\n", trace[i]);
fclose(log);
}
+ else {
+ fprintf (stderr, "Can't open %s : %s\n", mp_bt_log_name, strerror (errno));
+ }
}
}
}
@@ -283,7 +289,7 @@
if (node->ts >= mp_log_start) {
FILE *time_log;
- if ((time_log = fopen (MP_TIME_LOG, "at"))) {
+ if ((time_log = fopen (mp_time_log_name, "at"))) {
gchar tss[G_ASCII_DTOSTR_BUF_SIZE],tse[G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_dtostr(tss,G_ASCII_DTOSTR_BUF_SIZE,node->ts);
@@ -294,6 +300,9 @@
node->size, tss, tse, PADDED_TO_REAL(entry));
fclose(time_log);
}
+ else {
+ fprintf (stderr, "Can't open %s : %s\n", mp_time_log_name, strerror (errno));
+ }
}
}
else {
@@ -372,12 +381,8 @@
NULL,
};
gchar *envvar;
+ int sl;
- unlink(MP_TIME_LOG);
- unlink(MP_FRAG_LOG);
- unlink(MP_USE_LOG);
- unlink(MP_BT_LOG);
-
if( (envvar = getenv ("MP_TRACE_SIZE"))) {
mp_trace_size = atoi (envvar);
}
@@ -391,8 +396,33 @@
mp_log_start = atof (envvar);
}
if(!(mp_log_base = getenv ("MP_LOG_BASE"))) {
- mp_log_base = "/tmp/mp_";
- }
+ const gchar *tmpdir=g_get_tmp_dir();
+ mp_log_base = malloc(strlen(tmpdir)+strlen("/mp_")+1);
+ strcpy (mp_log_base, tmpdir);
+ strcat (mp_log_base, "/mp_");
+ }
+ sl=strlen(mp_log_base);
+
+ mp_time_log_name = malloc (sl + strlen ("time.log") + 1);
+ strcpy (mp_time_log_name, mp_log_base);
+ strcat (mp_time_log_name, "time.log");
+
+ mp_frag_log_name = malloc (sl + strlen ("frag.log") + 1);
+ strcpy (mp_frag_log_name, mp_log_base);
+ strcat (mp_frag_log_name, "frag.log");
+
+ mp_use_log_name = malloc (sl + strlen ("use.log") + 1);
+ strcpy (mp_use_log_name, mp_log_base);
+ strcat (mp_use_log_name, "use.log");
+
+ mp_bt_log_name = malloc (sl + strlen ("bt.log") + 1);
+ strcpy (mp_bt_log_name, mp_log_base);
+ strcat (mp_bt_log_name, "bt.log");
+
+ unlink (mp_time_log_name);
+ unlink (mp_frag_log_name);
+ unlink (mp_use_log_name);
+ unlink (mp_bt_log_name);
/*
if (!(time_log = fopen (MP_TIME_LOG, "wt"))) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]