|
Added
Link Here
|
| 0 |
- |
1 |
/******************************************************************************* |
|
|
2 |
* Copyright (c) 2012 Red Hat, Inc. |
| 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 |
* Camilo Bernal <cabernal@redhat.com> - Initial Implementation. |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.linuxtools.internal.perf.ui; |
| 12 |
|
| 13 |
import java.util.ArrayList; |
| 14 |
|
| 15 |
import org.eclipse.core.resources.IFile; |
| 16 |
import org.eclipse.jface.action.Action; |
| 17 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 18 |
import org.eclipse.linuxtools.internal.perf.model.PMSymbolMatch; |
| 19 |
import org.eclipse.linuxtools.internal.perf.model.PMSymbolMatcher; |
| 20 |
import org.eclipse.swt.widgets.Display; |
| 21 |
import org.eclipse.ui.IWorkbench; |
| 22 |
import org.eclipse.ui.IWorkbenchPage; |
| 23 |
import org.eclipse.ui.IWorkbenchWindow; |
| 24 |
import org.eclipse.ui.PartInitException; |
| 25 |
import org.eclipse.ui.PlatformUI; |
| 26 |
|
| 27 |
public class PerfDiffAction extends Action { |
| 28 |
public PerfDiffAction() { |
| 29 |
super("Session Comparison"); |
| 30 |
} |
| 31 |
|
| 32 |
@Override |
| 33 |
public void run() { |
| 34 |
IWorkbench workbench = PlatformUI.getWorkbench(); |
| 35 |
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); |
| 36 |
try { |
| 37 |
IWorkbenchPage wbp = workbenchWindow.getActivePage(); |
| 38 |
IWorkbench wb = PlatformUI.getWorkbench(); |
| 39 |
IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); |
| 40 |
IWorkbenchPage page = win.getActivePage(); |
| 41 |
|
| 42 |
PerfDataCollectionView vp = (PerfDataCollectionView) page |
| 43 |
.findView("org.eclipse.linuxtools.perf.ui.PerfSessionCompareView"); |
| 44 |
|
| 45 |
ArrayList<Object> selectedFiles = vp.getSelectedFiles(); |
| 46 |
|
| 47 |
if (selectedFiles.size() < 2) { |
| 48 |
MessageDialog.openInformation(Display.getCurrent() |
| 49 |
.getActiveShell(), "Warning", |
| 50 |
"Please select two perf data files."); |
| 51 |
vp.restart(); |
| 52 |
} else { |
| 53 |
IFile staleData; |
| 54 |
IFile freshData; |
| 55 |
|
| 56 |
// Check if selections are proper files. |
| 57 |
try { |
| 58 |
staleData = (IFile) selectedFiles.get(0); |
| 59 |
freshData = (IFile) selectedFiles.get(1); |
| 60 |
} catch (ClassCastException e) { |
| 61 |
e.printStackTrace(); |
| 62 |
MessageDialog.openInformation(Display.getCurrent() |
| 63 |
.getActiveShell(), "Error", |
| 64 |
"Selections were not proper perf data files."); |
| 65 |
vp.clearSelections(); |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
ArrayList<PMSymbolMatch> result = PMSymbolMatcher.buildResults( |
| 70 |
staleData, freshData); |
| 71 |
|
| 72 |
// If result is null, selected files were not proper perf data |
| 73 |
// files |
| 74 |
if (result == null) { |
| 75 |
MessageDialog.openInformation(Display.getCurrent() |
| 76 |
.getActiveShell(), "Error", |
| 77 |
"Selections were not proper perf data files."); |
| 78 |
vp.clearSelections(); |
| 79 |
} else { |
| 80 |
|
| 81 |
PerfDiffView diffView = (PerfDiffView) wbp |
| 82 |
.showView("org.eclipse.linuxtools.perf.ui.PerfSessionDiffView"); |
| 83 |
diffView.setResult(result); |
| 84 |
diffView.refreshView(); |
| 85 |
|
| 86 |
wbp.showView("org.eclipse.linuxtools.perf.ui.PerfSessionDiffView"); |
| 87 |
} |
| 88 |
} |
| 89 |
} catch (PartInitException e) { |
| 90 |
e.printStackTrace(); |
| 91 |
} |
| 92 |
} |
| 93 |
} |