[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r5788 - in branches/flightrecorder/src: . flighrecorderd in
From: |
gnunet |
Subject: |
[GNUnet-SVN] r5788 - in branches/flightrecorder/src: . flighrecorderd include libflightrecorder |
Date: |
Sat, 1 Dec 2007 14:38:09 -0700 (MST) |
Author: durner
Date: 2007-12-01 14:38:09 -0700 (Sat, 01 Dec 2007)
New Revision: 5788
Added:
branches/flightrecorder/src/include/flightrecorder.h
branches/flightrecorder/src/libflightrecorder/
branches/flightrecorder/src/libflightrecorder/main.c
branches/flightrecorder/src/libflightrecorder/private.h
branches/flightrecorder/src/libflightrecorder/stack_trace.c
branches/flightrecorder/src/libflightrecorder/threads.c
branches/flightrecorder/src/libflightrecorder/xmalloc.c
Removed:
branches/flightrecorder/src/util/
Modified:
branches/flightrecorder/src/flighrecorderd/flightrecorder.c
Log:
draft
Modified: branches/flightrecorder/src/flighrecorderd/flightrecorder.c
===================================================================
--- branches/flightrecorder/src/flighrecorderd/flightrecorder.c 2007-12-01
21:24:31 UTC (rev 5787)
+++ branches/flightrecorder/src/flighrecorderd/flightrecorder.c 2007-12-01
21:38:09 UTC (rev 5788)
@@ -1,5 +1,6 @@
/*
- flightrecorder - A recorder for runtime information gathered by AOP advices
or other process internal checks
+ flightrecorder - A recorder for runtime information gathered by AOP advices
+ or other process internal checks
Copyright (C) 2007 Nils Durner
@@ -16,10 +17,6 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-#include <termios.h>
-#include <grp.h>
-#include <pwd.h>
*/
#include <stdio.h>
Added: branches/flightrecorder/src/include/flightrecorder.h
===================================================================
--- branches/flightrecorder/src/include/flightrecorder.h
(rev 0)
+++ branches/flightrecorder/src/include/flightrecorder.h 2007-12-01
21:38:09 UTC (rev 5788)
@@ -0,0 +1,42 @@
+/*
+ libflightrecorder - Client library for flightrecorder, a recorder for
+ runtime information gathered by AOP advices or other process internal
+ checks
+
+ Copyright (C) 2007 Nils Durner
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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 Street, Fifth Floor, Boston, MA 02110-1301
USA
+*/
+
+#ifndef FLIGHTRECORDER_H_
+#define FLIGHTRECORDER_H_
+
+typedef struct
+{
+ char *file;
+ unsigned int line;
+ char *function;
+ char **info;
+ unsigned int info_count;
+} StackTraceEntry;
+
+typedef struct
+{
+ StackTraceEntry *entries;
+ unsigned int depth;
+ unsigned int tid;
+} StackTrace;
+
+#endif /*FLIGHTRECORDER_H_*/
Added: branches/flightrecorder/src/libflightrecorder/main.c
===================================================================
--- branches/flightrecorder/src/libflightrecorder/main.c
(rev 0)
+++ branches/flightrecorder/src/libflightrecorder/main.c 2007-12-01
21:38:09 UTC (rev 5788)
@@ -0,0 +1,64 @@
+/*
+ libflightrecorder - Client library for flightrecorder, a recorder for
+ runtime information gathered by AOP advices or other process internal
+ checks
+
+ Copyright (C) 2007 Nils Durner
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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 Street, Fifth Floor, Boston, MA 02110-1301
USA
+*/
+
+typedef struct
+{
+ unsigned int sock;
+} Session;
+
+static Session *sessions = NULL;
+static unsigned session_count = 0;
+static int remote_operation;
+
+/**
+ * @brief Initializes a session with the flightrecorder server
+ * @param server server name, NULL for in-process operation
+ * @param port server port
+ * @param opt server's logging/evaluation options
+ * @param desc optional description of the session (e.g. hostname)
+ * @return 1 on success, 0 otherwise
+ */
+int fr_init(char *server, unsigned int port, FLIGHT_REC_OPTS opts, char *desc)
+{
+ if (!sessions)
+ {
+ sessions = MALLOC(sizeof(Session));
+ session_count = 1;
+ }
+ else
+ sessions = REALLOC(++session_count * sizeof(Session));
+
+ if (! sessions)
+ return 0;
+
+ if (server)
+ {
+ remote_operation = 1;
+ }
+ else
+ remote_operation = 0;
+
+ // FIXME
+ // ...
+
+ return 1;
+}
Added: branches/flightrecorder/src/libflightrecorder/private.h
===================================================================
--- branches/flightrecorder/src/libflightrecorder/private.h
(rev 0)
+++ branches/flightrecorder/src/libflightrecorder/private.h 2007-12-01
21:38:09 UTC (rev 5788)
@@ -0,0 +1,38 @@
+/*
+ libflightrecorder - Client library for flightrecorder, a recorder for
+ runtime information gathered by AOP advices or other process internal
+ checks
+
+ Copyright (C) 2007 Nils Durner
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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 Street, Fifth Floor, Boston, MA 02110-1301
USA
+*/
+
+#ifndef PRIVATE_H_
+#define PRIVATE_H_
+
+#ifdef WINDOWS
+ #include <windows.h>
+
+ #define THREAD_TYPE DWORD
+#elif HAVE_PTHREADS
+ #include <pthread.h>
+
+ #define THREAD_TYPE pthread_t
+#else
+ #error Port threads.h/private.h
+#endif
+
+#endif /*PRIVATE_H_*/
Added: branches/flightrecorder/src/libflightrecorder/stack_trace.c
===================================================================
--- branches/flightrecorder/src/libflightrecorder/stack_trace.c
(rev 0)
+++ branches/flightrecorder/src/libflightrecorder/stack_trace.c 2007-12-01
21:38:09 UTC (rev 5788)
@@ -0,0 +1,200 @@
+/*
+ libflightrecorder - Client library for flightrecorder, a recorder for
+ runtime information gathered by AOP advices or other process internal
+ checks
+
+ Copyright (C) 2007 Nils Durner
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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 Street, Fifth Floor, Boston, MA 02110-1301
USA
+*/
+
+#include "flightrecorder.h"
+#include "private.h"
+
+static StackTrace *traces = NULL;
+static unsigned int threads = 0;
+
+static StackTrace *get_trace(THREAD_TYPE tid)
+{
+ StackTrace *trace;
+ unsigned idx;
+
+ if (!threads)
+ {
+ traces = (StackTrace *) MALLOC(sizeof(StackTrace));
+ threads++;
+
+ return traces;
+ }
+
+ trace = traces;
+ for (idx = 0; idx < threads; idx++)
+ {
+ if (fr_thread_cmp(trace->tid, tid))
+ return trace;
+ else
+ trace++;
+ }
+
+ traces = (StackTrace *) REALLOC(traces, ++threads * sizeof(StackTrace));
+
+ if (!traces)
+ return NULL;
+
+ trace = traces[threads-1];
+ trace->tid = tid;
+ trace->depth = 0;
+ trace->entries = NULL
+ return trace;
+}
+
+static THREAD_TYPE get_tid()
+{
+#if WINDOWS
+ return GetThreadID();
+#elif HAVE_PTHREADS
+ return pthread_self(); // FIXME
+#else
+ #error Port get_tid()
+#endif
+}
+
+/**
+ * @brief Add function to the stack trace
+ * @param file source file from which the function is called
+ * @param line source line from which the function is called
+ * @param function name of the function that is called
+ * @return 1 on success, 0 otherwise
+ */
+int fr_st_enter(char *file, unsigned int line, char *function)
+{
+ StrackTrace *trace;
+ StackTraceEntry *entry;
+
+ trace = get_trace(get_tid());
+ if (!trace)
+ return 0;
+
+ if (trace->depth == 0)
+ trace->entries = (StackTraceEntry *) MALLOC(sizeof(StackTraceEntry));
+ else
+ trace->entries = (StackTraceEntry *) REALLOC(trace->entries, (trace->depth
+ 1) * sizeof(StrackTraceEntry));
+ if (!trace->entries)
+ return 0;
+
+ trace->depth++;
+ entry = trace->entries[trace->depth-1];
+ entry->file = file;
+ entry->line = line;
+ entry->function = function;
+ entry->info = NULL;
+ entry->info_count = 0;
+
+ return 1;
+}
+
+/**
+ * @brief Remove function from the stack trace
+ * @param file source file from which the function is called
+ * @param line source line from which the function is called
+ * @param function name of the function that is called
+ * @return 1 on success, 0 otherwise
+ */
+int fr_st_leave(char *file, unsigned int line, char *function)
+{
+ StrackTrace *trace;
+
+ trace = get_trace(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++)
+ FREE(entry->info[idx]);
+
+ trace->entries = (StackTraceEntry *) REALLOC(trace->entries,
--trace->depth * sizeof(StackTraceEntry));
+ if (!trace->entries)
+ return 0;
+ }
+ else
+ {
+ FREE(trace->entries);
+ trace->entries = NULL;
+ }
+
+ return 1;
+}
+
+/**
+ * @brief Add a info to the last stack trace entry
+ * @param info diagnostics information/log/...
+ * @return 1 on success, 0 on error
+ */
+int fr_st_add_info(char *info)
+{
+ StrackTrace *trace;
+ StackTraceEntry *entry;
+
+ trace = get_trace(get_tid());
+ if (!trace || !trace->depth)
+ return 0;
+
+ entry = trace->entries + trace->depth - 1;
+ if (entry->info_count)
+ entry->info = (char **) REALLOC(entry->info, (entry->info_count + 1) *
sizeof(char *));
+ else
+ entry->info = (char **) MALLOC(sizeof(char *));
+
+ if (!entry->info)
+ return 0;
+
+ entry->info[entry->info_count - 1] = strdup(info);
+
+ return 1;
+}
+
+/**
+ * @brief Return the stack trace for a particular thread
+ * @param tid thread ID
+ * @return pointer stack trace, NULL on error
+ */
+StackTrace *fr_st_get(unsigned int tid)
+{
+ return get_trace(tid);
+}
+
+/**
+ * @brief Return a list of thread IDs
+ * @return array of thread IDs, NULL on error
+ */
+unsigned int *fr_st_threads()
+{
+ unsigned int idx;
+ unsigned int *ret;
+
+ ret = MALLOC(threads * sizeof(unsigned int));
+ if (!ret)
+ return NULL;
+
+ for (idx = 0; idx < threads; idx++)
+ ret[idx] = traces[idx]->tid;
+
+ return ret;
+}
Added: branches/flightrecorder/src/libflightrecorder/threads.c
===================================================================
--- branches/flightrecorder/src/libflightrecorder/threads.c
(rev 0)
+++ branches/flightrecorder/src/libflightrecorder/threads.c 2007-12-01
21:38:09 UTC (rev 5788)
@@ -0,0 +1,60 @@
+/*
+ libflightrecorder - Client library for flightrecorder, a recorder for
+ runtime information gathered by AOP advices or other process internal
+ checks
+
+ Copyright (C) 2007 Nils Durner
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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 Street, Fifth Floor, Boston, MA 02110-1301
USA
+*/
+
+#ifdef WINDOWS
+ #include <windows.h>
+#elif HAVE_PTHREADS
+ #include <pthread.h>
+#else
+ #error Port threads.h
+#endif
+
+/**
+ * @brief Get the current thread's ID
+ * @return thread ID
+ */
+THREAD_TYPE fr_thread_get_tid()
+{
+#if WINDOWS
+ return GetThreadId();
+#elif HAVE_PTHREADS
+ return pthread_self();
+#else
+ #error Port fr_util_get_tid()
+#endif
+}
+
+/**
+ * @brief Compare two thread IDs
+ * @param t1 first thread ID
+ * @param t2 second thread ID
+ * @return 1 on success, 0 otherwise
+ */
+int fr_thread_cmp(THREAD_TYPE t1, THREAD_TYPE t2)
+{
+#if WINDOWS
+ return t1 == t2;
+#else
+ // FIXME
+ return 1;
+#endif
+}
Added: branches/flightrecorder/src/libflightrecorder/xmalloc.c
===================================================================
--- branches/flightrecorder/src/libflightrecorder/xmalloc.c
(rev 0)
+++ branches/flightrecorder/src/libflightrecorder/xmalloc.c 2007-12-01
21:38:09 UTC (rev 5788)
@@ -0,0 +1,142 @@
+/* xmalloc.c -- malloc with out of memory checking
+ Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 99 Free Software Foundation,
Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if __STDC__
+# define VOID void
+#else
+# define VOID char
+#endif
+
+#include <stdio.h> /* for stderr */
+
+#if STDC_HEADERS
+
+#include <sys/types.h>
+#include <string.h> /* for strlen etc. */
+#include <stdlib.h>
+
+#else /* !STDC_HEADERS */
+
+extern size_t strlen ();
+extern char *strcpy ();
+
+VOID *calloc ();
+VOID *malloc ();
+VOID *realloc ();
+void free ();
+#endif
+
+#if ENABLE_NLS
+# include <libintl.h>
+# define _(Text) gettext (Text)
+#else
+# define textdomain(Domain)
+# define _(Text) Text
+#endif
+
+#include <error.h>
+
+/* Prototypes for functions defined here. */
+#if defined (__STDC__) && __STDC__
+static VOID *fixup_null_alloc (size_t n);
+VOID *xmalloc (size_t n);
+VOID *xcalloc (size_t n, size_t s);
+VOID *xrealloc (VOID *p, size_t n);
+char *xstrdup (char *p);
+#endif
+
+
+static VOID *
+fixup_null_alloc (n)
+ size_t n;
+{
+ VOID *p;
+
+ p = 0;
+ if (n == 0)
+ p = malloc ((size_t) 1);
+ if (p == 0)
+ {
+ /* possible revisions: release some memory and re-try, print
+ more information (e.g. line number of input file) */
+ fprintf(stderr, _("flightrecorder: Memory exhausted"));
+ exit(1);
+ }
+ return p;
+}
+
+/* Allocate N bytes of memory dynamically, with error checking. */
+
+VOID *
+xmalloc (n)
+ size_t n;
+{
+ VOID *p;
+
+ p = malloc (n);
+ if (p == 0)
+ p = fixup_null_alloc (n);
+ return p;
+}
+
+/* Allocate memory for N elements of S bytes, with error checking. */
+
+VOID *
+xcalloc (n, s)
+ size_t n, s;
+{
+ VOID *p;
+
+ p = calloc (n, s);
+ if (p == 0)
+ p = fixup_null_alloc (n);
+ return p;
+}
+
+/* Change the size of an allocated block of memory P to N bytes,
+ with error checking.
+ If P is NULL, run xmalloc. */
+
+VOID *
+xrealloc (p, n)
+ VOID *p;
+ size_t n;
+{
+ if (p == 0)
+ return xmalloc (n);
+ p = realloc (p, n);
+ if (p == 0)
+ p = fixup_null_alloc (n);
+ return p;
+}
+
+/* Make a copy of a string in a newly allocated block of memory. */
+
+char *
+xstrdup (str)
+ char *str;
+{
+ VOID *p;
+
+ p = xmalloc (strlen (str) + 1);
+ strcpy (p, str);
+ return p;
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r5788 - in branches/flightrecorder/src: . flighrecorderd include libflightrecorder,
gnunet <=