Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

setup.cpp

00001 /*
00002  *                         Sun Public License Notice
00003  *
00004  * The contents of this file are subject to the Sun Public License
00005  * Version 1.0 (the "License"); you may not use this file except
00006  * in compliance with the License. A copy of the License is available
00007  * at http://www.sun.com/
00008  *
00009  * The Original Code is the Java Profiler module.  The Initial Developers
00010  * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
00011  * Lukas Petru and Marek Przeczek.
00012  *
00013  * Portions created by Jan Stola are Copyright (C) 2000-2001.
00014  * All Rights Reserved.
00015  *
00016  * Portions created by Pavel Vacha are Copyright (C) 2000-2001.
00017  * All Rights Reserved.
00018  *
00019  * Portions created by Michal Pise are Copyright (C) 2000-2001.
00020  * All Rights Reserved.
00021  *
00022  * Portions created by Petr Luner are Copyright (C) 2000-2001.
00023  * All Rights Reserved.
00024  *
00025  * Portions created by Lukas Petru are Copyright (C) 2000-2001.
00026  * All Rights Reserved.
00027  *
00028  * Portions created by Marek Przeczek are Copyright (C) 2000-2001.
00029  * All Rights Reserved.
00030  *
00031  * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
00032  *               Lukas Petru and Marek Przeczek.
00033  */
00034 
00035 #include "../setup/setup.h"
00036 #include "../main/const.h"
00037 
00038 Setup::Setup( char* options) {
00039 
00040         alloc.turnedOn = 1;
00041         alloc.level = LEVEL_TRACE;
00042         alloc.traceDepth = 2;
00043         alloc.threadsEnabled = 1;
00044 
00045         cpu.turnedOn = 1; 
00046         cpu.sampling = 1;
00047         cpu.level = LEVEL_TRACE;
00048         cpu.traceDepth = 2;
00049         cpu.threadsEnabled = 1;
00050 
00051         mon.turnedOn = 1; 
00052         mon.level = LEVEL_TRACE;
00053         mon.traceDepth = 2;
00054         mon.threadsEnabled = 1;
00055 
00056         if( options) processOptions( options);
00057 }
00058 
00059 void Setup::processOptions(char* options) {
00060 
00061         char option[100];
00062         char* end;
00063         int len;
00064 
00065         if (!options) return;
00066 
00067         while (end = strchr(options, ',')) {
00068 
00069                 len = end - options;
00070                 if ((len > 0) && (len < 100)) {
00071                         strncpy(option, options, len);
00072                         option[len] = '\0';
00073                         processOption(option);
00074                 }
00075                 options = end + 1;
00076         }
00077 
00078         len = strlen(options);
00079         if ((len > 0) && (len < 100)) {
00080                 strcpy(option, options);
00081                 processOption(option);
00082         }
00083 }
00084 
00085 void Setup::processOption(char* option) {
00086 
00087         char* eq;
00088 
00089         if (!(eq = strchr(option, '='))) return;
00090         *eq = '\0';
00091         setParameter(option, eq + 1);
00092 }
00093 
00094 void Setup::setParameter(char* name, char* value) {
00095 
00096         if (strcmp(name, "alloc") == 0) {
00097                 
00098                 if (strcmp(value, "on") == 0) 
00099                         alloc.turnedOn = 1;
00100                 else if (strcmp(value, "off") == 0) 
00101                         alloc.turnedOn = 0;
00102 
00103                 return;
00104         }
00105 
00106         if (strcmp(name, "alloc_level") == 0) {
00107                 
00108                 if (strcmp(value, "object") == 0) 
00109                         alloc.level = LEVEL_OBJECT;
00110                 else if (strcmp(value, "method") == 0) 
00111                         alloc.level = LEVEL_METHOD;
00112                 else if (strcmp(value, "trace") == 0) 
00113                         alloc.level = LEVEL_TRACE;
00114 
00115                 return;
00116         }
00117 
00118         if (strcmp(name, "alloc_trace_depth") == 0) {
00119                 
00120                 int depth = atoi(value);
00121 
00122                 if (depth > 0) {
00123                         if (depth > MAX_TRACE) depth = MAX_TRACE;
00124                         alloc.traceDepth = depth;
00125                 }
00126                 return;
00127         }
00128 
00129         if (strcmp(name, "alloc_thread") == 0) {
00130                 
00131                 if (strcmp(value, "on") == 0) 
00132                         alloc.threadsEnabled = 1;
00133                 else if (strcmp(value, "off") == 0) 
00134                         alloc.threadsEnabled = 0;
00135 
00136                 return;
00137         }
00138 
00139         if (strcmp(name, "cpu") == 0) {
00140                 
00141                 if (strcmp(value, "on") == 0) 
00142                         cpu.turnedOn = 1;
00143                 else if (strcmp(value, "off") == 0) 
00144                         cpu.turnedOn = 0;
00145 
00146                 return;
00147         }
00148 
00149         if (strcmp(name, "cpu_method") == 0) {
00150                 
00151                 if (strcmp(value, "exact") == 0) 
00152                         cpu.sampling = 0;
00153                 else if (strcmp(value, "sampling") == 0) 
00154                         cpu.sampling = 1; 
00155 
00156                 return;
00157         }
00158 
00159         if (strcmp(name, "cpu_level") == 0) {
00160                 
00161                 if (strcmp(value, "method") == 0) 
00162                         cpu.level = LEVEL_METHOD;
00163                 else if (strcmp(value, "trace") == 0) 
00164                         cpu.level = LEVEL_TRACE;
00165 
00166                 return;
00167         }
00168 
00169         if (strcmp(name, "cpu_trace_depth") == 0) {
00170                 
00171                 int depth = atoi(value);
00172 
00173                 if (depth > 0) {
00174                         if (depth > MAX_TRACE) depth = MAX_TRACE;
00175                         cpu.traceDepth = depth;
00176                 }
00177                 return;
00178         }
00179 
00180         if (strcmp(name, "cpu_thread") == 0) {
00181                 
00182                 if (strcmp(value, "on") == 0) 
00183                         cpu.threadsEnabled = 1;
00184                 else if (strcmp(value, "off") == 0) 
00185                         cpu.threadsEnabled = 0;
00186 
00187                 return;
00188         }
00189 
00190         if (strcmp(name, "mon") == 0) {
00191                 
00192                 if (strcmp(value, "on") == 0) 
00193                         mon.turnedOn = 1;
00194                 else if (strcmp(value, "off") == 0) 
00195                         mon.turnedOn = 0;
00196 
00197                 return;
00198         }
00199 
00200         if (strcmp(name, "mon_level") == 0) {
00201                 
00202                 if (strcmp(value, "method") == 0) 
00203                         mon.level = LEVEL_METHOD;
00204                 else if (strcmp(value, "trace") == 0) 
00205                         mon.level = LEVEL_TRACE;
00206 
00207                 return;
00208         }
00209 
00210         if (strcmp(name, "mon_trace_depth") == 0) {
00211                 
00212                 int depth = atoi(value);
00213 
00214                 if (depth > 0) {
00215                         if (depth > MAX_TRACE) depth = MAX_TRACE;
00216                         mon.traceDepth = depth;
00217                 }
00218                 return;
00219         }
00220 
00221         if (strcmp(name, "mon_thread") == 0) {
00222                 
00223                 if (strcmp(value, "on") == 0) 
00224                         mon.threadsEnabled = 1;
00225                 else if (strcmp(value, "off") == 0) 
00226                         mon.threadsEnabled = 0;
00227 
00228                 return;
00229         }
00230 
00231         if( !strcmp( name, "commun_type")) {
00232         
00233                 if( !strcmp( value, "socket"))     com.communType = COMMUN_SOCKET;
00234                 else if( !strcmp( value, "shmem")) com.communType = COMMUN_SHMEM;
00235                 
00236                 return;
00237         }
00238 
00239         if( !strcmp( name, "commun_host")) {
00240         
00241                 com.hostname = value;
00242                 return;
00243         }
00244 
00245         if( !strcmp( name, "commun_port")) {
00246         
00247                 com.port = (unsigned short)atoi( value);
00248                 return;
00249         }
00250 
00251         if( !strcmp( name, "commun_shmem_size")) {
00252         
00253                 com.shmemSize = atoi( value);
00254                 return;
00255         }
00256 
00257         if( !strcmp( name, "commun_shmem_id")) {
00258         
00259                 com.shmemId = value;
00260                 return;
00261         }
00262 
00263         if( !strcmp( name, "connect_mode")) {
00264         
00265                 if( !strcmp( value, "server"))      com.connectMode = 0;
00266                 else if( !strcmp( value, "client")) com.connectMode = 1;
00267 
00268                 return;
00269         }
00270 }

Generated on Mon Jan 28 14:53:27 2002 for Java Profiler Dynamic Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001