comparison graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java @ 13142:401830ff96f4

some improvements in Debug logging
author Erik Eckstein <erik.eckstein@oracle.com>
date Mon, 25 Nov 2013 13:41:18 +0100
parents cb5df1879500
children 1baa169508f5
comparison
equal deleted inserted replaced
13141:333ec6116aa7 13142:401830ff96f4
73 lastUsedIndent = new IndentImpl(this, enabled); 73 lastUsedIndent = new IndentImpl(this, enabled);
74 return lastUsedIndent; 74 return lastUsedIndent;
75 } 75 }
76 76
77 @Override 77 @Override
78 public Indent logIndent(String msg, Object... args) { 78 public Indent logAndIndent(String msg, Object... args) {
79 log(msg, args); 79 log(msg, args);
80 return indent(); 80 return indent();
81 } 81 }
82 82
83 @Override 83 @Override
84 public Indent outdent() { 84 public Indent outdent() {
85 if (parentIndent != null) { 85 if (parentIndent != null) {
86 lastUsedIndent = parentIndent; 86 lastUsedIndent = parentIndent;
87 } 87 }
88 return lastUsedIndent; 88 return lastUsedIndent;
89 }
90
91 @Override
92 public void close() {
93 outdent();
89 } 94 }
90 } 95 }
91 96
92 private static ThreadLocal<DebugScope> instanceTL = new ThreadLocal<>(); 97 private static ThreadLocal<DebugScope> instanceTL = new ThreadLocal<>();
93 private static ThreadLocal<DebugConfig> configTL = new ThreadLocal<>(); 98 private static ThreadLocal<DebugConfig> configTL = new ThreadLocal<>();
229 * @return the value returned by the task 234 * @return the value returned by the task
230 */ 235 */
231 public <T> T scope(String newName, Runnable runnable, Callable<T> callable, boolean sandbox, DebugConfig sandboxConfig, Object[] newContext) { 236 public <T> T scope(String newName, Runnable runnable, Callable<T> callable, boolean sandbox, DebugConfig sandboxConfig, Object[] newContext) {
232 DebugScope oldContext = getInstance(); 237 DebugScope oldContext = getInstance();
233 DebugConfig oldConfig = getConfig(); 238 DebugConfig oldConfig = getConfig();
234 boolean oldLogEnabled = oldContext.isLogEnabled();
235 DebugScope newChild = null; 239 DebugScope newChild = null;
236 if (sandbox) { 240 if (sandbox) {
237 newChild = new DebugScope(newName, newName, null, newContext); 241 newChild = new DebugScope(newName, newName, null, newContext);
238 setConfig(sandboxConfig); 242 setConfig(sandboxConfig);
239 } else { 243 } else {
240 newChild = oldContext.createChild(newName, newContext); 244 newChild = oldContext.createChild(newName, newContext);
241 } 245 }
242 instanceTL.set(newChild); 246 instanceTL.set(newChild);
247 newChild.setLogEnabled(oldContext.isLogEnabled());
243 newChild.updateFlags(); 248 newChild.updateFlags();
244 try { 249 try {
245 return executeScope(runnable, callable); 250 return executeScope(runnable, callable);
246 } finally { 251 } finally {
247 newChild.context = null; 252 newChild.context = null;
248 instanceTL.set(oldContext); 253 instanceTL.set(oldContext);
249 setConfig(oldConfig); 254 setConfig(oldConfig);
250 setLogEnabled(oldLogEnabled);
251 } 255 }
252 } 256 }
253 257
254 private <T> T executeScope(Runnable runnable, Callable<T> callable) { 258 private <T> T executeScope(Runnable runnable, Callable<T> callable) {
255 259
281 DebugConfig config = getConfig(); 285 DebugConfig config = getConfig();
282 if (config == null) { 286 if (config == null) {
283 meterEnabled = false; 287 meterEnabled = false;
284 timeEnabled = false; 288 timeEnabled = false;
285 dumpEnabled = false; 289 dumpEnabled = false;
286 setLogEnabled(false);
287 290
288 // Be pragmatic: provide a default log stream to prevent a crash if the stream is not 291 // Be pragmatic: provide a default log stream to prevent a crash if the stream is not
289 // set while logging 292 // set while logging
290 output = System.out; 293 output = System.out;
291 } else { 294 } else {
292 meterEnabled = config.isMeterEnabled(); 295 meterEnabled = config.isMeterEnabled();
293 timeEnabled = config.isTimeEnabled(); 296 timeEnabled = config.isTimeEnabled();
294 dumpEnabled = config.isDumpEnabled(); 297 dumpEnabled = config.isDumpEnabled();
295 output = config.output(); 298 output = config.output();
296 setLogEnabled(config.isLogEnabled()); 299 if (config.isLogEnabled()) {
300 setLogEnabled(true);
301 }
297 } 302 }
298 } 303 }
299 304
300 private RuntimeException interceptException(final Throwable e) { 305 private RuntimeException interceptException(final Throwable e) {
301 final DebugConfig config = getConfig(); 306 final DebugConfig config = getConfig();