Index: Makefile.am =================================================================== RCS file: /cvs/gnome/sysprof/Makefile.am,v retrieving revision 1.3 diff -u -r1.3 Makefile.am --- Makefile.am 15 May 2005 14:25:01 -0000 1.3 +++ Makefile.am 24 Aug 2005 20:38:05 -0000 @@ -1,7 +1,7 @@ SUBDIRS = module DIST_SUBDIRS = module -bin_PROGRAMS = sysprof +bin_PROGRAMS = sysprof sysprof-text pkgdata_DATA = sysprof.glade sysprof-icon.png sysprof_SOURCES = \ @@ -22,7 +22,27 @@ watch.h \ watch.c +sysprof_text_SOURCES = \ + binfile.h \ + binfile.c \ + process.h \ + process.c \ + profile.h \ + profile.c \ + sfile.h \ + sfile.c \ + stackstash.h \ + stackstash.c \ + module/sysprof-module.h \ + sysprof-text.c \ + treeviewutils.h \ + treeviewutils.c \ + watch.h \ + watch.c + sysprof_LDADD = $(DEP_LIBS) + +sysprof_text_LDADD = $(DEP_LIBS) INCLUDES = \ $(DEP_CFLAGS) \ Index: sysprof-text.c =================================================================== RCS file: /cvs/gnome/sysprof/sysprof-text.c,v retrieving revision 1.1 diff -u -r1.1 sysprof-text.c --- sysprof-text.c 12 Nov 2004 23:27:52 -0000 1.1 +++ sysprof-text.c 24 Aug 2005 20:38:05 -0000 @@ -1,21 +1,116 @@ -/* - * Plan: - * - * blocking_read() - * - * select (fd); - * if (readable) - * read(); - * - * - * handle SIGUSR1 - * write spam to commandline given file - * - */ +#include +#include +#include +#include +#include +#include +#include -int -main () +#include "stackstash.h" +#include "module/sysprof-module.h" +#include "profile.h" +#include "process.h" +#include "watch.h" + +#define SYSPROF_FILE "/proc/sysprof-trace" + +int fd; +StackStash *gStash; +GMainLoop *loop; +char *outfile; + +void read_trace(StackStash *stash, SysprofStackTrace *trace, GTimeVal now) +{ + Process *process = process_get_from_pid (trace->pid); + int i; + for (i = 0; i < trace->n_addresses; ++i) + { + process_ensure_map (process, trace->pid, + (gulong)trace->addresses[i]); + } + + stack_stash_add_trace ( + stash, process, + (gulong *)trace->addresses, trace->n_addresses, 1); + +} + +void on_read(gpointer data) +{ + SysprofStackTrace trace; + int bytesread; + GTimeVal now; + + bytesread = read (fd, &trace, sizeof (trace)); + g_get_current_time (&now); + + if(bytesread < 0) + { + perror("read"); + return; + } + + if(bytesread > 0) + { + read_trace(gStash, &trace, now); + } + +} + +void +dump_data (StackStash *stash) { + GError *err = NULL; + Profile *profile = profile_new (stash); + + profile_save(profile, outfile, &err); + + if(err) { + fprintf(stderr, "%s: %s\n", outfile, err->message); + exit(1); + } +} + +void sighandler(int sig) +{ + signal(SIGTERM, SIG_DFL); + signal(SIGINT, SIG_DFL); + + dump_data(gStash); + g_main_loop_quit(loop); +} + +int main(int argc, char *argv[]) +{ + if(argc < 2) + { + fprintf(stderr, "\ +Usage: %s \n\ +Activates sysprof profiling and dumps it to outfile on SIGTERM or SIGINT.\n\ +", + argv[0]); + return 0; + } + + fd = open(SYSPROF_FILE, O_RDONLY); + if(fd < 0) + { + perror(SYSPROF_FILE); + fprintf(stderr, "Have you loaded the sysprof module?"); + return 1; + } + + outfile = argv[1]; + + gStash = stack_stash_new (); + signal(SIGTERM, sighandler); + signal(SIGINT, sighandler); + + loop = g_main_loop_new(NULL, 0); + fd_add_watch (fd, gStash); + fd_set_read_callback (fd, on_read); + g_main_loop_run(loop); + return 0; }