From: John L. <mov...@us...> - 2002-05-02 02:19:41
|
Update of /cvsroot/oprofile/oprofile/dae In directory usw-pr-cvs1:/tmp/cvs-serv8579/dae Modified Files: .cvsignore Makefile.in op_start op_stop opd_kernel.c opd_proc.c opd_proc.h opd_util.c opd_util.h oprofiled.c oprofiled.h Added Files: op_session.c Log Message: Most files touched, but actually nothing particularly exciting : 1) command line cleanup 2) daemon lock file 3) named sessions support --- NEW FILE: op_session.c --- /** * \file op_session.c * Copyright 2002 * Read the file COPYING * * \author John Levon <mo...@co...> */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <signal.h> #include <dirent.h> #include "opd_util.h" #include "../util/op_popt.h" char * sessionname; int showvers; static struct poptOption options[] = { { "session", 's', POPT_ARG_STRING, &sessionname, 0, "save current session under this name", "session-name", }, { "version", 'v', POPT_ARG_NONE, &showvers, 0, "show version", NULL, }, POPT_AUTOHELP { NULL, 0, 0, NULL, 0, NULL, NULL, }, }; /** * opd_options - parse command line options * @argc: argc * @argv: argv array * * Parse all command line arguments. */ static void opd_options(int argc, char const *argv[]) { poptContext optcon; optcon = opd_poptGetContext(NULL, argc, argv, options, 0); if (showvers) { show_version(argv[0]); } if (!sessionname) { fprintf(stderr, "op_session: no session name specified !\n"); poptPrintHelp(optcon, stderr, 0); exit(EXIT_FAILURE); } poptFreeContext(optcon); } /** * opd_move_files - move all the sample files * \param sname name of session directory * */ static void opd_move_files(char const * sname) { char * dir_name; DIR * dir; struct dirent * dirent; dir_name = xmalloc(strlen(OP_SAMPLES_DIR) + strlen(sname) + 1); strcpy(dir_name, OP_SAMPLES_DIR); strcat(dir_name, sname); if (mkdir(dir_name, 0755)) { fprintf(stderr, "unable to create directory %s\n", dir_name); exit(EXIT_FAILURE); } if (!(dir = opendir(OP_SAMPLES_DIR))) { fprintf(stderr, "unable to open directory " OP_SAMPLES_DIR "\n"); exit(EXIT_FAILURE); } while ((dirent = readdir(dir)) != 0) { if (opd_move_regular_file(dir_name, OP_SAMPLES_DIR, dirent->d_name)) { fprintf(stderr, "unable to backup %s/%s to directory %s\n", OP_SAMPLES_DIR, dirent->d_name, dir_name); exit(EXIT_FAILURE); } } closedir(dir); free(dir_name); } /** * opd_signal_daemon - signal daemon to re-open if it exists */ static void opd_signal_daemon(void) { pid_t pid = opd_read_lock_file(OP_LOCK_FILE); if (pid) { kill(pid, SIGHUP); } } int main(int argc, char const *argv[]) { opd_options(argc, argv); opd_move_files(sessionname); opd_signal_daemon(); return 0; } Index: .cvsignore =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/.cvsignore,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- .cvsignore 31 Dec 2001 06:37:26 -0000 1.2 +++ .cvsignore 2 May 2002 02:19:04 -0000 1.3 @@ -1,4 +1,5 @@ .deps Makefile oprofiled +op_session op_help Index: Makefile.in =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/Makefile.in,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- Makefile.in 24 Apr 2002 17:59:30 -0000 1.28 +++ Makefile.in 2 May 2002 02:19:05 -0000 1.29 @@ -1,16 +1,16 @@ # $Id$ -INSTALL_LIST=oprofiled op_start op_dump op_stop +INSTALL_LIST=oprofiled op_start op_dump op_stop op_session CFLAGS=-Wall -Wstrict-prototypes -pipe -Wunused -W -Wshadow -Wmissing-prototypes -Winline @CFLAGS@ LIBS=@extra_libraries@ -lpopt -liberty -SOURCES=oprofiled.c opd_util.c opd_proc.c opd_kernel.c +SOURCES=oprofiled.c opd_util.c opd_proc.c opd_kernel.c op_session.c OBJS=oprofiled.o opd_util.o opd_proc.o opd_kernel.o ../events/op_events.o ../events/op_events_desc.o ../util/op_popt.o ../util/misc.o .PHONY: all clean srcdoc install uninstall -all: oprofiled +all: oprofiled op_session install: all -$(MKDIR_P) $(BINDIR) @@ -34,6 +34,9 @@ oprofiled: $(OBJS) ../libdb/libdb.a $(CC) $(CFLAGS) $(INCLUDES) -g -o $@ $^ $(LIBS) +op_session: op_session.o opd_util.o ../util/op_popt.o + $(CC) $(CFLAGS) $(INCLUDES) -g -o $@ $^ $(LIBS) + %.o: %c $(CC) -c $(CFLAGS) -g $< -o $@ Index: op_start =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/op_start,v retrieving revision 1.64 retrieving revision 1.65 diff -u -d -r1.64 -r1.65 --- op_start 1 May 2002 19:03:43 -0000 1.64 +++ op_start 2 May 2002 02:19:06 -0000 1.65 @@ -94,13 +94,7 @@ --pgrp-filter=pgrp Only profile process group pgrp Daemon options - --log-file=file log file - --base-dir=dir base directory of daemon - --samples-dir=file output samples directory --separate-samples separate samples for each distinct application - --device-file=file profile device file - --note-device-file=file note device file - --hash-map-device-file=file profile hash map device file --map-file=file System.map for running kernel file --vmlinux=file vmlinux kernel image --verbose be verbose in the daemon log @@ -128,12 +122,6 @@ # initialise parameters do_init() { - LOG_FILE= - SEPARATE_SAMPLES=0 - SAMPLES_DIR= - DEVICE_FILE= - NOTE_DEVICE_FILE= - HASH_MAP_DEVICE_FILE= # for these three buffer size == 0 means use the default value # hard-coded in op_user.h BUF_SIZE=0 @@ -141,12 +129,21 @@ NOTE_SIZE=0 KERNEL_ONLY=0 IGNORE_MYSELF=0 - DIR="/var/opd" MAP_FILE= VMLINUX= PID_FILTER=0 PGRP_FILTER=0 VERBOSE=0 + SEPARATE_SAMPLES=0 + + # as in op_user.h + DIR="/var/lib/oprofile/" + LOCK_FILE="/var/lib/oprofile/lock" + LOG_FILE="$DIR/oprofiled.log" + SAMPLES_DIR="$DIR/samples/" + DEVICE_FILE="$DIR/opdev" + NOTE_DEVICE_FILE="$DIR/opnotedev" + HASH_MAP_DEVICE_FILE="$DIR/ophashmapdev" CPUTYPE=`cat /proc/sys/dev/oprofile/cpu_type` @@ -229,27 +226,9 @@ --rtc-value) RTC_VALUE=$val ;; - --base-dir) - DIR=$val - ;; - --samples-dir) - SAMPLES_DIR=$val - ;; --separate-samples) SEPARATE_SAMPLES=1 ;; - --log-file) - LOG_FILE=$val - ;; - --device-file) - DEVICE_FILE=$val - ;; - --note-device-file) - NOTE_DEVICE_FILE=$val - ;; - --hash-map-device-file) - HASH_MAP_DEVICE_FILE=$val - ;; --map-file) MAP_FILE=$val ;; @@ -321,21 +300,6 @@ fi fi - if [ "$LOG_FILE" = "" ]; then - LOG_FILE="$DIR/oprofiled.log" - fi - if [ "$SAMPLES_DIR" = "" ]; then - SAMPLES_DIR="$DIR/samples/" - fi - if [ "$DEVICE_FILE" = "" ]; then - DEVICE_FILE="$DIR/opdev" - fi - if [ "$NOTE_DEVICE_FILE" = "" ]; then - NOTE_DEVICE_FILE="$DIR/opnotedev" - fi - if [ "$HASH_MAP_DEVICE_FILE" = "" ]; then - HASH_MAP_DEVICE_FILE="$DIR/ophashmapdev" - fi vecho "Parameters used:" vecho "CPUTYPE $CPUTYPE" @@ -368,13 +332,7 @@ vecho "RTC_VALUE $RTC_VALUE" fi vecho "IGNORE_MYSELF $IGNORE_MYSELF" - vecho "DIR $DIR" - vecho "LOG_FILE $LOG_FILE" - vecho "SAMPLES_DIR $SAMPLES_DIR" vecho "SEPARATE_SAMPLES $SEPARATE_SAMPLES" - vecho "DEVICE_FILE $DEVICE_FILE" - vecho "NOTE_DEVICE_FILE $NOTE_DEVICE_FILE" - vecho "HASH_MAP_DEVICE_FILE $HASH_MAP_DEVICE_FILE" vecho "MAP_FILE $MAP_FILE" vecho "VMLINUX $VMLINUX" @@ -514,11 +472,14 @@ # start the daemon do_start() { - OPD_ARGS=" \ - --log-file=$LOG_FILE --base-dir=$DIR --samples-dir=$SAMPLES_DIR \ - --device-file=$DEVICE_FILE --note-device-file=$NOTE_DEVICE_FILE \ - --hash-map-device-file=$HASH_MAP_DEVICE_FILE --vmlinux=$VMLINUX \ - --map-file=$MAP_FILE --separate-samples=$SEPARATE_SAMPLES \ + + if test -f $LOCK_FILE; then + echo "lock file $LOCK_FILE still present." >&2 + exit 1 + fi + + OPD_ARGS="--vmlinux=$VMLINUX --map-file=$MAP_FILE \ + --separate-samples=$SEPARATE_SAMPLES \ --pid-filter=$PID_FILTER --pgrp-filter=$PGRP_FILTER" if [ "$VERBOSE" = "1" ]; then @@ -533,9 +494,8 @@ vecho "executing oprofiled $OPD_ARGS" oprofiled $OPD_ARGS - # FIXME: does not check child is up and running COUNT=0 - while test -z `pidof oprofiled` + while ! test -f "$DIR/lock" do sleep 1 COUNT=`expr $COUNT + 1` @@ -545,6 +505,7 @@ exit 1 fi done + echo "Daemon started. Remember you may need to use op_dump" echo "to retrieve profile data" } Index: op_stop =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/op_stop,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- op_stop 15 Jan 2002 00:57:21 -0000 1.17 +++ op_stop 2 May 2002 02:19:08 -0000 1.18 @@ -16,26 +16,26 @@ # Place - Suite 330, Boston, MA 02111-1307, USA. # -if test `pidof oprofiled` -then +# FIXME: support different base dir ?? + +if test -f /var/lib/oprofile/lock; then echo "Stopping profiling and killing daemon" - COUNT=0 - while test `pidof oprofiled` - do - sleep 1 - # we need this in here because we can send a dump_stop that gets missed - # when the daemon is just starting up - a better fix is a lockfile for - # "fully started up" - echo 1 >/proc/sys/dev/oprofile/dump_stop - COUNT=`expr $COUNT + 1` - if [ "$COUNT" -eq 30 ]; then - echo "Daemon stuck shutting down; killing !" - kill -9 `pidof oprofiled` - exit 0 - fi - done - exit 0 + echo 1 >/proc/sys/dev/oprofile/dump_stop fi + +COUNT=0 +while test `pidof oprofiled` +do + sleep 1 + + COUNT=`expr $COUNT + 1` + if [ "$COUNT" -eq 30 ]; then + echo "Daemon stuck shutting down; killing !" + kill -9 `pidof oprofiled` + rm -f /var/lib/oprofile/lock + exit 0 + fi +done # if profiler is not started consider as ok to try to stop it. exit 0 Index: opd_kernel.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/opd_kernel.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- opd_kernel.c 20 Mar 2002 21:19:42 -0000 1.6 +++ opd_kernel.c 2 May 2002 02:19:08 -0000 1.7 @@ -113,7 +113,7 @@ int i; for (i=0; i < OPD_MAX_MODULES; i++) { - if (opd_modules[i].name && bstreq(name,opd_modules[i].name)) { + if (opd_modules[i].name && bstreq(name, opd_modules[i].name)) { /* free this copy */ free(name); return &opd_modules[i]; Index: opd_proc.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/opd_proc.c,v retrieving revision 1.112 retrieving revision 1.113 diff -u -d -r1.112 -r1.113 --- opd_proc.c 1 May 2002 19:56:17 -0000 1.112 +++ opd_proc.c 2 May 2002 02:19:08 -0000 1.113 @@ -200,7 +200,7 @@ uint len; const char * app_name = separate_samples ? image->app_name : NULL; - mangled = opd_mangle_filename(smpdir, image->name, app_name); + mangled = opd_mangle_filename(image->name, app_name); len = strlen(mangled); @@ -307,7 +307,7 @@ */ static void opd_open_sample_file(struct opd_image *image, int counter) { - char* mangled; + char * mangled; struct opd_sample_file *sample_file; struct opd_header * header; const char * app_name; @@ -315,7 +315,7 @@ sample_file = &image->sample_files[counter]; app_name = separate_samples ? image->app_name : NULL; - mangled = opd_mangle_filename(smpdir, image->name, app_name); + mangled = opd_mangle_filename(image->name, app_name); sprintf(mangled + strlen(mangled), "#%d", counter); @@ -350,6 +350,31 @@ /** + * opd_reopen_sample_files - re-open all sample files + * + * In fact we just close them, and re-open them lazily + * as usual. + */ +void opd_reopen_sample_files(void) +{ + struct list_head * pos; + + list_for_each(pos, &opd_images) { + struct opd_image * image = + list_entry(pos, struct opd_image, list_node); + unsigned int i; + + for (i = 0 ; i < op_nr_counters ; ++i) { + struct opd_sample_file * samples = + &image->sample_files[i]; + + db_close(&samples->tree); + } + } +} + + +/** * opd_check_image_mtime - ensure samples file is up to date * @image: image to check */ @@ -368,7 +393,7 @@ "mtime %lu for %s\n", newmtime, image->mtime, image->name); app_name = separate_samples ? image->app_name : NULL; - mangled = opd_mangle_filename(smpdir, image->name, app_name); + mangled = opd_mangle_filename(image->name, app_name); len = strlen(mangled); Index: opd_proc.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/opd_proc.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- opd_proc.h 5 Jan 2002 02:40:57 -0000 1.1 +++ opd_proc.h 2 May 2002 02:19:08 -0000 1.2 @@ -31,5 +31,6 @@ int bstreq(const char *str1, const char *str2); void opd_put_image_sample(struct opd_image *image, u32 offset, u16 count); void opd_handle_kernel_sample(u32 eip, u16 count); +void opd_reopen_sample_files(void); #endif /* OPD_PROC_H */ Index: opd_util.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/opd_util.c,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- opd_util.c 20 Mar 2002 21:19:42 -0000 1.36 +++ opd_util.c 2 May 2002 02:19:08 -0000 1.37 @@ -24,33 +24,27 @@ /** * opd_mangle_filename - mangle a file filename - * @smpdir: base directory name * @image_name: a path name to the image file * @app_name: a path name for the owner image * of this image or %NULL if no owner exist * - * allocate memory of size strlen(@image_name) + - * strlen(@smpdir) + strlen(@app_name) + 2 + 32 then - * concat @smpdir and the mangled name of @filename - * and optionnally @app_name. The 32 bytes added are - * assumed to concat something like "#%d" - * - * Returns a char* pointer to the mangled string. + * Returns a char* pointer to the mangled string. Caller + * is respomsible for freeing this string. * */ -char* opd_mangle_filename(const char *smpdir, const char* image_name, const char * app_name) +char* opd_mangle_filename(const char * image_name, const char * app_name) { char *mangled; char *c; size_t len; - len = strlen(smpdir) + 2 + strlen(image_name) + 32; + len = strlen(OP_SAMPLES_DIR) + 2 + strlen(image_name) + 32; if (app_name) len += strlen(app_name) + 2; mangled = xmalloc(len); - strcpy(mangled, smpdir); + strcpy(mangled, OP_SAMPLES_DIR); strcat(mangled, "/"); c = mangled + strlen(mangled); @@ -257,7 +251,6 @@ */ u32 opd_read_int_from_file(const char *filename) { - FILE *fp; u32 value; @@ -498,3 +491,52 @@ return ret; } + +/** + * opd_read_lock_file - read a lock file + * + * Return the pid written in the given lock file, + * or 0 if it doesn't exist. + */ +pid_t opd_read_lock_file(const char * file) +{ + FILE * fp; + pid_t value; + + fp = fopen(file, "r"); + if (fp == NULL) + return 0; + + if (fscanf(fp, "%u", &value) != 1) { + fclose(fp); + return 0; + } + + fclose(fp); + + return value; +} + + +/** + * opd_write_lock_file - write a lock file + * \return errno on failure, or 0 on success + * + * Write the pid into the given lock file. + */ +int opd_write_lock_file(const char * file) +{ + FILE * fp; + + if (opd_get_fsize(file, 0) != 0) + return EEXIST; + + fp = fopen(file, "w"); + if (!fp) + return errno; + + fprintf(fp, "%d", getpid()); + fclose(fp); + + return 0; +} Index: opd_util.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/opd_util.h,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- opd_util.h 24 Apr 2002 17:59:30 -0000 1.26 +++ opd_util.h 2 May 2002 02:19:08 -0000 1.27 @@ -68,7 +68,7 @@ extern "C" { #endif -char* opd_mangle_filename(const char *smpdir, const char* filename, const char * app_name); +char* opd_mangle_filename(const char* filename, const char * app_name); #define opd_try_open_file(n,m) opd_do_open_file((n), (m), 0) #define opd_open_file(n,m) opd_do_open_file((n), (m), 1) @@ -93,6 +93,9 @@ ssize_t opd_read_device(fd_t devfd, void *buf, size_t size, int seek); off_t opd_get_fsize(const char *file, int fatal); time_t opd_get_mtime(const char *file); + +pid_t opd_read_lock_file(const char * file); +int opd_write_lock_file(const char * file); char *opd_get_time(void); char *opd_get_line(FILE *fp); Index: oprofiled.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/oprofiled.c,v retrieving revision 1.73 retrieving revision 1.74 diff -u -d -r1.73 -r1.74 --- oprofiled.c 1 May 2002 19:03:43 -0000 1.73 +++ oprofiled.c 2 May 2002 02:19:08 -0000 1.74 @@ -26,7 +26,6 @@ int verbose; op_cpu cpu_type; int separate_samples; -char *smpdir="/var/opd/samples/"; char *vmlinux; int kernel_only; unsigned long opd_stats[OPD_MAX_STATS] = { 0, }; @@ -39,11 +38,6 @@ static const char *cpu_speed_str; static int opd_buf_size=OP_DEFAULT_BUF_SIZE; static int opd_note_buf_size=OP_DEFAULT_NOTE_SIZE; -static char *opd_dir="/var/opd/"; -static char *logfilename="oprofiled.log"; -static char *devfilename="opdev"; -static char *notedevfilename="opnotedev"; -static char *devhashmapfilename="ophashmapdev"; static char *systemmapfilename; static pid_t mypid; static pid_t pid_filter; @@ -58,12 +52,6 @@ static struct poptOption options[] = { { "pid-filter", 0, POPT_ARG_INT, &pid_filter, 0, "only profile the given process ID", "pid" }, { "pgrp-filter", 0, POPT_ARG_INT, &pgrp_filter, 0, "only profile the given process group", "pgrp" }, - { "log-file", 'l', POPT_ARG_STRING, &logfilename, 0, "log file", "file", }, - { "base-dir", 'd', POPT_ARG_STRING, &opd_dir, 0, "base directory of daemon", "dir", }, - { "samples-dir", 's', POPT_ARG_STRING, &smpdir, 0, "output samples dir", "file", }, - { "device-file", 'd', POPT_ARG_STRING, &devfilename, 0, "profile device file", "file", }, - { "note-device-file", 'p', POPT_ARG_STRING, ¬edevfilename, 0, "note device file", "file", }, - { "hash-map-device-file", 'h', POPT_ARG_STRING, &devhashmapfilename, 0, "profile hashmap device file", "file", }, { "map-file", 'f', POPT_ARG_STRING, &systemmapfilename, 0, "System.map for running kernel file", "file", }, { "vmlinux", 'k', POPT_ARG_STRING, &vmlinux, 0, "vmlinux kernel image", "file", }, { "cpu-speed", 0, POPT_ARG_STRING, &cpu_speed_str, 0, "cpu speed (MHz)", "cpu_mhz", }, @@ -84,7 +72,7 @@ */ static void opd_open_logfile(void) { - if (open(logfilename, O_WRONLY|O_CREAT|O_NOCTTY|O_APPEND, 0755) == -1) { + if (open(OP_LOG_FILE, O_WRONLY|O_CREAT|O_NOCTTY|O_APPEND, 0755) == -1) { perror("oprofiled: couldn't re-open stdout: "); exit(EXIT_FAILURE); } @@ -106,46 +94,46 @@ { fd_t hashmapdevfd; - hashmapdevfd = opd_open_device(devhashmapfilename, 0); + hashmapdevfd = opd_open_device(OP_HASH_DEVICE, 0); if (hashmapdevfd == -1) { - perror("Failed to open hash map device: "); + perror("Failed to open hash map device"); exit(EXIT_FAILURE); } - notedevfd = opd_open_device(notedevfilename, 0); + notedevfd = opd_open_device(OP_NOTE_DEVICE, 0); if (notedevfd == -1) { if (errno == EINVAL) fprintf(stderr, "Failed to open note device. Possibly you have passed incorrect\n" "parameters. Check /var/log/messages."); else - perror("Failed to open note device: "); + perror("Failed to open note device"); exit(EXIT_FAILURE); } - devfd = opd_open_device(devfilename, 0); + devfd = opd_open_device(OP_DEVICE, 0); if (devfd == -1) { if (errno == EINVAL) fprintf(stderr, "Failed to open device. Possibly you have passed incorrect\n" "parameters. Check /var/log/messages."); else - perror("Failed to open profile device: "); + perror("Failed to open profile device"); exit(EXIT_FAILURE); } hashmap = mmap(0, OP_HASH_MAP_SIZE, PROT_READ, MAP_SHARED, hashmapdevfd, 0); if ((long)hashmap == -1) { - perror("oprofiled: couldn't mmap hash map: "); + perror("oprofiled: couldn't mmap hash map"); exit(EXIT_FAILURE); } /* give output before re-opening stdout as the logfile */ - printf("Using log file \"%s\"\n", logfilename); + printf("Using log file " OP_LOG_FILE "\n"); /* set up logfile */ close(0); close(1); - if (open("/dev/null",O_RDONLY) == -1) { + if (open("/dev/null", O_RDONLY) == -1) { perror("oprofiled: couldn't re-open stdin as /dev/null: "); exit(EXIT_FAILURE); } @@ -160,8 +148,8 @@ /** * opd_backup_samples_files - back up all the samples file * - * move all files in dir @smpdir to directory - * @smpdir/session-#nr + * move all files in samples dir to sub-directory + * session-#nr/ */ static void opd_backup_samples_files(void) { @@ -171,11 +159,11 @@ DIR *dir; struct dirent *dirent; - dir_name = xmalloc(strlen(smpdir) + strlen("session-") + 10); - strcpy(dir_name, smpdir); + dir_name = xmalloc(strlen(OP_SAMPLES_DIR) + strlen("session-") + 10); + strcpy(dir_name, OP_SAMPLES_DIR); do { - sprintf(dir_name + strlen(smpdir), "/session-%d", ++gen); + sprintf(dir_name + strlen(OP_SAMPLES_DIR), "/session-%d", ++gen); } while (stat(dir_name, &stat_buf) == 0); if (mkdir(dir_name, 0755)) { @@ -185,17 +173,17 @@ exit(EXIT_FAILURE); } - if (!(dir = opendir(smpdir))) { - printf("unable to open directory %s\n", smpdir); + if (!(dir = opendir(OP_SAMPLES_DIR))) { + printf("unable to open directory " OP_SAMPLES_DIR "\n"); exit(EXIT_FAILURE); } printf("Backing up samples file to directory %s\n", dir_name); while ((dirent = readdir(dir)) != 0) { - if (opd_move_regular_file(dir_name, smpdir, dirent->d_name)) { + if (opd_move_regular_file(dir_name, OP_SAMPLES_DIR, dirent->d_name)) { printf("unable to backup %s/%s to directory %s\n", - smpdir, dirent->d_name, dir_name); + OP_SAMPLES_DIR, dirent->d_name, dir_name); } } @@ -225,9 +213,8 @@ int counter_set, old_counter_set; uint i; - if (!(dir = opendir(smpdir))) { - printf("unable to open directory %s\n", smpdir); - + if (!(dir = opendir(OP_SAMPLES_DIR))) { + printf("unable to open directory " OP_SAMPLES_DIR "\n"); exit(EXIT_FAILURE); } @@ -235,9 +222,8 @@ need_backup = 0; while ((dirent = readdir(dir)) != 0 && need_backup == 0) { - char * file = xmalloc(strlen(smpdir) + strlen(dirent->d_name) + 2); - strcpy(file, smpdir); - strcat(file, "/"); + char * file = xmalloc(strlen(OP_SAMPLES_DIR) + strlen(dirent->d_name) + 2); + strcpy(file, OP_SAMPLES_DIR); strcat(file, dirent->d_name); if (!stat(file, &stat_buf) && S_ISREG(stat_buf.st_mode)) { struct opd_header header; @@ -430,8 +416,9 @@ { opd_fork(); - if (chdir(opd_dir)) { - fprintf(stderr,"oprofiled: opd_go_daemon: couldn't chdir to %s: %s", opd_dir, strerror(errno)); + if (chdir(OP_BASE_DIR)) { + fprintf(stderr,"oprofiled: opd_go_daemon: couldn't chdir to " + OP_BASE_DIR ": %s", strerror(errno)); exit(EXIT_FAILURE); } @@ -593,7 +580,7 @@ * to the relevant sample file. Additionally mapping and * process notifications are handled here. */ -void opd_do_samples(const struct op_sample *opd_buf, size_t count) +void opd_do_samples(const struct op_sample * opd_buf, size_t count) { uint i; @@ -603,10 +590,12 @@ opd_stats[OPD_DUMP_COUNT]++; for (i=0; i < count/sizeof(struct op_sample); i++) { - verbprintf("%.6u: EIP: 0x%.8x pid: %.6d count: %.6d\n", i, opd_buf[i].eip, opd_buf[i].pid, opd_buf[i].count); + verbprintf("%.6u: EIP: 0x%.8x pid: %.6d count: %.6d\n", + i, opd_buf[i].eip, opd_buf[i].pid, opd_buf[i].count); - // happens during initial startup whilst the - // hash table is being filled + /* happens during initial startup whilst the + * hash table is being filled + */ if (opd_buf[i].eip == 0) continue; @@ -627,8 +616,16 @@ close(1); close(2); opd_open_logfile(); + opd_reopen_sample_files(); } + +static void clean_exit(void) +{ + unlink(OP_LOCK_FILE); +} + + int main(int argc, char const *argv[]) { struct op_sample *sbuf; @@ -649,6 +646,12 @@ opd_init_images(); + if (atexit(clean_exit)) { + fprintf(stderr, "Couldn't set exit cleanup !\n"); + unlink(OP_LOCK_FILE); + exit(EXIT_FAILURE); + } + opd_go_daemon(); if (opd_need_backup_samples_files()) { @@ -690,6 +693,13 @@ /* clean up every 10 minutes */ alarm(60*10); + if (opd_write_lock_file(OP_LOCK_FILE)) { + fprintf(stderr, + "oprofiled: could not create lock file " + OP_LOCK_FILE "\n"); + exit(EXIT_FAILURE); + } + /* simple sleep-then-process loop */ opd_do_read(sbuf, s_buf_bytesize, nbuf, n_buf_bytesize); Index: oprofiled.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/oprofiled.h,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- oprofiled.h 24 Apr 2002 17:59:30 -0000 1.44 +++ oprofiled.h 2 May 2002 02:19:09 -0000 1.45 @@ -77,7 +77,6 @@ extern int kernel_only; extern op_cpu cpu_type; extern int separate_samples; -extern char * smpdir; extern char * vmlinux; extern unsigned long opd_stats[]; |