1 11 12 package org.eclipse.osgi.internal.profile; 13 14 import org.eclipse.osgi.framework.debug.FrameworkDebugOptions; 15 import org.eclipse.osgi.framework.internal.core.FrameworkProperties; 16 17 23 24 public class Profile { 25 28 public static final boolean PROFILE = true; 32 public static boolean STARTUP = false; 36 public static boolean BENCHMARK = false; 40 public static boolean DEBUG = false; 42 private static final String OSGI_PROP = "osgi.profile."; private static final String PROP_STARTUP = OSGI_PROP + "startup"; private static final String PROP_BENCHMARK = OSGI_PROP + "benchmark"; private static final String PROP_DEBUG = OSGI_PROP + "debug"; private static final String PROP_IMPL = OSGI_PROP + "impl"; 48 private static final String OSGI_OPTION = "org.eclipse.osgi/profile/"; private static final String OPTION_STARTUP = OSGI_OPTION + "startup"; private static final String OPTION_BENCHMARK = OSGI_OPTION + "benchmark"; private static final String OPTION_DEBUG = OSGI_OPTION + "debug"; private static final String OPTION_IMPL = OSGI_OPTION + "impl"; 54 57 public static final int FLAG_NONE = 0; 58 61 public static final int FLAG_ENTER = 1; 62 65 public static final int FLAG_EXIT = 2; 66 69 public static final String ENTER_DESCRIPTION = "enter"; 73 public static final String EXIT_DESCRIPTION = "exit"; 75 private static ProfileLogger profileLogger = null; 76 private static String profileLoggerClassName = null; 77 78 static { 79 initProps(); 80 } 81 82 88 public static void initProps() { 89 String prop; 90 FrameworkDebugOptions dbgOptions = null; 91 92 if (FrameworkProperties.getProperty("osgi.debug") != null) { dbgOptions = FrameworkDebugOptions.getDefault(); 97 if (dbgOptions != null) { 98 STARTUP = dbgOptions.getBooleanOption(OPTION_STARTUP, false); 99 BENCHMARK = dbgOptions.getBooleanOption(OPTION_BENCHMARK, false); 100 DEBUG = dbgOptions.getBooleanOption(OPTION_DEBUG, false); 101 if (profileLogger == null) 102 profileLoggerClassName = dbgOptions.getOption(OPTION_IMPL); 103 } 104 } 105 106 if ((prop = FrameworkProperties.getProperty(PROP_STARTUP)) != null) { 108 STARTUP = Boolean.valueOf(prop).booleanValue(); 109 if (dbgOptions != null) 110 dbgOptions.setOption(OPTION_STARTUP, new Boolean (STARTUP).toString()); 111 } 112 if ((prop = FrameworkProperties.getProperty(PROP_BENCHMARK)) != null) { 113 BENCHMARK = Boolean.valueOf(prop).booleanValue(); 114 if (dbgOptions != null) 115 dbgOptions.setOption(OPTION_BENCHMARK, new Boolean (BENCHMARK).toString()); 116 } 117 if ((prop = FrameworkProperties.getProperty(PROP_DEBUG)) != null) { 118 DEBUG = Boolean.valueOf(prop).booleanValue(); 119 if (dbgOptions != null) 120 dbgOptions.setOption(OPTION_DEBUG, new Boolean (DEBUG).toString()); 121 } 122 123 if (profileLogger == null) { 124 if ((prop = FrameworkProperties.getProperty(PROP_IMPL)) != null) { 125 profileLoggerClassName = prop; 126 if (dbgOptions != null) 127 dbgOptions.setOption(OPTION_IMPL, profileLoggerClassName); 128 } 129 } else { 130 profileLogger.initProps(); 131 } 132 } 133 134 139 public static void logEnter(String id) { 140 logTime(FLAG_ENTER, id, ENTER_DESCRIPTION, null); 141 } 142 143 149 public static void logEnter(String id, String description) { 150 logTime(FLAG_ENTER, id, ENTER_DESCRIPTION, description); 151 } 152 153 158 public static void logExit(String id) { 159 logTime(FLAG_EXIT, id, EXIT_DESCRIPTION, null); 160 } 161 162 168 public static void logExit(String id, String description) { 169 logTime(FLAG_EXIT, id, EXIT_DESCRIPTION, description); 170 } 171 172 178 public static void logTime(String id, String msg) { 179 logTime(FLAG_NONE, id, msg, null); 180 } 181 182 189 public static void logTime(String id, String msg, String description) { 190 logTime(FLAG_NONE, id, msg, description); 191 } 192 193 205 public static void logTime(int flag, String id, String msg, String description) { 206 if (profileLogger == null) 207 profileLogger = createProfileLogger(); 208 profileLogger.logTime(flag, id, msg, description); 209 } 210 211 216 public static void accumLogEnter(String scope) { 217 if (profileLogger == null) 218 profileLogger = createProfileLogger(); 219 profileLogger.accumLogEnter(scope); 220 } 221 222 227 public static void accumLogExit(String scope) { 228 if (profileLogger == null) 229 profileLogger = createProfileLogger(); 230 profileLogger.accumLogExit(scope); 231 } 232 233 238 public static String getProfileLog() { 239 if (profileLogger != null) 240 return profileLogger.getProfileLog(); 241 return ""; } 243 244 247 private static ProfileLogger createProfileLogger() { 248 ProfileLogger result = null; 249 250 if (profileLoggerClassName != null) { 252 Class profileImplClass = null; 253 try { 254 profileImplClass = Class.forName(profileLoggerClassName); 255 result = (ProfileLogger) profileImplClass.newInstance(); 256 } catch (Exception e) { 257 e.printStackTrace(); 259 } 260 } 261 262 if (result == null) 264 result = new DefaultProfileLogger(); 265 266 return (result); 267 } 268 } 269 | Popular Tags |