Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.eclipse.e4.ui.internal.workbench.ResourceHandler;
import org.eclipse.e4.ui.internal.workbench.SelectionAggregator;
import org.eclipse.e4.ui.internal.workbench.SelectionServiceImpl;
import org.eclipse.core.internal.runtime.StartupTrace;
import org.eclipse.e4.ui.internal.workbench.URIHelper;
import org.eclipse.e4.ui.internal.workbench.WorkbenchLogger;
import org.eclipse.e4.ui.model.application.MAddon;
Expand Down Expand Up @@ -140,6 +141,7 @@ public Display getApplicationDisplay() {

@Override
public Object start(IApplicationContext applicationContext) throws Exception {
long tStart = StartupTrace.begin();
// set the display name before the Display is
// created to ensure the app name is used in any
// platform menus, etc. See
Expand All @@ -148,7 +150,9 @@ public Object start(IApplicationContext applicationContext) throws Exception {
if (product != null && product.getName() != null) {
Display.setAppName(product.getName());
}
long tDisp = StartupTrace.begin();
Display display = getApplicationDisplay();
StartupTrace.record("E4Application.start/getApplicationDisplay", tDisp); //$NON-NLS-1$
Location instanceLocation = null;
try {
E4Workbench workbench = createE4Workbench(applicationContext, display);
Expand All @@ -160,11 +164,15 @@ public Object start(IApplicationContext applicationContext) throws Exception {
// place it off so it's not visible
shell.setLocation(0, 10000);
}
if (!checkInstanceLocation(instanceLocation, shell, workbench.getContext())) {
long tCheck = StartupTrace.begin();
boolean ok = checkInstanceLocation(instanceLocation, shell, workbench.getContext());
StartupTrace.record("E4Application.start/checkInstanceLocation", tCheck); //$NON-NLS-1$
if (!ok) {
return EXIT_OK;
}

// Create and run the UI (if any)
StartupTrace.record("E4Application.start (pre-createAndRunUI)", tStart); //$NON-NLS-1$
workbench.createAndRunUI(workbench.getApplication());

saveModel();
Expand Down Expand Up @@ -210,9 +218,12 @@ public void saveModel() {
}

public E4Workbench createE4Workbench(IApplicationContext applicationContext, final Display display) {
long tTotal = StartupTrace.begin();
args = (String[]) applicationContext.getArguments().get(IApplicationContext.APPLICATION_ARGS);

long tCtx = StartupTrace.begin();
IEclipseContext appContext = createDefaultContext();
StartupTrace.record("E4Application.createE4Workbench/createDefaultContext", tCtx); //$NON-NLS-1$
appContext.set(Display.class, display);
appContext.set(Realm.class, DisplayRealm.getRealm(display));
appContext.set(UISynchronize.class, new DisplayUISynchronize(display));
Expand All @@ -227,6 +238,7 @@ public E4Workbench createE4Workbench(IApplicationContext applicationContext, fin

// Install the life-cycle manager for this session if there's one
// defined
long tLc = StartupTrace.begin();
Optional<String> lifeCycleURI = getArgValue(IWorkbench.LIFE_CYCLE_URI_ARG, applicationContext, false);
lifeCycleURI.ifPresent(lifeCycleURIValue -> {
lcManager = factory.create(lifeCycleURIValue, appContext);
Expand All @@ -235,6 +247,7 @@ public E4Workbench createE4Workbench(IApplicationContext applicationContext, fin
ContextInjectionFactory.invoke(lcManager, PostContextCreate.class, appContext, null);
}
});
StartupTrace.record("E4Application.createE4Workbench/lifecycle manager (PostContextCreate)", tLc); //$NON-NLS-1$

Optional<String> forcedPerspectiveId = getArgValue(PERSPECTIVE_ARG_NAME, applicationContext, false);
forcedPerspectiveId.ifPresent(forcedPerspectiveIdValue -> appContext.set(E4Workbench.FORCED_PERSPECTIVE_ID,
Expand All @@ -246,7 +259,9 @@ public E4Workbench createE4Workbench(IApplicationContext applicationContext, fin
}

// Create the app model and its context
long tModel = StartupTrace.begin();
MApplication appModel = loadApplicationModel(applicationContext, appContext);
StartupTrace.record("E4Application.createE4Workbench/loadApplicationModel", tModel); //$NON-NLS-1$
appModel.setContext(appContext);

boolean isRtl = ((Window.getDefaultOrientation() & SWT.RIGHT_TO_LEFT) != 0);
Expand All @@ -263,21 +278,34 @@ public E4Workbench createE4Workbench(IApplicationContext applicationContext, fin
appContext.set(MApplication.class, appModel);

// adds basic services to the contexts
long tSvc = StartupTrace.begin();
initializeServices(appModel);
StartupTrace.record("E4Application.createE4Workbench/initializeServices", tSvc); //$NON-NLS-1$

// let the life cycle manager add to the model
if (lcManager != null) {
long tLc2 = StartupTrace.begin();
ContextInjectionFactory.invoke(lcManager, ProcessAdditions.class, appContext, null);
ContextInjectionFactory.invoke(lcManager, ProcessRemovals.class, appContext, null);
StartupTrace.record("E4Application.createE4Workbench/lifecycle ProcessAdditions+Removals", tLc2); //$NON-NLS-1$
}

// Create the addons
long tAddons = StartupTrace.begin();
long tQuery = StartupTrace.begin();
IEclipseContext addonStaticContext = EclipseContextFactory.create();
for (MAddon addon : appModel.getAddons()) {
List<MAddon> addons = appModel.getAddons();
StartupTrace.record("create addons/query extension registry", tQuery); //$NON-NLS-1$
long tInstantiate = StartupTrace.begin();
int addonCount = 0;
for (MAddon addon : addons) {
addonStaticContext.set(MAddon.class, addon);
Object obj = factory.create(addon.getContributionURI(), appContext, addonStaticContext);
addon.setObject(obj);
addonCount++;
}
StartupTrace.record("create addons/instantiate addons (count=" + addonCount + ")", tInstantiate); //$NON-NLS-1$ //$NON-NLS-2$
StartupTrace.record("E4Application.createE4Workbench/create addons", tAddons); //$NON-NLS-1$

// Parse out parameters from both the command line and/or the product
// definition (if any) and put them in the context
Expand All @@ -287,7 +315,9 @@ public E4Workbench createE4Workbench(IApplicationContext applicationContext, fin
});


long tCss = StartupTrace.begin();
setCSSContextVariables(applicationContext, appContext);
StartupTrace.record("E4Application.createE4Workbench/setCSSContextVariables", tCss); //$NON-NLS-1$

Optional<String> rendererFactoryURI = getArgValue(E4Workbench.RENDERER_FACTORY_URI, applicationContext, false);
rendererFactoryURI.ifPresent(rendererFactoryURIValue -> {
Expand All @@ -300,7 +330,11 @@ public E4Workbench createE4Workbench(IApplicationContext applicationContext, fin

// Instantiate the Workbench (which is responsible for
// 'running' the UI (if any)...
return workbench = new E4Workbench(appModel, appContext);
long tCtor = StartupTrace.begin();
E4Workbench wb = new E4Workbench(appModel, appContext);
StartupTrace.record("E4Application.createE4Workbench/new E4Workbench(ctor)", tCtor); //$NON-NLS-1$
StartupTrace.record("E4Application.createE4Workbench (total)", tTotal); //$NON-NLS-1$
return workbench = wb;
}

private void setCSSContextVariables(IApplicationContext applicationContext, IEclipseContext context) {
Expand Down Expand Up @@ -378,10 +412,14 @@ private MApplication loadApplicationModel(IApplicationContext appContext, IEclip

IContributionFactory factory = eclipseContext.get(IContributionFactory.class);

long tHandler = StartupTrace.begin();
handler = (IModelResourceHandler) factory.create(resourceHandler, eclipseContext);
StartupTrace.record("loadApplicationModel/create IModelResourceHandler", tHandler); //$NON-NLS-1$
eclipseContext.set(IModelResourceHandler.class, handler);

long tLoad = StartupTrace.begin();
Resource resource = handler.loadMostRecentModel();
StartupTrace.record("loadApplicationModel/handler.loadMostRecentModel (XMI parse)", tLoad); //$NON-NLS-1$
return (MApplication) resource.getContents().get(0);
}

Expand Down Expand Up @@ -509,21 +547,37 @@ public void stop() {

// TODO This should go into a different bundle
public static IEclipseContext createDefaultHeadlessContext() {
long tCreate = StartupTrace.begin();
IEclipseContext serviceContext = E4Workbench.getServiceContext();
StartupTrace.record("createDefaultContext/EclipseContextFactory.create", tCreate); //$NON-NLS-1$

long tCore = StartupTrace.begin();
long coreCifNs = 0L;
int coreCifCount = 0;
IExtensionRegistry registry = RegistryFactory.getRegistry();
ExceptionHandler exceptionHandler = new ExceptionHandler();
serviceContext.set(IContributionFactory.class, new ReflectionContributionFactory());
serviceContext.set(IExceptionHandler.class, exceptionHandler);
serviceContext.set(IExtensionRegistry.class, registry);

serviceContext.set(Adapter.class, ContextInjectionFactory.make(EclipseAdapter.class, serviceContext));
long tCif1 = StartupTrace.begin();
EclipseAdapter adapter = ContextInjectionFactory.make(EclipseAdapter.class, serviceContext);
coreCifNs += System.nanoTime() - tCif1;
coreCifCount++;
serviceContext.set(Adapter.class, adapter);

// No default log provider available
if (serviceContext.get(ILoggerProvider.class) == null) {
serviceContext.set(ILoggerProvider.class,
ContextInjectionFactory.make(DefaultLoggerProvider.class, serviceContext));
long tCif2 = StartupTrace.begin();
DefaultLoggerProvider loggerProvider = ContextInjectionFactory.make(DefaultLoggerProvider.class, serviceContext);
coreCifNs += System.nanoTime() - tCif2;
coreCifCount++;
serviceContext.set(ILoggerProvider.class, loggerProvider);
}
StartupTrace.record(
"createDefaultContext/register core services/ContextInjectionFactory.make (count=" + coreCifCount + ")", //$NON-NLS-1$ //$NON-NLS-2$
System.nanoTime() - coreCifNs);
StartupTrace.record("createDefaultContext/register core services", tCore); //$NON-NLS-1$

return serviceContext;
}
Expand All @@ -532,12 +586,25 @@ public static IEclipseContext createDefaultHeadlessContext() {
public static IEclipseContext createDefaultContext() {

IEclipseContext serviceContext = createDefaultHeadlessContext();

long tUi = StartupTrace.begin();
long uiCifNs = 0L;
int uiCifCount = 0;
final IEclipseContext appContext = serviceContext.createChild("WorkbenchContext"); //$NON-NLS-1$
// make application context available for dependency injection under the E4Application.APPLICATION_CONTEXT_KEY key
appContext.set(IWorkbench.APPLICATION_CONTEXT_KEY, appContext);

appContext.set(Logger.class, ContextInjectionFactory.make(WorkbenchLogger.class, appContext));
appContext.set(EModelService.class, ContextInjectionFactory.make(ModelServiceImpl.class, appContext));
long tCif3 = StartupTrace.begin();
WorkbenchLogger logger = ContextInjectionFactory.make(WorkbenchLogger.class, appContext);
uiCifNs += System.nanoTime() - tCif3;
uiCifCount++;
appContext.set(Logger.class, logger);

long tCif4 = StartupTrace.begin();
ModelServiceImpl modelService = ContextInjectionFactory.make(ModelServiceImpl.class, appContext);
uiCifNs += System.nanoTime() - tCif4;
uiCifCount++;
appContext.set(EModelService.class, modelService);
appContext.set(EPlaceholderResolver.class, new PlaceholderResolver());

// setup for commands and handlers
Expand Down Expand Up @@ -571,6 +638,10 @@ public void setClassnameAndId(Object widget, String classname, String id) {

// translation
initializeLocalization(appContext);
StartupTrace.record(
"createDefaultContext/register UI services/ContextInjectionFactory.make (count=" + uiCifCount + ")", //$NON-NLS-1$ //$NON-NLS-2$
System.nanoTime() - uiCifNs);
StartupTrace.record("createDefaultContext/register UI services", tUi); //$NON-NLS-1$

return appContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.internal.runtime.StartupTrace;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
Expand Down Expand Up @@ -314,11 +315,17 @@ public void processModel(boolean initial) {
IExtension[] extensions = new ExtensionsSort().sort(extPoint.getExtensions());

// run processors which are marked to run before fragments
long tProcBefore = StartupTrace.begin();
runProcessors(extensions, initial, false);
StartupTrace.record("handler.loadMostRecentModel/processor.process", tProcBefore); //$NON-NLS-1$
// process fragments (and resolve imports)
long tFrag = StartupTrace.begin();
processFragments(extensions, initial);
StartupTrace.record("handler.loadMostRecentModel/fragments.process", tFrag); //$NON-NLS-1$
// run processors which are marked to run after fragments
long tProcAfter = StartupTrace.begin();
runProcessors(extensions, initial, true);
StartupTrace.record("handler.loadMostRecentModel/processor.process", tProcAfter); //$NON-NLS-1$
}

// once we are done, any further handling in the tracker can't be initial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.internal.runtime.StartupTrace;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
Expand Down Expand Up @@ -139,6 +140,7 @@ private boolean hasTopLevelWindows(Resource applicationResource) {

@Override
public Resource loadMostRecentModel() {
long tResolve = StartupTrace.begin();
File workbenchData = null;
URI restoreLocation = null;

Expand All @@ -160,10 +162,13 @@ public Resource loadMostRecentModel() {
// boolean restore = restoreLastModified > lastApplicationModification;
boolean restore = restoreLastModified > 0;
boolean initialModel;
StartupTrace.record("handler.loadMostRecentModel/resolve applicationXMI URI", tResolve); //$NON-NLS-1$

resource = null;
if (restore && saveAndRestore) {
resource = loadResource(restoreLocation);
long tDeltas = StartupTrace.begin();
resource = loadResource(restoreLocation, "handler.loadMostRecentModel/merge deltas"); //$NON-NLS-1$
StartupTrace.record("handler.loadMostRecentModel/merge deltas (if persisted state exists)", tDeltas); //$NON-NLS-1$
// If the saved model does not have any top-level windows, Eclipse will exit
// immediately, so throw out the persisted state and reinitialize with the defaults.
if (!hasTopLevelWindows(resource)) {
Expand All @@ -175,7 +180,9 @@ public Resource loadMostRecentModel() {
}
}
if (resource == null) {
Resource applicationResource = loadResource(applicationDefinitionInstance);
long tLoad = StartupTrace.begin();
Resource applicationResource = loadResource(applicationDefinitionInstance, null);
StartupTrace.record("handler.loadMostRecentModel/load default model (XMIResource.load)", tLoad); //$NON-NLS-1$
MApplication theApp = (MApplication) applicationResource.getContents().get(0);
resource = createResourceWithApp(theApp);
context.set(E4Workbench.NO_SAVED_MODEL_FOUND, Boolean.TRUE);
Expand Down Expand Up @@ -257,10 +264,14 @@ private File getBaseLocation() {
}

// Ensures that even models with error are loaded!
private Resource loadResource(URI uri) {
private Resource loadResource(URI uri, String tracePhasePrefix) {
Resource resource;
try {
long tLoad = StartupTrace.begin();
resource = getResource(uri);
if (tracePhasePrefix != null) {
StartupTrace.record(tracePhasePrefix + "/load delta resource", tLoad); //$NON-NLS-1$
}
} catch (Exception e) {
// TODO We could use diagnostics for better analyzing the error
logger.error(e, "Unable to load resource " + uri); //$NON-NLS-1$
Expand All @@ -270,13 +281,19 @@ private Resource loadResource(URI uri) {
// TODO once we switch from deltas, we only need this once on the default model?
String contributorURI = URIHelper.EMFtoPlatform(uri);
if (contributorURI != null) {
long tApply = StartupTrace.begin();
int count = 0;
TreeIterator<EObject> it = EcoreUtil.getAllContents(resource.getContents());
while (it.hasNext()) {
EObject o = it.next();
if (o instanceof MApplicationElement) {
((MApplicationElement) o).setContributorURI(contributorURI);
count++;
}
}
if (tracePhasePrefix != null) {
StartupTrace.record(tracePhasePrefix + "/apply delta (count=" + count + ")", tApply); //$NON-NLS-1$ //$NON-NLS-2$
}
}
return resource;
}
Expand Down
Loading
Loading