1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

[288656] Add tracing for DsfSession. Implemented Pawel's recommendation after review

This commit is contained in:
John Cortell 2009-09-08 15:52:33 +00:00
parent edda14615e
commit df44df36d3
3 changed files with 60 additions and 8 deletions

View file

@ -40,7 +40,7 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.core.templateengine,
org.eclipse.cdt.core.templateengine.process,
org.eclipse.cdt.core.templateengine.process.processes,
org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.debug.core,org.eclipse.cdt.dsf",
org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.debug.core",
org.eclipse.cdt.internal.core.browser;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.cdtvariables;x-internal:=true,
org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui",

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2009 Freescale Semiconductor, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Freescale Semiconductor - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.dsf.internal;
/**
* Some general purpose functions that can be useful for logging/tracing
* activities. This is a duplicate of LoggingUtils in
* org.eclipse.cdt.internal.core. The idea is for core parts of DSF (ones that
* don't have debug in package name) to have very limited dependencies on other
* plugins.
*
* @since 5.2
*/
public class LoggingUtils {
/**
* Return a string that uniquely identifies a Java object reference, in the form "classname@id", where
* 'classname' is the simple (unqualified) name of the object's class, and 'id' is the hash code. If the
* object is of an anonymous class, classname will be "<anonymous-class>".
*
* Why not just use obj.toString()? That method is often overriden, and so cannot be relied on for a
* representation that uniquely identifies the object in the VM space.
*
* @param obj
* the object reference to stringify
* @return the stringified representation of the object reference
*/
public static String toString(Object obj) {
if (obj == null) {
return "null"; //$NON-NLS-1$
}
String className = obj.getClass().getSimpleName();
if (className == null) {
className = "<anonymous-class>"; //$NON-NLS-1$
}
String id = Integer.toHexString(System.identityHashCode(obj));
return className + "@" + id; //$NON-NLS-1$
}
}

View file

@ -30,7 +30,7 @@ import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
import org.eclipse.cdt.dsf.concurrent.ThreadSafe;
import org.eclipse.cdt.dsf.internal.DsfPlugin;
import org.eclipse.cdt.internal.core.LoggingUtils;
import org.eclipse.cdt.dsf.internal.LoggingUtils;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
@ -63,7 +63,7 @@ public class DsfSession
*
* @since 2.1
*/
protected static final boolean DEBUG_SESSION;
private static final boolean DEBUG_SESSION;
/**
* Has the "debug/session/listeners" tracing option been turned on? Requires
@ -71,7 +71,7 @@ public class DsfSession
*
* @since 2.1
*/
protected static final boolean DEBUG_SESSION_LISTENERS;
private static final boolean DEBUG_SESSION_LISTENERS;
/**
* Has the "debug/session/dispatches" tracing option been turned on? Requires
@ -79,7 +79,7 @@ public class DsfSession
*
* @since 2.1
*/
protected static final boolean DEBUG_SESSION_DISPATCHES;
private static final boolean DEBUG_SESSION_DISPATCHES;
static {
DEBUG_SESSION = DsfPlugin.DEBUG && "true".equals( //$NON-NLS-1$
@ -286,7 +286,8 @@ public class DsfSession
assert !fListeners.containsKey(entry);
if (DEBUG_SESSION_LISTENERS) {
String msg = new Formatter().format(
"%s added as a service listener to %s (id=%s)", //$NON-NLS-1$
"%s %s added as a service listener to %s (id=%s)", //$NON-NLS-1$
DsfPlugin.getDebugTime(),
LoggingUtils.toString(listener),
LoggingUtils.toString(this),
getId()
@ -305,7 +306,8 @@ public class DsfSession
assert fListeners.containsKey(entry);
if (DEBUG_SESSION_LISTENERS) {
String msg = new Formatter().format(
"%s removed as a service listener to %s (id=%s)", //$NON-NLS-1$
"%s %s removed as a service listener to %s (id=%s)", //$NON-NLS-1$
DsfPlugin.getDebugTime(),
LoggingUtils.toString(listener),
LoggingUtils.toString(this),
getId()
@ -429,7 +431,7 @@ public class DsfSession
for (Method method : entry.getValue()) {
try {
if (DEBUG_SESSION_DISPATCHES) {
DsfPlugin.debug("Listener " + LoggingUtils.toString(entry.getKey().fListener) + " invoked with event " + LoggingUtils.toString(event)); //$NON-NLS-1$ //$NON-NLS-2$
DsfPlugin.debug(DsfPlugin.getDebugTime() + " Listener " + LoggingUtils.toString(entry.getKey().fListener) + " invoked with event " + LoggingUtils.toString(event)); //$NON-NLS-1$ //$NON-NLS-2$
}
method.invoke(entry.getKey().fListener, new Object[] { event } );
}