sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.irq/src/com/nokia/carbide/cpp/pi/irq/IrqPlugin.java
changeset 5 844b047e260d
child 12 ae255c9aa552
equal deleted inserted replaced
4:615035072f7e 5:844b047e260d
       
     1 /*
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: 
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.carbide.cpp.pi.irq;
       
    19 
       
    20 import java.io.File;
       
    21 import org.osgi.framework.BundleContext;
       
    22 import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository;
       
    23 import com.nokia.carbide.cpp.internal.pi.analyser.ProfileVisualiser;
       
    24 import com.nokia.carbide.cpp.internal.pi.model.GenericTrace;
       
    25 import com.nokia.carbide.cpp.internal.pi.model.ParsedTraceData;
       
    26 import com.nokia.carbide.cpp.internal.pi.plugin.model.AbstractPiPlugin;
       
    27 import com.nokia.carbide.cpp.internal.pi.plugin.model.IClassReplacer;
       
    28 import com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace;
       
    29 import com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable;
       
    30 import com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph;
       
    31 import com.nokia.carbide.cpp.internal.pi.visual.GraphDrawRequest;
       
    32 import com.nokia.carbide.cpp.pi.editors.PIPageEditor;
       
    33 
       
    34 /**
       
    35  * The activator class controls the plug-in life cycle
       
    36  */
       
    37 public class IrqPlugin extends AbstractPiPlugin implements ITrace,
       
    38 		IClassReplacer, IVisualizable {
       
    39 
       
    40 	/** The plug-in ID */
       
    41 	public static final String PLUGIN_ID = "com.nokia.carbide.cpp.pi.irq"; //$NON-NLS-1$
       
    42 
       
    43 	private static final String HELP_CONTEXT_ID = PIPageEditor.PI_ID + ".irq";  //$NON-NLS-1$
       
    44 	/** context help id of the main page */
       
    45 	public static final String HELP_CONTEXT_ID_MAIN_PAGE = HELP_CONTEXT_ID + ".irqPageContext";  //$NON-NLS-1$
       
    46 
       
    47 	private IrqTrace trace = null;
       
    48 
       
    49 	// There will be 1 graph for editor page 0
       
    50 	// This code may assume that page 0 has the threads graph
       
    51 	private final static int GRAPH_COUNT = 3;
       
    52 
       
    53 	// The plug-in ID
       
    54 
       
    55 	// The shared instance
       
    56 	private static IrqPlugin plugin;
       
    57 
       
    58 	/**
       
    59 	 * The constructor
       
    60 	 */
       
    61 	public IrqPlugin() {
       
    62 		super();
       
    63 	}
       
    64 
       
    65 	/*
       
    66 	 * (non-Javadoc)
       
    67 	 * 
       
    68 	 * @see
       
    69 	 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
       
    70 	 * )
       
    71 	 */
       
    72 	public void start(BundleContext context) throws Exception {
       
    73 		super.start(context);
       
    74 		plugin = this;
       
    75 	}
       
    76 
       
    77 	/*
       
    78 	 * (non-Javadoc)
       
    79 	 * 
       
    80 	 * @see
       
    81 	 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
       
    82 	 * )
       
    83 	 */
       
    84 	public void stop(BundleContext context) throws Exception {
       
    85 		plugin = null;
       
    86 		super.stop(context);
       
    87 	}
       
    88 
       
    89 	/**
       
    90 	 * Returns the shared instance
       
    91 	 * 
       
    92 	 * @return the shared instance
       
    93 	 */
       
    94 	public static IrqPlugin getDefault() {
       
    95 		return plugin;
       
    96 	}
       
    97 
       
    98 	/*
       
    99 	 * (non-Javadoc)
       
   100 	 * 
       
   101 	 * @see
       
   102 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace#getTraceClass()
       
   103 	 */
       
   104 	@SuppressWarnings("unchecked")
       
   105 	public Class getTraceClass() {
       
   106 		return IrqTrace.class;
       
   107 	}
       
   108 
       
   109 	/*
       
   110 	 * (non-Javadoc)
       
   111 	 * 
       
   112 	 * @see com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace#getTraceId()
       
   113 	 */
       
   114 	public int getTraceId() {
       
   115 		return 6;
       
   116 	}
       
   117 
       
   118 	/*
       
   119 	 * (non-Javadoc)
       
   120 	 * 
       
   121 	 * @see com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace#getTraceName()
       
   122 	 */
       
   123 	public String getTraceName() {
       
   124 		return Messages.IrqPlugin_0;
       
   125 	}
       
   126 
       
   127 	/* (non-Javadoc)
       
   128 	 * @see com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace#getTraceTitle()
       
   129 	 */
       
   130 	public String getTraceTitle() {
       
   131 		return Messages.IrqPlugin_5;
       
   132 	}
       
   133 
       
   134 	/*
       
   135 	 * (non-Javadoc)
       
   136 	 * 
       
   137 	 * @see
       
   138 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace#initialiseTrace
       
   139 	 * (com.nokia.carbide.cpp.internal.pi.model.GenericTrace)
       
   140 	 */
       
   141 	public void initialiseTrace(GenericTrace genericTrace) {
       
   142 		trace = (IrqTrace) genericTrace;
       
   143 		NpiInstanceRepository.getInstance().activeUidAddTrace(
       
   144 				"com.nokia.carbide.cpp.pi.irq", trace); //$NON-NLS-1$
       
   145 		trace.gatherDrawData();
       
   146 
       
   147 	}
       
   148 
       
   149 	/*
       
   150 	 * (non-Javadoc)
       
   151 	 * 
       
   152 	 * @see
       
   153 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace#parseTraceFiles
       
   154 	 * (java.io.File[])
       
   155 	 */
       
   156 	public ParsedTraceData parseTraceFiles(File[] files) throws Exception {
       
   157 		throw new UnsupportedOperationException();
       
   158 	}
       
   159 
       
   160 	/*
       
   161 	 * (non-Javadoc)
       
   162 	 * 
       
   163 	 * @see
       
   164 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace#parseTraceFile(
       
   165 	 * java.io.File)
       
   166 	 */
       
   167 	public ParsedTraceData parseTraceFile(File file) throws Exception {
       
   168 		IrqTraceParser irqParser;
       
   169 
       
   170 		irqParser = new IrqTraceParser();
       
   171 		ParsedTraceData ptd = irqParser.parse(file);
       
   172 		return ptd;
       
   173 	}
       
   174 
       
   175 	/*
       
   176 	 * (non-Javadoc)
       
   177 	 * 
       
   178 	 * @seecom.nokia.carbide.cpp.internal.pi.plugin.model.IClassReplacer#
       
   179 	 * getReplacedClass(java.lang.String)
       
   180 	 */
       
   181 	@SuppressWarnings("unchecked")
       
   182 	public Class getReplacedClass(String className) {
       
   183 		if (className.indexOf(Messages.IrqPlugin_1) != -1
       
   184 				|| className.indexOf(Messages.IrqPlugin_2) != -1)
       
   185 
       
   186 		{
       
   187 			return IrqTrace.class;
       
   188 		} else if (className
       
   189 				.indexOf(Messages.IrqPlugin_3) != -1
       
   190 				|| className.indexOf(Messages.IrqPlugin_4) != -1) {
       
   191 			return IrqSample.class;
       
   192 		} else
       
   193 			return null;
       
   194 	}
       
   195 
       
   196 	/*
       
   197 	 * (non-Javadoc)
       
   198 	 * 
       
   199 	 * @see
       
   200 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#arePagesCreated
       
   201 	 * ()
       
   202 	 */
       
   203 	public boolean arePagesCreated() {
       
   204 		return false;
       
   205 	}
       
   206 
       
   207 	/*
       
   208 	 * (non-Javadoc)
       
   209 	 * 
       
   210 	 * @see
       
   211 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#createPage
       
   212 	 * (int)
       
   213 	 */
       
   214 	public ProfileVisualiser createPage(int index) {
       
   215 		return null;
       
   216 	}
       
   217 
       
   218 	/*
       
   219 	 * (non-Javadoc)
       
   220 	 * 
       
   221 	 * @seecom.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#
       
   222 	 * getCreatePageCount()
       
   223 	 */
       
   224 	public int getCreatePageCount() {
       
   225 		return 0;
       
   226 	}
       
   227 
       
   228 	/*
       
   229 	 * (non-Javadoc)
       
   230 	 * 
       
   231 	 * @seecom.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#
       
   232 	 * getCreatePageIndex(int)
       
   233 	 */
       
   234 	public int getCreatePageIndex(int index) {
       
   235 		return 0;
       
   236 	}
       
   237 
       
   238 	/*
       
   239 	 * (non-Javadoc)
       
   240 	 * 
       
   241 	 * @see
       
   242 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#getDrawRequest
       
   243 	 * (int)
       
   244 	 */
       
   245 	public GraphDrawRequest getDrawRequest(int graphIndex) {
       
   246 		return null;
       
   247 	}
       
   248 
       
   249 	/*
       
   250 	 * (non-Javadoc)
       
   251 	 * 
       
   252 	 * @see
       
   253 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#getGraphCount
       
   254 	 * ()
       
   255 	 */
       
   256 	public int getGraphCount() {
       
   257 		return GRAPH_COUNT;
       
   258 	}
       
   259 
       
   260 	/*
       
   261 	 * (non-Javadoc)
       
   262 	 * 
       
   263 	 * @see
       
   264 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#getLastSample
       
   265 	 * (int)
       
   266 	 */
       
   267 	public Integer getLastSample(int graphIndex) {
       
   268 		IrqTrace trace = (IrqTrace) NpiInstanceRepository.getInstance()
       
   269 				.activeUidGetTrace("com.nokia.carbide.cpp.pi.irq"); //$NON-NLS-1$
       
   270 
       
   271 		if (trace != null)
       
   272 			return Integer.valueOf(trace.getLastSampleNumber());
       
   273 		else
       
   274 			return null;
       
   275 	}
       
   276 
       
   277 	/*
       
   278 	 * (non-Javadoc)
       
   279 	 * 
       
   280 	 * @see
       
   281 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#getPageNumber
       
   282 	 * (int)
       
   283 	 */
       
   284 	public int getPageNumber(int graphIndex) {
       
   285 		// Assumes page 0 has the threads graph, 1 has the binaries, and 2 has
       
   286 		// the functions
       
   287 		if (graphIndex == 0)
       
   288 			return PIPageEditor.THREADS_PAGE;
       
   289 		else if (graphIndex == 1)
       
   290 			return PIPageEditor.BINARIES_PAGE;
       
   291 		else if (graphIndex == 2)
       
   292 			return PIPageEditor.FUNCTIONS_PAGE;
       
   293 
       
   294 		return PIPageEditor.NEXT_AVAILABLE_PAGE;
       
   295 	}
       
   296 
       
   297 	/*
       
   298 	 * (non-Javadoc)
       
   299 	 * 
       
   300 	 * @see
       
   301 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#getTraceGraph
       
   302 	 * (int)
       
   303 	 */
       
   304 	public GenericTraceGraph getTraceGraph(int graphIndex) {
       
   305 		IrqTrace trace = (IrqTrace) NpiInstanceRepository.getInstance()
       
   306 				.activeUidGetTrace("com.nokia.carbide.cpp.pi.irq"); //$NON-NLS-1$
       
   307 
       
   308 		if (trace != null)
       
   309 			return trace.getTraceGraph(graphIndex);
       
   310 		else
       
   311 			return null;
       
   312 	}
       
   313 
       
   314 	/*
       
   315 	 * (non-Javadoc)
       
   316 	 * 
       
   317 	 * @see
       
   318 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#setPageIndex
       
   319 	 * (int, int)
       
   320 	 */
       
   321 	public void setPageIndex(int index, int pageIndex) {
       
   322 		return;
       
   323 	}
       
   324 
       
   325 	/*
       
   326 	 * (non-Javadoc)
       
   327 	 * 
       
   328 	 * @see
       
   329 	 * com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#setPagesCreated
       
   330 	 * (boolean)
       
   331 	 */
       
   332 	public void setPagesCreated(boolean pagesCreated) {
       
   333 		return;
       
   334 	}
       
   335 
       
   336 }