sysperfana/memspyext/com.nokia.s60tools.heapanalyser/src/com/nokia/s60tools/heapanalyser/interfaces/HeapAnalyserLauncher.java
changeset 7 8e12a575a9b5
equal deleted inserted replaced
6:f65f740e69f9 7:8e12a575a9b5
       
     1 /*
       
     2 * Copyright (c) 2009 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 "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 
       
    19 
       
    20 package com.nokia.s60tools.heapanalyser.interfaces;
       
    21 
       
    22 import java.io.File;
       
    23 
       
    24 import com.nokia.s60tools.heapanalyser.HeapAnalyserPlugin;
       
    25 import com.nokia.s60tools.util.debug.DbgUtility;
       
    26 
       
    27 /**
       
    28  * Class with static variables and helper method to launch Heap Analyser.
       
    29  */
       
    30 public class HeapAnalyserLauncher {
       
    31 
       
    32     /// Indicates an unspecified or general error
       
    33     public static final int KErrCommandLineGeneral = -1;
       
    34 
       
    35     /// Indicates that one or more mandatory command line arguments was omitted
       
    36     public static final int KErrCommandLineArgumentsMissing = -2;
       
    37 
       
    38     /// Indicates that an input command was not supported or valid
       
    39     public static final int KErrCommandLineInvalidCommand = -3;
       
    40 
       
    41     /// Indicates that the specified input file was not found
       
    42     public static final int KErrCommandLineArgumentsFileNotFound = -4;
       
    43 
       
    44     /// Indicates a fatal problem when attempting to read the input file
       
    45     public static final int KErrCommandLineArgumentsFileInvalid = -5;
       
    46 
       
    47     /// Indicates source file(s) were not found or specified
       
    48     public static final int KErrCommandLineSourceFileNotFound = -6;
       
    49 
       
    50     /// Indicates debug meta data was omitted from the inputs
       
    51     public static final int KErrCommandLineDebugMetaDataMissing = -7;
       
    52 
       
    53     /// Occurs if Heap Analyser cannot find a handler for the specified command
       
    54     /// line arguments.
       
    55     public static final int KErrCommandLineUINotAvailable = -8;
       
    56 
       
    57     /// The requested analysis type is not supported
       
    58     public static final int KErrCommandLineAnalysisTypeNotSupported = -9;
       
    59 
       
    60     /// The specified analysis thread name is invalid
       
    61     public static final int KErrCommandLineAnalysisThreadNameInvalid = -10;
       
    62 
       
    63     /// The specified output data is invalid
       
    64     public static final int KErrCommandLineAnalysisOutputInvalid = -11;
       
    65 	
       
    66     /// The specified output data is invalid
       
    67     public static final int KErrCommandLineLaunchingFailed = -12;
       
    68 	
       
    69 	
       
    70 	private static final String EXE_FOLDER = "Binaries";
       
    71 	private static final String COMMAND_LINE_COMMAND = " -input "; 
       
    72 
       
    73 	/**
       
    74 	 * Launch Heap Analyser application.
       
    75 	 * @param configurationFilePath
       
    76 	 * @return {@link Process#exitValue()} or {@link HeapAnalyserLauncher#KErrCommandLineLaunchingFailed} 
       
    77 	 * if an exception occurs.
       
    78 	 */
       
    79 	public static int launchHeapAnalyser( String configurationFilePath ){
       
    80 		String workingDirectory = getHeapAnalyserPath();
       
    81 		String heapAnalyserCommand = workingDirectory + "HeapAnalyser.exe";
       
    82 		
       
    83 		// surround file paths with quotation marks so that spaces in file names wont cause failure.
       
    84 		heapAnalyserCommand = surroundWithQuotation( heapAnalyserCommand ); 
       
    85 		configurationFilePath = surroundWithQuotation( configurationFilePath );
       
    86 		
       
    87 		String commandLineCommand = heapAnalyserCommand + COMMAND_LINE_COMMAND + configurationFilePath;
       
    88 	
       
    89 		int returnValue = 0;
       
    90 		
       
    91 		File file = new File(workingDirectory);
       
    92 		
       
    93 		// execute HeapAnalyser.exe
       
    94 		try {
       
    95 			DbgUtility.println(DbgUtility.PRIORITY_OPERATION, "Starting Heap Analyser: " + commandLineCommand); //$NON-NLS-N$
       
    96 			Process p = Runtime.getRuntime().exec(commandLineCommand, null, file);
       
    97 			p.waitFor();
       
    98 			returnValue = p.exitValue();
       
    99 		} 
       
   100 		catch (Exception e) {
       
   101 			return KErrCommandLineLaunchingFailed;
       
   102 		} 
       
   103 		
       
   104 		return returnValue;
       
   105 		
       
   106 		
       
   107 	}
       
   108 	
       
   109 	/**
       
   110 	 * Gets the path where HeapAnalyserConsole.exe is located
       
   111 	 * @return the path where HeapAnalyserConsole.exe is located
       
   112 	 */
       
   113 	private static String getHeapAnalyserPath() {
       
   114 		String heapAnalyserExePath = HeapAnalyserPlugin.getPluginInstallPath();
       
   115 		if (!heapAnalyserExePath.endsWith(File.separator)){
       
   116 			heapAnalyserExePath += File.separator;
       
   117 		}
       
   118 		heapAnalyserExePath += EXE_FOLDER + File.separator;
       
   119 		return heapAnalyserExePath;
       
   120 	}
       
   121 	
       
   122 	private static String surroundWithQuotation( String text ){
       
   123 		String retVal = "\"";
       
   124 		retVal = retVal + text + retVal;
       
   125 		return retVal;
       
   126 	}
       
   127 	
       
   128 	/**
       
   129 	 * Gets HeapAnalyser launcher error message.
       
   130 	 */
       
   131 	public static String getErrorMessage(int returnValue ){
       
   132 		switch(returnValue){
       
   133 			case HeapAnalyserLauncher.KErrCommandLineLaunchingFailed:{
       
   134 				return "MemSpy was unable to start analysing imported files.";
       
   135 			}
       
   136 			case HeapAnalyserLauncher.KErrCommandLineGeneral:{
       
   137 				return "Unspecified or general error";
       
   138 			}
       
   139 			case HeapAnalyserLauncher.KErrCommandLineArgumentsMissing:{
       
   140 				return "An error occurred when starting Heap Analyser.(Command line argument missing)";
       
   141 			}
       
   142 			case HeapAnalyserLauncher.KErrCommandLineInvalidCommand:{
       
   143 				return "An error occurred when starting Heap Analyser.(Input command not specified)";
       
   144 			}
       
   145 			case HeapAnalyserLauncher.KErrCommandLineArgumentsFileNotFound:{
       
   146 				return "An error occurred when starting Heap Analyser.(Input.xml file not found)";
       
   147 			}
       
   148 			case HeapAnalyserLauncher.KErrCommandLineArgumentsFileInvalid:{
       
   149 				return "An error occurred when starting Heap Analyser.(Unable to read input file. Perhaps your symbol or map files are moved/renamed. )";
       
   150 			}
       
   151 			case HeapAnalyserLauncher.KErrCommandLineSourceFileNotFound:{
       
   152 				return "An error occurred when starting Heap Analyser.(Unable to read source file)";
       
   153 			}
       
   154 			case HeapAnalyserLauncher.KErrCommandLineDebugMetaDataMissing:{
       
   155 				return "An error occurred when starting Heap Analyser.(Symbol files were not found)";
       
   156 			}
       
   157 			case HeapAnalyserLauncher.KErrCommandLineUINotAvailable:{
       
   158 				return "An error occurred when starting Heap Analyser.(Command line UI not available)";
       
   159 			}
       
   160 			case HeapAnalyserLauncher.KErrCommandLineAnalysisTypeNotSupported:{
       
   161 				return "An error occurred when starting Heap Analyser.(Analysis type not supported)";
       
   162 			}
       
   163 			case HeapAnalyserLauncher.KErrCommandLineAnalysisThreadNameInvalid:{
       
   164 				return "An error occurred when starting Heap Analyser.(Thread name invalid)";
       
   165 			}
       
   166 			case HeapAnalyserLauncher.KErrCommandLineAnalysisOutputInvalid:{
       
   167 				return "An error occurred when starting Heap Analyser.(Output file invalid)";
       
   168 			}
       
   169 			default:
       
   170 				return "An unknown error occurred when starting Heap Analyser. "
       
   171 				       + "Check software prerequisites from release notes "
       
   172 				       + "(e.g. check correct version of .NET framework is installed).";
       
   173 		}
       
   174 	}
       
   175 }