1 11 package org.eclipse.ui.internal.misc; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.core.runtime.PerformanceStats; 16 import org.eclipse.core.runtime.Platform; 17 import org.eclipse.ui.PlatformUI; 18 19 26 public class UIStats { 27 28 private static HashMap operations = new HashMap (); 29 30 public static final int CREATE_PART = 0; 31 32 public static final int CREATE_PART_CONTROL = 1; 33 34 public static final int INIT_PART = 2; 35 36 public static final int CREATE_PERSPECTIVE = 3; 37 38 public static final int RESTORE_WORKBENCH = 4; 39 40 public static final int START_WORKBENCH = 5; 41 42 public static final int CREATE_PART_INPUT = 6; 43 44 public static final int ACTIVATE_PART = 7; 45 46 public static final int BRING_PART_TO_TOP = 8; 47 48 public static final int NOTIFY_PART_LISTENERS = 9; 49 50 public static final int SWITCH_PERSPECTIVE = 10; 51 52 public static final int NOTIFY_PAGE_LISTENERS = 11; 53 54 public static final int NOTIFY_PERSPECTIVE_LISTENERS = 12; 55 56 public static final int UI_JOB = 13; 57 58 public static final int CONTENT_TYPE_LOOKUP = 14; 59 60 63 public static final int LAST_VALUE = CONTENT_TYPE_LOOKUP; 64 65 private static boolean debug[] = new boolean[LAST_VALUE+1]; 66 67 private static String [] events = new String [LAST_VALUE+1]; 68 69 static { 70 events[CREATE_PART] = PlatformUI.PLUGIN_ID + "/perf/part.create"; events[CREATE_PART_INPUT] = PlatformUI.PLUGIN_ID + "/perf/part.input"; events[CREATE_PART_CONTROL] = PlatformUI.PLUGIN_ID + "/perf/part.control"; events[INIT_PART] = PlatformUI.PLUGIN_ID + "/perf/part.init"; events[CREATE_PERSPECTIVE] = PlatformUI.PLUGIN_ID + "/perf/perspective.create"; events[SWITCH_PERSPECTIVE] = PlatformUI.PLUGIN_ID + "/perf/perspective.switch"; events[RESTORE_WORKBENCH] = PlatformUI.PLUGIN_ID + "/perf/workbench.restore"; events[START_WORKBENCH] = PlatformUI.PLUGIN_ID + "/perf/workbench.start"; events[ACTIVATE_PART] = PlatformUI.PLUGIN_ID + "/perf/part.activate"; events[BRING_PART_TO_TOP] = PlatformUI.PLUGIN_ID + "/perf/part.activate"; events[NOTIFY_PART_LISTENERS] = PlatformUI.PLUGIN_ID + "/perf/part.listeners"; events[NOTIFY_PAGE_LISTENERS] = PlatformUI.PLUGIN_ID + "/perf/page.listeners"; events[NOTIFY_PERSPECTIVE_LISTENERS] = PlatformUI.PLUGIN_ID + "/perf/perspective.listeners"; events[UI_JOB] = PlatformUI.PLUGIN_ID + "/perf/uijob"; events[CONTENT_TYPE_LOOKUP] = PlatformUI.PLUGIN_ID + "/perf/contentTypes"; 86 for (int i = 0; i <= LAST_VALUE; i++) { 87 if (events[i] != null && PerformanceStats.ENABLED) { 89 debug[i] = PerformanceStats.isEnabled(events[i]); 90 } 91 } 92 } 93 94 101 public static boolean isDebugging(int event) { 102 return debug[event]; 103 } 104 105 111 public static void start(int event, String label) { 112 if (debug[event]) { 113 operations.put(event + label, new Long (System.currentTimeMillis())); 114 } 115 } 116 117 125 public static void end(int event, Object blame, String label) { 126 if (debug[event]) { 127 Long startTime = (Long ) operations.remove(event + label); 128 if (startTime == null) { 129 return; 130 } 131 final long elapsed = System.currentTimeMillis() - startTime.longValue(); 132 PerformanceStats.getStats(events[event], blame).addRun(elapsed, label); 135 } 136 } 137 138 142 public static void startupComplete() { 143 String option = Platform.getDebugOption(Platform.PI_RUNTIME + "/debug"); if (option == null || !"true".equalsIgnoreCase(option)) { return; 148 } 149 String startString = System.getProperty("eclipse.startTime"); if (startString == null) { 151 return; 152 } 153 try { 154 long start = Long.parseLong(startString); 155 long end = System.currentTimeMillis(); 156 System.out.println("Startup complete: " + (end - start) + "ms"); } catch (NumberFormatException e) { 158 } 160 } 161 } 162 | Popular Tags |