/[svn]/linuxsampler/trunk/src/linuxsampler.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/linuxsampler.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1765 by persson, Sat Sep 6 16:44:42 2008 UTC revision 1908 by persson, Mon Jun 1 18:50:06 2009 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2004 by Benno Senoner and Christian Schoenebeck    *   *   Copyright (C) 2003-2004 by Benno Senoner and Christian Schoenebeck    *
6   *   Copyright (C) 2005-2008 Christian Schoenebeck                         *   *   Copyright (C) 2005-2009 Christian Schoenebeck                         *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 23  Line 23 
23    
24  #include <getopt.h>  #include <getopt.h>
25  #include <signal.h>  #include <signal.h>
26    #include <sys/stat.h>
27    
28  #if defined(WIN32)  #if defined(WIN32)
29  // require at least Windows 2000 for the GlobalMemoryStatusEx() call  // require at least Windows 2000 for the GlobalMemoryStatusEx() call
30    #if _WIN32_WINNT < 0x0500
31    #ifdef _WIN32_WINNT
32    #undef _WIN32_WINNT
33    #endif
34  #define _WIN32_WINNT 0x0500  #define _WIN32_WINNT 0x0500
35  #endif  #endif
36    #endif
37    
38  #include "Sampler.h"  #include "Sampler.h"
39  #include "common/global_private.h"  #include "common/global_private.h"
# Line 63  pid_t       main_pid; Line 69  pid_t       main_pid;
69  bool bPrintStatistics = false;  bool bPrintStatistics = false;
70  bool profile = false;  bool profile = false;
71  bool tune = true;  bool tune = true;
72    static bool bShowStackTrace = false;
73  unsigned long int lscp_addr;  unsigned long int lscp_addr;
74  unsigned short int lscp_port;  unsigned short int lscp_port;
75    
# Line 73  static atomic_t running = ATOMIC_INIT(1) Line 80  static atomic_t running = ATOMIC_INIT(1)
80    
81  int main(int argc, char **argv) {  int main(int argc, char **argv) {
82    
83        lscp_addr = htonl(LSCP_ADDR);
84        lscp_port = htons(LSCP_PORT);
85    
86        #if !defined(WIN32)
87        main_pid = getpid();
88        #endif
89    
90        // parse and assign command line options
91        parse_options(argc, argv);
92    
93        // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
94        signal(SIGINT, signal_handler);
95    
96      // initialize the stack trace mechanism with our binary file      // initialize the stack trace mechanism with our binary file
97      StackTraceInit(argv[0], -1);      // (if requested by command line option)
98        if (bShowStackTrace) {
99            #if defined(WIN32)
100            // FIXME: sigaction() not supported on WIN32, we ignore it for now
101            #else
102            StackTraceInit(argv[0], -1);
103            // register signal handler for all unusual signals
104            // (we will print the stack trace and exit)
105            struct sigaction sact;
106            sigemptyset(&sact.sa_mask);
107            sact.sa_flags   = 0;
108            sact.sa_handler = signal_handler;
109            sigaction(SIGSEGV, &sact, NULL);
110            sigaction(SIGBUS,  &sact, NULL);
111            sigaction(SIGILL,  &sact, NULL);
112            sigaction(SIGFPE,  &sact, NULL);
113            sigaction(SIGUSR1, &sact, NULL);
114            sigaction(SIGUSR2, &sact, NULL);
115            #endif
116        }
117    
118        dmsg(1,("LinuxSampler %s\n", VERSION));
119        dmsg(1,("Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck\n"));
120        dmsg(1,("Copyright (C) 2005-2009 Christian Schoenebeck\n"));
121    
122      #if defined(WIN32)      #if defined(WIN32)
123        #if 0
124      // some WIN32 memory info code which tries to determine the maximum lockable amount of memory (for debug purposes)      // some WIN32 memory info code which tries to determine the maximum lockable amount of memory (for debug purposes)
125      SYSTEM_INFO siSysInfo;      SYSTEM_INFO siSysInfo;
126      long physical_memory;      long physical_memory;
127      GetSystemInfo(&siSysInfo);      GetSystemInfo(&siSysInfo);
128      dmsg(1,("page size=%d\n", siSysInfo.dwPageSize));      dmsg(2,("page size=%d\n", siSysInfo.dwPageSize));
129    
130      MEMORYSTATUSEX statex;      MEMORYSTATUSEX statex;
131          statex.dwLength = sizeof (statex);          statex.dwLength = sizeof (statex);
132      GlobalMemoryStatusEx (&statex);      GlobalMemoryStatusEx (&statex);
133      dmsg(1, ("There are %*I64d total Kbytes of physical memory.\n",      dmsg(2, ("There are %*I64d total Kbytes of physical memory.\n",
134            8, statex.ullTotalPhys));            8, statex.ullTotalPhys));
135      dmsg(1, ("There are %*I64d free Kbytes of physical memory.\n",      dmsg(2, ("There are %*I64d free Kbytes of physical memory.\n",
136            8, statex.ullAvailPhys));            8, statex.ullAvailPhys));
137      physical_memory = statex.ullTotalPhys;      physical_memory = statex.ullTotalPhys;
138    
# Line 121  int main(int argc, char **argv) { Line 165  int main(int argc, char **argv) {
165          if(RequestedMinimumWorkingSetSize < DefaultMinimumWorkingSetSize) break;          if(RequestedMinimumWorkingSetSize < DefaultMinimumWorkingSetSize) break;
166      }      }
167    
168      dmsg(1,("AFTER GetProcessWorkingSetSize: res = %d  MinimumWorkingSetSize=%d, MaximumWorkingSetSize=%d\n", res,MinimumWorkingSetSize, MaximumWorkingSetSize));      dmsg(2,("AFTER GetProcessWorkingSetSize: res = %d  MinimumWorkingSetSize=%d, MaximumWorkingSetSize=%d\n", res,MinimumWorkingSetSize, MaximumWorkingSetSize));
169      #endif      #endif
170        #endif // WIN32
     #if !defined(WIN32)  
     main_pid = getpid();  
     #endif  
   
     // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)  
     signal(SIGINT, signal_handler);  
   
     #if defined(WIN32)  
     // FIXME: sigaction() not supported on WIN32, we ignore it for now  
     #else  
     // register signal handler for all unusual signals  
     // (we will print the stack trace and exit)  
     struct sigaction sact;  
     sigemptyset(&sact.sa_mask);  
     sact.sa_flags   = 0;  
     sact.sa_handler = signal_handler;  
     sigaction(SIGSEGV, &sact, NULL);  
     sigaction(SIGBUS,  &sact, NULL);  
     sigaction(SIGILL,  &sact, NULL);  
     sigaction(SIGFPE,  &sact, NULL);  
     sigaction(SIGUSR1, &sact, NULL);  
     sigaction(SIGUSR2, &sact, NULL);  
     #endif  
   
     lscp_addr = htonl(LSCP_ADDR);  
     lscp_port = htons(LSCP_PORT);  
   
     // parse and assign command line options  
     parse_options(argc, argv);  
   
     dmsg(1,("LinuxSampler %s\n", VERSION));  
     dmsg(1,("Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck\n"));  
     dmsg(1,("Copyright (C) 2005-2008 Christian Schoenebeck\n"));  
171    
172      if (tune) {      if (tune) {
173          // detect and print system / CPU specific features          // detect and print system / CPU specific features
# Line 166  int main(int argc, char **argv) { Line 177  int main(int argc, char **argv) {
177          Features::enableDenormalsAreZeroMode();          Features::enableDenormalsAreZeroMode();
178      }      }
179    
180        dmsg(1,("Automatic Stacktrace: %s\n", (bShowStackTrace) ? "On" : "Off"));
181    
182      // create LinuxSampler instance      // create LinuxSampler instance
183      dmsg(1,("Creating Sampler..."));      dmsg(1,("Creating Sampler..."));
184      pSampler = new Sampler;      pSampler = new Sampler;
# Line 266  void signal_handler(int iSignal) { Line 279  void signal_handler(int iSignal) {
279          }          }
280      }      }
281      signal(iSignal, SIG_DFL); // Reinstall default handler to prevent race conditions      signal(iSignal, SIG_DFL); // Reinstall default handler to prevent race conditions
282      std::cerr << "Showing stack trace...\n" << std::flush;      if (bShowStackTrace) {
283      StackTrace();          std::cerr << "Showing stack trace...\n" << std::flush;
284      sleep(2);          StackTrace();
285            sleep(2);
286        }
287      std::cerr << "Killing LinuxSampler...\n" << std::flush;      std::cerr << "Killing LinuxSampler...\n" << std::flush;
288      kill_app(); // Use abort() if we want to generate a core dump.      kill_app(); // Use abort() if we want to generate a core dump.
289  }  }
# Line 296  void parse_options(int argc, char **argv Line 311  void parse_options(int argc, char **argv
311              {"create-instruments-db",1,0,0},              {"create-instruments-db",1,0,0},
312              {"lscp-addr",1,0,0},              {"lscp-addr",1,0,0},
313              {"lscp-port",1,0,0},              {"lscp-port",1,0,0},
314                {"stacktrace",0,0,0},
315              {0,0,0,0}              {0,0,0,0}
316          };          };
317    
# Line 319  void parse_options(int argc, char **argv Line 335  void parse_options(int argc, char **argv
335                      printf("--lscp-port                 set LSCP port (default: 8888)\n");                      printf("--lscp-port                 set LSCP port (default: 8888)\n");
336                      printf("--create-instruments-db     creates an instruments DB\n");                      printf("--create-instruments-db     creates an instruments DB\n");
337                      printf("--instruments-db-location   specifies the instruments DB file\n");                      printf("--instruments-db-location   specifies the instruments DB file\n");
338                        printf("--stacktrace                automatically shows stacktrace if crashes\n");
339                        printf("                            (broken on most systems at the moment)\n");
340                      exit(EXIT_SUCCESS);                      exit(EXIT_SUCCESS);
341                      break;                      break;
342                  case 1: // --version                  case 1: // --version
# Line 389  void parse_options(int argc, char **argv Line 407  void parse_options(int argc, char **argv
407                      exit(EXIT_FAILURE);                      exit(EXIT_FAILURE);
408                      return;                      return;
409  #endif  #endif
410                  case 7: // --lscp-addr                  case 7: { // --lscp-addr
411                      struct in_addr addr;                      struct in_addr addr;
412                      if (inet_aton(optarg, &addr) == 0)                      if (inet_aton(optarg, &addr) == 0)
413                          printf("WARNING: Failed to parse lscp-addr argument, ignoring!\n");                          printf("WARNING: Failed to parse lscp-addr argument, ignoring!\n");
414                      else                      else
415                          lscp_addr = addr.s_addr;                          lscp_addr = addr.s_addr;
416                      break;                      break;
417                  case 8: // --lscp-port                  }
418                    case 8: {// --lscp-port
419                      long unsigned int port = 0;                      long unsigned int port = 0;
420                      if ((sscanf(optarg, "%u", &port) != 1) || (port == 0) || (port > 65535))                      if ((sscanf(optarg, "%u", &port) != 1) || (port == 0) || (port > 65535))
421                          printf("WARNING: Failed to parse lscp-port argument, ignoring!\n");                          printf("WARNING: Failed to parse lscp-port argument, ignoring!\n");
422                      else                      else
423                          lscp_port = htons(port);                          lscp_port = htons(port);
424                      break;                      break;
425                    }
426                    case 9: // --stacktrace
427                        bShowStackTrace = true;
428                        break;
429              }              }
430          }          }
431      }      }

Legend:
Removed from v.1765  
changed lines
  Added in v.1908

  ViewVC Help
Powered by ViewVC