Changeset 1418

Show
Ignore:
Timestamp:
10/14/07 13:53:29 (1 year ago)
Author:
till
Message:

nebula
- throughput profiling
- clean configure script

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nebula/trunk/ChangeLog

    r1416 r1418  
     1- throughput profiling 
     2- clean configure script 
    13- process input from directory chronologically when -t is given 
    24- fixed sized queues for outlier list and cluster elements; size can be set via command line options 
  • nebula/trunk/configure.in

    r1373 r1418  
    11# $Id$  
    22AC_PREREQ(02.50) 
    3 AC_INIT([cluster], [0.0.1], [tillmann.werner@gmx.de]) 
     3AC_INIT([nebula], [0.0.1], [tillmann.werner@gmx.de]) 
    44AM_CONFIG_HEADER(config.h) 
    5 AM_INIT_AUTOMAKE(cluster,0.0.1) 
     5AM_INIT_AUTOMAKE(nebula,0.0.1) 
    66 
    7 # Since we get -O2 from configure defaults, which doesn't work in 64bit 
    8 # mode, let's make some changes here before calling _CC macros. 
    9 AC_ARG_ENABLE(64bit-gcc, 
    10 [  --enable-64bit-gcc      try to compile 64bit (only tested on Sparc Solaris 9).], 
    11                 [ CFLAGS="-O0 -g" CC="gcc -m64"; export CFLAGS CC ],) 
    12 # Disable annoying practice of recursively re-running the autotools 
    13 AM_MAINTAINER_MODE 
    14 AM_PROG_CC_STDC 
    157AC_PROG_CC 
    16 #AC_PROG_LD(gnu-ld) 
    17 #AC_PROG_LIBTOOL 
    18  if test -n "$GCC"; then 
    19       CFLAGS="$CFLAGS -Wall" 
    20  fi 
    218 
    229AC_ARG_ENABLE(debug, 
    2310[  --enable-debug          enable debugging options (bugreports and developers only)], 
    24                 [ if test -n "$GCC"; then 
    25                     CFLAGS="-O0 -DDEBUG -g" 
    26                   else 
    27                     CFLAGS="$CFLAGS -DDEBUG" 
    28                   fi       
    29                  enable_debug="X" 
    30                 ], enable_debug=" ") 
     11       [ if test -n "$GCC"; then 
     12               CFLAGS="-O0 -DDEBUG -g" 
     13       else 
     14               CFLAGS="$CFLAGS -DDEBUG" 
     15        fi 
     16        enable_debug="X"], enable_debug=" ") 
     17 
    3118 
    3219AC_ARG_ENABLE(profile, 
    3320[  --enable-profile        enable profiling options (developers only)], 
    34         [ if test -n "$GCC"; then 
    35             CFLAGS="$CFLAGS -DPROFILE -pg" 
    36           else 
    37             CFLAGS="$CFLAGS -DPROFILE" 
    38           fi 
    39           enable_profile="X" 
    40         ], enable_profile=" ") 
    41  
    42 #AC_CANONICAL_HOST 
    43 linux=no 
    44 sunos4=no 
    45  
    46 AC_C_BIGENDIAN 
    47 SHELL="/bin/sh" 
    48  
    49 case "$host" in 
    50   *-openbsd2.6|*-openbsd2.5|*-openbsd2.4|*-openbsd2.3*) 
    51     AC_DEFINE(OPENBSD,,[Define if OPENBSD]) 
    52     AC_DEFINE(BROKEN_SIOCGIFMTU,,[Define if BROKEN_SIOCGIFMTU]) 
    53  
    54     ;; 
    55   *-openbsd*) 
    56     AC_DEFINE(OPENBSD) 
    57  
    58     ;; 
    59   *-sgi-irix5*) 
    60     AC_DEFINE(IRIX,,[Define if IRIX]) 
    61     no_libsocket=yes 
    62     no_libnsl=yes 
    63     if test -z "$GCC"; then 
    64       sgi_cc=yes 
    65     fi 
    66     LDFLAGS=${LDFLAGS} -L/usr/local/lib 
    67     extra_incl=-I/usr/local/include 
    68     ;; 
    69   *-sgi-irix6*) 
    70     AC_DEFINE(IRIX) 
    71     no_libsocket=yes 
    72     no_libnsl=yes 
    73     if test -z "$GCC"; then 
    74       sgi_cc=yes 
    75     fi 
    76     LDFLAGS=${LDFLAGS} -L/usr/local/lib 
    77     extra_incl=-I/usr/local/include 
    78     ;; 
    79   *-solaris*) 
    80     AC_DEFINE(SOLARIS,,[Define if SOLARIS]) 
    81     CPPFLAGS="${CPPFLAGS} -DBSD_COMP -D_REENTRANT" 
    82     ;; 
    83   *-sunos*) 
    84     AC_DEFINE(SUNOS,,[Define if SUNOS]) 
    85     sunos4=yes 
    86     ;; 
    87   *-linux*) 
    88     linux=yes 
    89     AC_DEFINE(LINUX,,[Define if LINUX]) 
    90     # libpcap doesn't even LOOK at the timeout you give it under Linux 
    91        AC_DEFINE(PCAP_TIMEOUT_IGNORED,,[Define if PCAP_TIMEOUT_IGNORED]) 
    92     AC_SUBST(extra_incl) 
    93     extra_incl=-I/usr/include/pcap 
    94     ;; 
    95   *-hpux10*) 
    96     AC_DEFINE(HPUX,,[Define if HPUX]) 
    97     AC_DEFINE(WORDS_BIGENDIAN) 
    98     AC_SUBST(extra_incl) 
    99     extra_incl=-I/usr/local/include 
    100     ;; 
    101  
    102   *-freebsd*) 
    103     AC_DEFINE(FREEBSD,,[Define if FREEBSD]) 
    104     CFLAGS="$CFLAGS -fPIC -DPIC" 
    105  
    106     ;; 
    107   *-bsdi*) 
    108     AC_DEFINE(BSDI,,[Define if BSDI]) 
    109     ;; 
    110   *-aix*) 
    111     AC_DEFINE(AIX,,[Define if AIX]) 
    112      broken_types=yes 
    113     ;; 
    114   *-osf4*) 
    115     AC_DEFINE(OSF1,,[Define if OSF1]) 
    116     tru64_types=yes 
    117     ;; 
    118   *-osf5.1*) 
    119     AC_DEFINE(OSF1) 
    120     ;; 
    121   *-tru64*) 
    122     AC_DEFINE(OSF1) 
    123     tru64_types=yes 
    124     ;; 
    125 # it is actually <platform>-apple-darwin1.2 or <platform>-apple-rhapsody5.x but lets stick with this for the moment     
    126   *-apple*) 
    127     AC_DEFINE(MACOS,,[Define if MACOS]) 
    128     AC_DEFINE(BROKEN_SIOCGIFMTU) 
    129     LDFLAGS="${LDFLAGS} -L/sw/lib" 
    130     extra_incl=-I/sw/include 
    131 esac 
    132  
    133 # any sparc platform has to have this one defined. 
    134 AC_MSG_CHECKING(for sparc alignment) 
    135 if eval "echo $host_cpu|grep -i sparc >/dev/null"; then 
    136      AC_DEFINE(WORDS_MUSTALIGN,,[Define if WORDS_MUSTALIGN]) 
    137      AC_MSG_RESULT(yes) 
    138 else 
    139      AC_MSG_RESULT(no) 
    140 fi 
    141  
    142  
    143 LIBS="${LIBS}" 
    144  
    145 AC_TRY_COMPILE([ 
    146 #include <stdio.h> 
    147 ],[char *foo; foo = sys_errlist[0];],  
    148 AC_DEFINE(ERRLIST_PREDEFINED,,[Define if ERRLIST_PREDEFINED])) 
    149  
    150 AC_MSG_CHECKING(for __FUNCTION__) 
    151 AC_TRY_COMPILE([ 
    152 #include <stdio.h> 
    153 ],[printf ("%s", __FUNCTION__);], 
    154 sn_cv_have___FUNCTION__=yes, sn_cv__have___FUNCTION__=no) 
    155 if test "x$sn_cv_have___FUNCTION__" = "xyes"; then 
    156    AC_MSG_RESULT(yes) 
    157    AC_DEFINE(HAVE___FUNCTION__, 1, 
    158              [Define if the compiler understands __FUNCTION__.]) 
    159 else 
    160    AC_MSG_RESULT(no) 
    161    AC_MSG_CHECKING(for __func__) 
    162    AC_TRY_COMPILE([ 
    163 #include <stdio.h> 
    164 ],[printf ("%s", __func__);], 
    165 sn_cv_have___func__=yes, sn_cv__have___func__=no) 
    166    if test "x$sn_cv_have___func__" = "xyes"; then 
    167       AC_MSG_RESULT(yes) 
    168       AC_DEFINE(HAVE___func__, 1, 
    169                 [Define if the compiler understands __func__.]) 
    170       AC_DEFINE(__FUNCTION__, __func__, [Define __FUNCTION__ as required.]) 
    171    else 
    172       AC_MSG_RESULT(no) 
    173       AC_DEFINE(__FUNCTION__, "mystery function") 
    174    fi 
    175 fi 
     21        [ if test -n "$GCC"; then 
     22                CFLAGS="$CFLAGS -DPROFILE -pg" 
     23        else 
     24                CFLAGS="$CFLAGS -DPROFILE" 
     25        fi 
     26        enable_profile="X"], enable_profile=" ") 
    17627 
    17728 
    17829# Check for electric fence malloc debugger 
    179 AC_ARG_WITH(efence, [  --with-efence           link with electric fence ]) 
    180 if test "$with_efence" = "yes" 
    181 then 
    182         with_efence="X" 
    183         AC_CHECK_LIB(efence, EF_ALIGNMENT, LIBS="${LIBS} -lefence", AC_MSG_ERROR(libefence not found)) 
    184 else 
    185         with_efence=" " 
    186 fi 
    187  
    188  
    189 # let's make some fixes.. 
    190  
    191 CFLAGS=`echo $CFLAGS |sed -e 's/-I\/usr\/include //g'` 
    192 CPPFLAGS=`echo $CPPFLAGS | sed -e 's/-I\/usr\/include //g'` 
    193  
    194 INCLUDES='-I$(top_srcdir) -I$(top_srcdir)/src' 
    195  
    196 AC_SUBST(INCLUDES) 
     30AC_ARG_ENABLE(efence, 
     31[  --enable-efence       link with electric fence], enable_efence="X", enable_efence=" ") 
     32        if test "$enable_efence" = "X"; then 
     33                AC_CHECK_LIB(efence, EF_ALIGNMENT, LIBS="${LIBS} -lefence", AC_MSG_ERROR(libefence not found)) 
     34        fi 
    19735 
    19836 
  • nebula/trunk/src/Makefile.am

    r1414 r1418  
    11AM_CFLAGS=-Wall -Werror 
    22 
    3 LIBS=-lm 
     3LIBS += -lm 
    44 
    55bin_PROGRAMS = nebula 
  • nebula/trunk/src/nebula.c

    r1416 r1418  
    3232#include <unistd.h> 
    3333 
     34#if HAVE_CONFIG_H 
     35//#include <config.h> 
     36#endif 
     37 
    3438#include "cluster.h" 
    3539#include "md5.h" 
     
    4044#include "util.h" 
    4145 
     46#ifndef VERSION 
     47#define VERSION "(unknown version)" 
     48#endif 
     49 
    4250 
    4351void usage(const char* progname, const int exit_val) { 
    44         printf("Usage: %s [-l] [-v] [-r cluster radius] [-d directory] [file ...]\n", progname); 
     52#ifdef PROFILE 
     53        printf("Usage: %s [-ltpv] [-c maximum cluster size] [-r cluster radius] [-q maximum outlier queue size] [-d directory] [file ...]\n", progname); 
     54#else 
     55        printf("Usage: %s [-ltpv] [-a profiling interval] [-c maximum cluster size] [-r cluster radius] [-q maximum outlier queue size] [-d directory] [file ...]\n", progname); 
     56#endif 
    4557 
    4658        exit(exit_val); 
     
    4860 
    4961int main(int argc, char *argv[]) { 
    50         int             i, qsize, show_progress
     62        int             i, qsize
    5163        u_char          time_sort, *content, *tmpbuf; 
    5264        char            option, *dirname; 
     
    7284        qsize           = 0; 
    7385        total_files     = 0; 
     86#ifdef PROFILE 
     87        alarm_time      = 5; 
     88#endif 
    7489 
    7590        /* default values for parameters */ 
     
    85100        memset(&spamsum_trie, 0, sizeof(trie_node)); 
    86101 
     102        printf("\n  Nebula %s Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de>\n\n", VERSION); 
     103 
    87104        // process args 
     105#ifdef PROFILE 
     106        while((option = getopt(argc, argv, "c:q:a:tplvd:r:h?")) > 0) { 
     107#else 
    88108        while((option = getopt(argc, argv, "c:q:tplvd:r:h?")) > 0) { 
     109#endif 
    89110                switch(option) { 
     111#ifdef PROFILE 
     112                        case 'a': 
     113                                alarm_time = atoi(optarg); 
     114                                if (alarm_time < 1) { 
     115                                        fprintf(stderr, "Error - Profile time interval must be at least one second.\n"); 
     116                                        exit(EXIT_FAILURE); 
     117                                } 
     118                                break; 
     119#endif 
    90120                        case 'c': 
    91121                                clusterq_max = atoi(optarg); 
     
    137167        set_signal_handlers(); 
    138168 
    139         /* initialize outlier queue */ 
    140         outlierq = hashq_new(); 
    141  
     169 
     170        // if a directory is given, scan (and sort) its content 
    142171        if (dirname) { 
    143                 printf("scanning directory... "); 
     172                printf("Scanning directory... "); 
    144173                fflush(stdout); 
    145174                if (time_sort) { 
     
    162191        } 
    163192 
     193        // initialize outlier queue 
     194        outlierq = hashq_new(); 
     195 
     196 
     197#ifdef PROFILE 
     198        alarm(alarm_time); 
     199        printf("Profiling enabled, printing statistics every %d seconds.\n", alarm_time); 
     200        files_in_interval = 0; 
     201        checkpoint = 0; 
     202#endif 
    164203 
    165204        printf("processing %u files.\n", (unsigned int) total_files); 
     
    169208        } 
    170209 
     210 
    171211        for (n=0; n<total_files; n++) { 
    172212                bstr = bstr_map(namelist[n]->d_name); 
    173213                num_of_files++; 
     214#ifdef PROFILE 
     215                files_in_interval++; 
     216#endif 
    174217 
    175218                if (verbose) printf("  processing file %s.\n", namelist[n]->d_name); 
    176219                else if (show_progress) { 
    177                         printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); 
     220                        printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); 
    178221                        if (num_of_files < total_files) 
    179                                 printf("%05.2f%% (%04d clusters)", num_of_files/total_files*100, num_of_clusters); 
     222                                printf("files processed: %05.2f%% (%04d clusters)", num_of_files/total_files*100, num_of_clusters); 
    180223                        else 
    181                                 printf("100.00%% (%04d clusters)\n", num_of_clusters); 
     224                                printf("files processed: 100.00%% (%04d clusters)\n", num_of_clusters); 
    182225                        fflush(stdout); 
    183226                } 
  • nebula/trunk/src/nebula.h

    r1416 r1418  
    3131#include "hashq.h" 
    3232 
    33 u_char          verbose, list_files
     33u_char          verbose, list_files, show_progress
    3434int             clusterq_max, outlierq_max;  
    3535u_int16_t       num_of_clusters; 
     
    4040hashq           *outlierq; 
    4141 
     42#ifdef PROFILE 
     43int             alarm_time;     // number of seconds for profile output interval 
     44float           files_in_interval; 
     45u_int32_t       checkpoint; 
    4246#endif 
     47 
     48#endif 
  • nebula/trunk/src/signals.c

    r1414 r1418  
    2323#include <stdlib.h> 
    2424#include <string.h> 
     25#include <unistd.h> 
    2526 
    2627#include "nebula.h" 
     
    2930 
    3031 
    31 void handle_signal(int sig) { 
     32void handle_term_signal(int sig) { 
    3233        printf("Premature termination forced (signal %d caught).\n", sig); 
     34 
    3335        cleanup(); 
    3436        exit(EXIT_SUCCESS); 
     
    3739 
    3840 
     41#ifdef PROFILE 
     42void handle_alarm_signal(int sig) { 
     43        if (show_progress) printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\n"); 
     44        printf("%u: %u files form %u clusters (%.0f files per second).\n", 
     45                checkpoint, (unsigned int) num_of_files, num_of_clusters, files_in_interval/alarm_time); 
     46 
     47        checkpoint++; 
     48        files_in_interval = 0; 
     49        alarm(alarm_time); 
     50 
     51        return; 
     52} 
     53#endif 
     54 
     55 
    3956void set_signal_handlers(void) { 
    4057        u_char                  i; 
    4158        struct sigaction        s_action; 
    42         static int              sigs[] = { 
     59        static int              termsigs[] = { 
    4360#ifdef HAVE_SIGBUS 
    4461                SIGBUS, 
     
    5269        }; 
    5370 
    54         /* install signal handlers */ 
     71        // install handler for signals indicating errors 
    5572        memset(&s_action, 0, sizeof(struct sigaction)); 
    56         s_action.sa_handler     = handle_signal; 
     73        s_action.sa_handler     = handle_term_signal; 
    5774#ifdef SA_RESTART 
    5875        s_action.sa_flags       |= SA_RESTART; 
    5976#endif 
    60         for (i = 0; i < sizeof(sigs)/sizeof(sigs[0]); i++) { 
    61                 if (sigaction(sigs[i], &s_action, NULL) == -1) { 
    62                         fprintf(stdout, "  Error - Unable to install handler for signal %d: %m.\n", sigs[i]); 
     77        for (i = 0; i < sizeof(termsigs)/sizeof(termsigs[0]); i++) { 
     78                if (sigaction(termsigs[i], &s_action, NULL) == -1) { 
     79                        fprintf(stdout, "  Error - Unable to install handler for signal %d: %m.\n", termsigs[i]); 
    6380                        exit(EXIT_FAILURE); 
    6481                } 
    6582        } 
     83 
     84#ifdef PROFILE 
     85        // install handler for SIGALARM 
     86        memset(&s_action, 0, sizeof(struct sigaction)); 
     87        s_action.sa_handler     = handle_alarm_signal; 
     88#ifdef SA_RESTART 
     89        s_action.sa_flags       |= SA_RESTART; 
     90#endif 
     91        if (sigaction(SIGALRM, &s_action, NULL) == -1) { 
     92                fprintf(stdout, "  Error - Unable to install handler for signal %d: %m.\n", SIGALRM); 
     93                exit(EXIT_FAILURE); 
     94        } 
     95#endif 
     96 
    6697        return; 
    6798} 
  • nebula/trunk/src/signals.h

    r1376 r1418  
    2727 
    2828 
    29 void handle_signal(int sig); 
     29void handle_term_signal(int sig); 
     30#ifdef PROFILE 
     31void handle_alarm_signal(int sig); 
     32#endif 
    3033void set_signal_handlers(void); 
    3134 
  • nebula/trunk/src/util.c

    r1415 r1418  
    2121#include <dirent.h> 
    2222#include <fcntl.h> 
     23#include <signal.h> 
    2324#include <stdlib.h> 
    2425#include <stdio.h> 
     
    3132#include "hashq.h" 
    3233#include "nebula.h" 
     34#include "signals.h" 
    3335#include "trie.h" 
    3436#include "util.h" 
     37 
    3538 
    3639bstring bstr_map(const char* filename) { 
     
    103106        } 
    104107 
    105         if (sta.st_ctime < stb.st_ctime) return(1); 
    106         if (sta.st_ctime > stb.st_ctime) return(-1); 
     108        if (sta.st_ctime < stb.st_ctime) return(-1); 
     109        if (sta.st_ctime > stb.st_ctime) return(1); 
    107110        return(0); 
    108111} 
     
    110113 
    111114void cleanup(void) { 
     115        struct sigaction        s_action; 
     116 
     117#ifdef PROFILE 
     118        // reset handler for SIGALRM 
     119        memset(&s_action, 0, sizeof(struct sigaction)); 
     120        s_action.sa_handler     = NULL; 
     121#ifdef SA_RESTART 
     122        s_action.sa_flags       |= SA_RESTART; 
     123#endif 
     124        if (sigaction(SIGALRM, &s_action, NULL) == -1) { 
     125                fprintf(stdout, "  Error - Unable to reset handler for signal %d: %m.\n", SIGALRM); 
     126                exit(EXIT_FAILURE); 
     127        } 
     128#endif 
     129 
    112130        // free data structures 
    113131        printf("%u files form %u clustes.\n-----------------------\n", (unsigned int) num_of_files, num_of_clusters);