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

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

  ViewVC Help
Powered by ViewVC