diff options
author | Eike Stepper | 2007-12-15 08:34:47 +0000 |
---|---|---|
committer | Eike Stepper | 2007-12-15 08:34:47 +0000 |
commit | a12a51bb96fb2ebed5996aa6661a9647744c995b (patch) | |
tree | 638a865d05eb0eedbc4cfe7323229912cb8cc091 /plugins/org.eclipse.net4j.util | |
parent | 0fbb634e5b04a79035322b391291e979af4cf20b (diff) | |
download | cdo-a12a51bb96fb2ebed5996aa6661a9647744c995b.tar.gz cdo-a12a51bb96fb2ebed5996aa6661a9647744c995b.tar.xz cdo-a12a51bb96fb2ebed5996aa6661a9647744c995b.zip |
[213084] Provide performance logging
https://bugs.eclipse.org/bugs/show_bug.cgi?id=213084
Diffstat (limited to 'plugins/org.eclipse.net4j.util')
-rw-r--r-- | plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/PerfTracer.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/PerfTracer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/PerfTracer.java new file mode 100644 index 0000000000..65f54ba2a4 --- /dev/null +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/PerfTracer.java @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * 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: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.net4j.internal.util.om.trace; + +import org.eclipse.net4j.util.om.trace.OMTracer; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +/** + * @author Eike Stepper + */ +public class PerfTracer extends ContextTracer +{ + public static final long NOT_STARTED = 0L; + + private ConcurrentMap<Object, Long> timers = new ConcurrentHashMap<Object, Long>(); + + public PerfTracer(OMTracer delegate, Class<?> context) + { + super(delegate, context); + } + + public void start(Object object) + { + if (isEnabled()) + { + timers.put(object, System.currentTimeMillis()); + } + } + + public long stop(Object object) + { + long duration = NOT_STARTED; + if (isEnabled()) + { + Long timer = timers.remove(object); + if (timer != null) + { + duration = System.currentTimeMillis() - timer; + format("{0} = {1} millis", object, duration); + } + } + + return duration; + } + + public long getDuration(Object object) + { + long duration = NOT_STARTED; + if (isEnabled()) + { + Long timer = timers.get(object); + if (timer != null) + { + duration = System.currentTimeMillis() - timer; + } + } + + return duration; + } +} |