diff options
author | Roland Grunberg | 2010-04-08 16:00:49 +0000 |
---|---|---|
committer | Roland Grunberg | 2010-04-08 16:00:49 +0000 |
commit | b60cdad8f2b1e713dc3daeb4781669dd3e7c2cd3 (patch) | |
tree | 4cb1efc4d9137c67d16ecb4a0f90ed0acbe2807b /oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse | |
parent | fbb695782f35df1bcff6b1cd931ccfbcc83a0572 (diff) | |
download | org.eclipse.linuxtools-b60cdad8f2b1e713dc3daeb4781669dd3e7c2cd3.tar.gz org.eclipse.linuxtools-b60cdad8f2b1e713dc3daeb4781669dd3e7c2cd3.tar.xz org.eclipse.linuxtools-b60cdad8f2b1e713dc3daeb4781669dd3e7c2cd3.zip |
Use helper functions relocated into the profiling framework.
Diffstat (limited to 'oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse')
-rw-r--r-- | oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/oprofile/ui/view/OprofileViewDoubleClickListener.java | 125 |
1 files changed, 19 insertions, 106 deletions
diff --git a/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/oprofile/ui/view/OprofileViewDoubleClickListener.java b/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/oprofile/ui/view/OprofileViewDoubleClickListener.java index 4b753595b8..84dd4ae8b6 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/oprofile/ui/view/OprofileViewDoubleClickListener.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/oprofile/ui/view/OprofileViewDoubleClickListener.java @@ -10,20 +10,8 @@ *******************************************************************************/ package org.eclipse.linuxtools.oprofile.ui.view; -import java.util.ArrayList; import java.util.HashMap; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.IFunction; -import org.eclipse.cdt.core.index.IIndex; -import org.eclipse.cdt.core.index.IIndexFile; -import org.eclipse.cdt.core.index.IIndexManager; -import org.eclipse.cdt.core.index.IIndexName; -import org.eclipse.cdt.core.index.IndexFilter; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementVisitor; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.BadLocationException; @@ -67,14 +55,17 @@ public class OprofileViewDoubleClickListener implements IDoubleClickListener { } else if (element instanceof UiModelSymbol) { UiModelSymbol symbol = (UiModelSymbol)element; - String symbolString = symbol.getParent().getLabelText(); + String symbolLabel = symbol.getParent().getLabelText(); String fileName = symbol.getFileName(); String functionName = symbol.getFunctionName(); + int numOfArgs = -1; HashMap<String,int[]> map; ICProject project; try { - project = findCProjectWithFileName(symbolString); + // hard coded to match "XY.PQ% in /some/arbitrary/path/to/binary" + String absPath = symbolLabel.substring(symbolLabel.indexOf(" in ") + 4); + project = ProfileUIUtils.findCProjectWithAbsolutePath(absPath); if (project == null){ return; } @@ -83,9 +74,21 @@ public class OprofileViewDoubleClickListener implements IDoubleClickListener { return; } + // detect function with arguments and narrow search accordingly + if (functionName.matches(".*\\(.*\\)")) { + int start = functionName.indexOf('('); + if (functionName.contains(",")) { + int end = functionName.indexOf(')'); + numOfArgs = functionName.substring(start, end).split(",").length; + } else { + numOfArgs = 1; + } + functionName = functionName.substring(0, start); + } + if (fileName.length() > 0 && functionName.length() > 0){ // try and go to the function in the file - map = findFunctionsInProject(project, functionName, fileName); + map = ProfileUIUtils.findFunctionsInProject(project, functionName, numOfArgs, fileName); for (String loc : map.keySet()){ try { @@ -97,7 +100,7 @@ public class OprofileViewDoubleClickListener implements IDoubleClickListener { }else if (functionName.length() > 0){ // try to find the file name that has this function - map = findFunctionsInProject(project, functionName, null); + map = ProfileUIUtils.findFunctionsInProject(project, functionName, numOfArgs, null); for (String loc : map.keySet()){ try { @@ -135,94 +138,4 @@ public class OprofileViewDoubleClickListener implements IDoubleClickListener { } } - private static ICProject findCProjectWithFileName(final String symbolString) throws CoreException{ - final ArrayList<ICProject> ret = new ArrayList<ICProject>(); - - // visitor object to check for the matching path string - ICElementVisitor vis = new ICElementVisitor() { - public boolean visit(ICElement element) throws CoreException { - if (element.getElementType() == ICElement.C_CCONTAINER - || element.getElementType() == ICElement.C_PROJECT){ - return true; - }else if (symbolString.endsWith((element.getPath().toFile().getAbsolutePath()))){ - ret.add(element.getCProject()); - } - return false; - }}; - - ICProject[] cProjects = CCorePlugin.getDefault().getCoreModel().getCModel().getCProjects(); - for (ICProject proj : cProjects){ - // visit every project - proj.accept(vis); - } - - // is it possible to find more than one matching project ? - return ret.size() == 0 ? null : ret.get(0); - } - - /** - * Get a mapping between a file name, and the data relevant to locating - * the corresponding function name for a given project. - * - * @param project : C Project Type - * @param functionName : Name of a function - * @param fileHint : The name of the file where we expect to find functionName. - * It is null if we do not want to use this option. - * @return a HashMap<String, int []> of String absolute paths of files and the - * function's corresponding node-offset and length. - */ - private static HashMap<String,int[]> findFunctionsInProject(ICProject project, String functionName, String fileHint) { - HashMap<String,int[]> files = new HashMap<String,int[]>() ; - int numOfArgs = 0; - - // detect function with arguments and narrow search accordingly - if (functionName.matches(".*\\(.*\\)")){ - int start = functionName.indexOf('('); - if (functionName.contains(",")){ - int end = functionName.indexOf(')'); - numOfArgs = functionName.substring(start, end).split(",").length; - }else{ - numOfArgs = 1; - } - functionName = functionName.substring(0, start); - } - - IIndexManager manager = CCorePlugin.getIndexManager(); - IIndex index = null; - try { - index = manager.getIndex(project); - index.acquireReadLock(); - IBinding[] bindings = index.findBindings(functionName.toCharArray(), IndexFilter.ALL, null); - for (IBinding bind : bindings) { - if (bind instanceof IFunction && (((IFunction)bind).getParameters().length == numOfArgs)) { - IFunction ifunction = (IFunction) bind; - IIndexName[] names = index.findNames(ifunction, IIndex.FIND_DEFINITIONS); - for (IIndexName iname : names) { - IIndexFile file = iname.getFile(); - if (file != null) { - String loc = file.getLocation().getURI().getPath(); - if (fileHint != null){ - if (loc.endsWith(fileHint)){ - files.put(loc, new int [] {iname.getNodeOffset(), iname.getNodeLength()}); - } - }else{ - files.put(loc, new int [] {iname.getNodeOffset(), iname.getNodeLength()}); - } - } - } - } - } - - } catch (CoreException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (DOMException e) { - e.printStackTrace(); - }finally{ - index.releaseReadLock(); - } - return files; - } - } |