[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r7694 - in flightrecorder/src: include libflightrecorder
From: |
gnunet |
Subject: |
[GNUnet-SVN] r7694 - in flightrecorder/src: include libflightrecorder |
Date: |
Thu, 11 Sep 2008 13:53:31 -0600 (MDT) |
Author: durner
Date: 2008-09-11 13:53:30 -0600 (Thu, 11 Sep 2008)
New Revision: 7694
Modified:
flightrecorder/src/include/flightrecorder.h
flightrecorder/src/libflightrecorder/stack_trace.c
Log:
fr_st_iterate()
Modified: flightrecorder/src/include/flightrecorder.h
===================================================================
--- flightrecorder/src/include/flightrecorder.h 2008-09-11 04:47:15 UTC (rev
7693)
+++ flightrecorder/src/include/flightrecorder.h 2008-09-11 19:53:30 UTC (rev
7694)
@@ -1,4 +1,4 @@
-/*
+/*
libflightrecorder - Client library for flightrecorder, a recorder for
runtime information gathered by AOP advices or other process internal
checks
@@ -55,6 +55,8 @@
unsigned int trace_count;
} FR_Session;
+typedef int (*StackTraceIterator)(StackTraceEntry *entry);
+
typedef enum {FR_OPT_RECORD_STACK_TRACE} FR_Option;
void *fr_malloc (size_t n);
@@ -119,11 +121,18 @@
StackTrace *fr_st_get(unsigned int tid);
/**
- * @brief Return a list of thread IDs
+ * @brief Return a list of thread IDs
* @return array of thread IDs, NULL on error
*/
unsigned int *fr_st_threads();
+/**
+ * @brief Call a function for each entry on the call stack
+ * @param trace stack trace
+ * @param iter callback function
+ */
+void fr_st_iterate(StackTrace *trace, StackTraceIterator iter);
+
/* --- Stack traces - C/S API --- */
/**
@@ -163,7 +172,7 @@
StackTrace *fr_srv_st_get(FR_Session *ses, unsigned int tid);
/**
- * @brief Return a list of thread IDs
+ * @brief Return a list of thread IDs
* @param ses C/S session
* @return array of thread IDs, NULL on error
*/
Modified: flightrecorder/src/libflightrecorder/stack_trace.c
===================================================================
--- flightrecorder/src/libflightrecorder/stack_trace.c 2008-09-11 04:47:15 UTC
(rev 7693)
+++ flightrecorder/src/libflightrecorder/stack_trace.c 2008-09-11 19:53:30 UTC
(rev 7694)
@@ -1,4 +1,4 @@
-/*
+/*
libflightrecorder - Client library for flightrecorder, a recorder for
runtime information gathered by AOP advices or other process internal
checks
@@ -33,10 +33,10 @@
{
ses->traces = (StackTrace *) fr_malloc(sizeof(StackTrace));
ses->trace_count++;
-
+
return ses->traces;
}
-
+
trace = ses->traces;
for (idx = 0; idx < ses->trace_count; idx++)
{
@@ -45,12 +45,12 @@
else
trace++;
}
-
+
ses->traces = (StackTrace *) fr_realloc(ses->traces, ++ses->trace_count *
sizeof(StackTrace));
-
+
if (!ses->traces)
return NULL;
-
+
trace = ses->traces + ses->trace_count - 1;
trace->tid = tid;
trace->depth = 0;
@@ -70,7 +70,7 @@
{
StackTrace *trace;
StackTraceEntry *entry;
-
+
trace = get_trace(ses, fr_thread_get_tid());
if (!trace)
return 0;
@@ -81,7 +81,7 @@
trace->entries = (StackTraceEntry *) fr_realloc(trace->entries,
(trace->depth + 1) * sizeof(StackTraceEntry));
if (!trace->entries)
return 0;
-
+
trace->depth++;
entry = trace->entries + trace->depth - 1;
entry->file = file;
@@ -89,7 +89,7 @@
entry->function = function;
entry->info = NULL;
entry->info_count = 0;
-
+
return 1;
}
@@ -104,20 +104,20 @@
int fr_srv_st_leave(FR_Session *ses, char *file, unsigned int line, char
*function)
{
StackTrace *trace;
-
+
trace = get_trace(ses, fr_thread_get_tid());
if (!trace || trace->depth == 0)
return 0;
-
+
if (trace->depth)
{
StackTraceEntry *entry;
unsigned int idx;
-
+
entry = trace->entries + trace->depth - 1;
for(idx = 0; idx < entry->info_count; idx++)
fr_free(entry->info[idx]);
-
+
trace->entries = (StackTraceEntry *) fr_realloc(trace->entries,
--trace->depth * sizeof(StackTraceEntry));
if (!trace->entries)
return 0;
@@ -127,7 +127,7 @@
fr_free(trace->entries);
trace->entries = NULL;
}
-
+
return 1;
}
@@ -141,7 +141,7 @@
{
StackTrace *trace;
StackTraceEntry *entry;
-
+
trace = get_trace(ses, fr_thread_get_tid());
if (!trace || !trace->depth)
return 0;
@@ -151,12 +151,12 @@
entry->info = (char **) fr_realloc(entry->info, (entry->info_count + 1) *
sizeof(char *));
else
entry->info = (char **) fr_malloc(sizeof(char *));
-
+
if (!entry->info)
return 0;
-
+
entry->info[entry->info_count - 1] = fr_strdup(info);
-
+
return 1;
}
@@ -172,7 +172,7 @@
}
/**
- * @brief Return a list of thread IDs
+ * @brief Return a list of thread IDs
* @param ses C/S session
* @return array of thread IDs, NULL on error
*/
@@ -180,13 +180,33 @@
{
unsigned int idx;
unsigned int *ret;
-
+
ret = fr_malloc(ses->trace_count * sizeof(unsigned int));
if (!ret)
return NULL;
-
+
for (idx = 0; idx < ses->trace_count; idx++)
ret[idx] = ses->traces[idx].tid;
-
+
return ret;
}
+
+/**
+ * @brief Call a function for each entry on the call stack
+ * @param trace stack trace
+ * @param iter callback function
+ */
+void fr_st_iterate(StackTrace *trace, StackTraceIterator iter)
+{
+ StackTraceEntry *entry;
+ unsigned idx;
+
+ entry = trace->entries;
+ for (idx = trace->depth; idx > 0; idx--)
+ {
+ if (! iter(entry))
+ break;
+
+ entry++;
+ }
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r7694 - in flightrecorder/src: include libflightrecorder,
gnunet <=