TraceDatabase.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.traceviewer.db;
00002
00003 import java.util.HashMap;
00004
00005 import org.eclipse.core.commands.Command;
00006 import org.eclipse.jface.action.IStatusLineManager;
00007 import org.eclipse.jface.window.Window;
00008 import org.eclipse.swt.widgets.Shell;
00009 import org.eclipse.ui.IWorkbenchPage;
00010 import org.eclipse.ui.IWorkbenchWindow;
00011 import org.eclipse.ui.PartInitException;
00012 import org.eclipse.ui.services.ISourceProviderService;
00013
00014 import edu.rice.cs.hpc.common.ui.Util;
00015 import edu.rice.cs.hpc.traceviewer.actions.OptionMidpoint;
00016 import edu.rice.cs.hpc.traceviewer.db.local.LocalDBOpener;
00017 import edu.rice.cs.hpc.traceviewer.db.remote.RemoteDBOpener;
00018 import edu.rice.cs.hpc.traceviewer.depth.HPCDepthView;
00019 import edu.rice.cs.hpc.traceviewer.main.HPCTraceView;
00020 import edu.rice.cs.hpc.traceviewer.misc.HPCCallStackView;
00021 import edu.rice.cs.hpc.traceviewer.operation.TraceOperation;
00022 import edu.rice.cs.hpc.traceviewer.services.DataService;
00023 import edu.rice.cs.hpc.traceviewer.spaceTimeData.SpaceTimeDataController;
00024 import edu.rice.cs.hpc.traceviewer.summary.HPCSummaryView;
00025 import edu.rice.cs.hpc.traceviewer.ui.OpenDatabaseDialog;
00026
00027
00028
00029
00030
00031
00032
00033 public class TraceDatabase
00034 {
00035 static private HashMap<IWorkbenchWindow, TraceDatabase> listOfDatabases = null;
00036
00037 private SpaceTimeDataController dataTraces = null;
00038 private AbstractDBOpener opener = null;
00039
00040
00041
00042
00043
00044
00045
00046 static public TraceDatabase getInstance(IWorkbenchWindow _window) {
00047 if (listOfDatabases == null) {
00048 listOfDatabases = new HashMap<IWorkbenchWindow, TraceDatabase>();
00049 TraceDatabase data = new TraceDatabase();
00050 listOfDatabases.put(_window, data);
00051 return data;
00052 } else {
00053 TraceDatabase data = listOfDatabases.get(_window);
00054 if (data == null) {
00055 data = new TraceDatabase();
00056 listOfDatabases.put(_window, data);
00057 }
00058 return data;
00059 }
00060 }
00061
00065 static public void removeInstance(IWorkbenchWindow _window) {
00066
00067 if (listOfDatabases != null) {
00068 final TraceDatabase data = listOfDatabases.get(_window);
00069 if (data == null) return;
00070 if (data.dataTraces != null) {
00071 data.dataTraces.closeDB();
00072 data.dataTraces.dispose();
00073 }
00074 listOfDatabases.remove(_window);
00075 }
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 private AbstractDBOpener getDBOpener(DatabaseAccessInfo info)
00087 {
00088 if (info.isLocal())
00089 {
00090 opener = new LocalDBOpener(info.databasePath);
00091 } else
00092 {
00093 opener = new RemoteDBOpener(info);
00094 }
00095 return opener;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 static public boolean openDatabase(IWorkbenchWindow window,
00107 final String database, IStatusLineManager statusMgr)
00108 {
00109 DatabaseAccessInfo info = new DatabaseAccessInfo();
00110 info.databasePath = database;
00111
00112 return openDatabase(window, statusMgr, info);
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 static public boolean openDatabase(IWorkbenchWindow window, IStatusLineManager statusMgr)
00126 {
00127 OpenDatabaseDialog dlg = new OpenDatabaseDialog(window.getShell(), statusMgr, null);
00128 if (dlg.open() == Window.CANCEL)
00129 return false;
00130
00131 DatabaseAccessInfo info = dlg.getDatabaseAccessInfo();
00132 return openDatabase(window, statusMgr, info);
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 static private boolean openDatabase(IWorkbenchWindow window, IStatusLineManager statusMgr,
00146 DatabaseAccessInfo info)
00147 {
00148 SpaceTimeDataController stdc = null;
00149 TraceDatabase database = TraceDatabase.getInstance(window);
00150 String message = null;
00151 DatabaseAccessInfo database_info = info;
00152
00153 do {
00154 database.opener = database.getDBOpener(database_info);
00155
00156 try {
00157 stdc = database.opener.openDBAndCreateSTDC(window, statusMgr);
00158 } catch (Exception e)
00159 {
00160 stdc = null;
00161 message = e.getMessage();
00162
00163 OpenDatabaseDialog dlg = new OpenDatabaseDialog(window.getShell(), statusMgr, message);
00164 if (dlg.open() == Window.CANCEL)
00165 return false;
00166
00167 database_info = dlg.getDatabaseAccessInfo();
00168 }
00169
00170 } while (stdc == null);
00171
00172
00173 if (database.dataTraces != null)
00174 database.dataTraces.dispose();
00175
00176 database.dataTraces = stdc;
00177
00178
00179
00180
00181 final Command command = Util.getCommand(window, OptionMidpoint.commandId);
00182 boolean enableMidpoint = Util.isOptionEnabled(command);
00183 database.dataTraces.setEnableMidpoint(enableMidpoint);
00184
00185 statusMgr.setMessage("Rendering trace data ...");
00186
00187 final Shell shell = window.getShell();
00188 shell.update();
00189
00190
00191 ISourceProviderService sourceProviderService = (ISourceProviderService) window.getService(ISourceProviderService.class);
00192
00193
00194 DataService dataService = (DataService) sourceProviderService.getSourceProvider(DataService.DATA_PROVIDER);
00195 dataService.setData(database.dataTraces);
00196
00197
00198 TraceOperation.clear();
00199
00200 try {
00201
00202
00203
00204 shell.setText("hpctraceviewer: " + database.dataTraces.getName());
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 IWorkbenchPage page = window.getActivePage();
00219
00220 HPCSummaryView sview = (HPCSummaryView) page.showView(HPCSummaryView.ID);
00221 sview.updateView(database.dataTraces);
00222
00223 HPCDepthView dview = (HPCDepthView) page.showView(HPCDepthView.ID);
00224 dview.updateView(database.dataTraces);
00225
00226 HPCTraceView tview = (HPCTraceView) page.showView(HPCTraceView.ID);
00227 tview.updateView(database.dataTraces);
00228
00229 HPCCallStackView cview = (HPCCallStackView) page.showView(HPCCallStackView.ID);
00230 cview.updateView(database.dataTraces);
00231
00232 return true;
00233
00234 } catch (PartInitException e) {
00235 e.printStackTrace();
00236 }
00237
00238 return false;
00239 }
00240 }