KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > events > ResourceStats


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.events;
12
13 import org.eclipse.core.resources.*;
14 import org.eclipse.core.runtime.PerformanceStats;
15
16 /**
17  * An ResourceStats collects and aggregates timing data about an event such as
18  * a builder running, an editor opening, etc.
19  */

20 public class ResourceStats {
21     /**
22      * The event that is currently occurring, maybe <code>null</code>
23      */

24     private static PerformanceStats currentStats;
25     //performance event names
26
public static final String JavaDoc EVENT_BUILDERS = ResourcesPlugin.PI_RESOURCES + "/perf/builders"; //$NON-NLS-1$
27
public static final String JavaDoc EVENT_LISTENERS = ResourcesPlugin.PI_RESOURCES + "/perf/listeners"; //$NON-NLS-1$
28
public static final String JavaDoc EVENT_SAVE_PARTICIPANTS = ResourcesPlugin.PI_RESOURCES + "/perf/save.participants"; //$NON-NLS-1$
29
public static final String JavaDoc EVENT_SNAPSHOT = ResourcesPlugin.PI_RESOURCES + "/perf/snapshot"; //$NON-NLS-1$
30

31     //performance event enablement
32
public static boolean TRACE_BUILDERS = PerformanceStats.isEnabled(ResourceStats.EVENT_BUILDERS);
33     public static boolean TRACE_LISTENERS = PerformanceStats.isEnabled(ResourceStats.EVENT_LISTENERS);
34     public static boolean TRACE_SAVE_PARTICIPANTS = PerformanceStats.isEnabled(ResourceStats.EVENT_SAVE_PARTICIPANTS);
35     public static boolean TRACE_SNAPSHOT = PerformanceStats.isEnabled(ResourceStats.EVENT_SNAPSHOT);
36
37     public static void endBuild() {
38         if (currentStats != null)
39             currentStats.endRun();
40         currentStats = null;
41     }
42
43     public static void endNotify() {
44         if (currentStats != null)
45             currentStats.endRun();
46         currentStats = null;
47     }
48
49     public static void endSave() {
50         if (currentStats != null)
51             currentStats.endRun();
52         currentStats = null;
53     }
54
55     public static void endSnapshot() {
56         if (currentStats != null)
57             currentStats.endRun();
58         currentStats = null;
59     }
60
61     /**
62      * Notifies the stats tool that a resource change listener has been added.
63      */

64     public static void listenerAdded(IResourceChangeListener listener) {
65         if (listener != null)
66             PerformanceStats.getStats(EVENT_LISTENERS, listener.getClass().getName());
67     }
68
69     /**
70      * Notifies the stats tool that a resource change listener has been removed.
71      */

72     public static void listenerRemoved(IResourceChangeListener listener) {
73         if (listener != null)
74             PerformanceStats.removeStats(EVENT_LISTENERS, listener.getClass().getName());
75     }
76
77     public static void startBuild(IncrementalProjectBuilder builder) {
78         currentStats = PerformanceStats.getStats(EVENT_BUILDERS, builder);
79         currentStats.startRun(builder.getProject().getName());
80     }
81
82     public static void startNotify(IResourceChangeListener listener) {
83         currentStats = PerformanceStats.getStats(EVENT_LISTENERS, listener);
84         currentStats.startRun();
85     }
86
87     public static void startSnapshot() {
88         currentStats = PerformanceStats.getStats(EVENT_SNAPSHOT, ResourcesPlugin.getWorkspace());
89         currentStats.startRun();
90     }
91
92     public static void startSave(ISaveParticipant participant) {
93         currentStats = PerformanceStats.getStats(EVENT_SAVE_PARTICIPANTS, participant);
94         currentStats.startRun();
95     }
96 }
Popular Tags