os/kernelhwsrv/kerneltest/e32utils/analyse/ProcessCfg.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 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 #include <windows.h>
    18 #include "analyse.h"
    19 #include "nonxip.h"
    20 
    21 
    22 extern NonXIP gNonXIP;
    23 
    24 const char* COMMON_SECT="Common";
    25 const char* PROFILE_SECT="Profile";
    26 const char* PARTITION_SECT="Partition";
    27 const char* FORMAT_SECT="Format";
    28 const char* NON_XIP_SECT="NonXIP";
    29 
    30 std::string Analyse::iRomFile;
    31 std::string Analyse::iThread;
    32 std::string Analyse::iDll;
    33 std::string Analyse::iFunction;
    34 std::vector<std::string> Analyse::iTraces;
    35 
    36 int Analyse::ProcessCfgFile(const char* aCfgFileName)
    37 	{
    38 	char buf[1024];
    39 	char path[MAX_PATH];
    40 	if (aCfgFileName[0] != '\\' || aCfgFileName[1] != ':')
    41 		{
    42 		char ** file_name = 0;
    43 		if (!GetFullPathNameA(aCfgFileName, sizeof path, path, file_name))
    44 			return ENoCfgFile;
    45 		aCfgFileName = path;
    46 		}
    47 
    48 	if (GetFileAttributesA(aCfgFileName) == 0xffffffff) // no ini file
    49 		return ENoCfgFile;
    50 	int rc = GetPrivateProfileStringA(COMMON_SECT, "TraceFile", "", buf, sizeof buf, aCfgFileName);
    51 	if (rc)
    52 		{
    53 		iTraces.push_back(buf);
    54 		sTraces.push_back(iTraces[iTraces.size()-1].c_str());
    55 		}
    56 
    57 	GetPrivateProfileStringA(COMMON_SECT, "Mode", "profile", buf, sizeof buf, aCfgFileName);
    58 	switch(buf[0])
    59 		{
    60 	case 'l': case 'L':
    61 		sAction = ETrace;
    62 		break;
    63 	case 'p': case 'P':
    64 		sAction = EProfile;
    65 		break;
    66 	case 'a': case 'A':
    67 		sAction = EActivity;
    68 		break;
    69 	default:
    70 		return EErrorCfgFile;
    71 		}
    72 
    73 	rc = GetPrivateProfileStringA(COMMON_SECT, "SymbolFile", "", buf, sizeof buf, aCfgFileName);
    74 	if (rc) 
    75 		{
    76 		iRomFile = buf;
    77 		sRomFile = iRomFile.c_str();
    78 		}
    79 
    80 	rc = GetPrivateProfileStringA(COMMON_SECT, "Range", "", buf, sizeof buf, aCfgFileName);
    81 	if (rc) 
    82 		{
    83 		sOptions |= ERange;
    84 		bool plus = false;
    85 		char * p = strrchr(buf, '+');
    86 		if (p)
    87 			plus = true;
    88 		else
    89 			p = strrchr(buf, '-');
    90 		if (!p) return EErrorCfgFile;
    91 		*p = '\0';
    92 		sBeginSample = atoi(buf);
    93 		sEndSample = atoi(++p);
    94 		if (plus) 
    95 			sEndSample = sEndSample += sBeginSample;
    96 		}
    97 
    98 	rc = GetPrivateProfileIntA(COMMON_SECT, "IncludeNullThread", 0, aCfgFileName);
    99 	if (rc) 
   100 		sOptions|=ENull;
   101 	
   102 	rc = GetPrivateProfileStringA(COMMON_SECT, "Cutoff", "", buf, sizeof buf, aCfgFileName);
   103 	if (rc) 
   104 		sCutOff = atof(buf);
   105 
   106 
   107 	rc = GetPrivateProfileStringA(PROFILE_SECT, "Thread", "", buf, sizeof buf, aCfgFileName);
   108 	if (rc) 
   109 		{
   110 		iThread = buf;
   111 		sThread = iThread.c_str();
   112 		}
   113 
   114 	rc = GetPrivateProfileStringA(PROFILE_SECT, "Dll", "", buf, sizeof buf, aCfgFileName);
   115 	if (rc) 
   116 		{
   117 		iDll = buf;
   118 		sDll = iDll.c_str();
   119 		}
   120 
   121 	rc = GetPrivateProfileStringA(PROFILE_SECT, "Function", "", buf, sizeof buf, aCfgFileName);
   122 	if (rc) 
   123 		{
   124 		iFunction = buf;
   125 		sFunction = iFunction.c_str();
   126 		}
   127 
   128 	rc = GetPrivateProfileStringA(PROFILE_SECT, "Range", "", buf, sizeof buf, aCfgFileName);
   129 	if (rc) 
   130 		{
   131 		sOptions |= EAddress;
   132 		bool plus = false;
   133 		char * p = strrchr(buf, '+');
   134 		if (p)
   135 			plus = true;
   136 		else
   137 			p = strrchr(buf, '-');
   138 		if (!p) return EErrorCfgFile;
   139 		*p = '\0';
   140 		sBase = strtoul(buf,0,16);
   141 		sLim = strtoul(++p,0,16);
   142 		if (plus) 
   143 			sLim = sLim += sBase;
   144 		}
   145 	
   146 
   147 	rc = GetPrivateProfileStringA(PARTITION_SECT, "Mode", "", buf, sizeof buf, aCfgFileName);
   148 	if (rc)
   149 		{
   150 		switch(buf[0])
   151 			{
   152 		case 'd': case 'D':
   153 			sPartition = EDll;
   154 			break;
   155 		case 'f': case 'F':
   156 			sPartition = EFunction;
   157 			break;
   158 		default:
   159 			return EErrorCfgFile;
   160 			}
   161 		}
   162 
   163 	rc = GetPrivateProfileIntA(PARTITION_SECT, "BucketSize", 0, aCfgFileName);
   164 	if (rc)
   165 		{
   166 		sPartition = ESize;
   167 		sBucketSize = rc;
   168 		}
   169 
   170 	rc = GetPrivateProfileIntA(PARTITION_SECT, "NumberOfBuckets", 0, aCfgFileName);
   171 	if (rc)
   172 		{
   173 		sPartition = EBuckets;
   174 		sBuckets = rc;
   175 		}
   176 
   177 
   178 
   179 	rc = GetPrivateProfileStringA(FORMAT_SECT, "Mode", "", buf, sizeof buf, aCfgFileName);
   180 	if (rc)
   181 		{
   182 		switch(buf[0])
   183 			{
   184 		case 'p': case 'P':
   185 			sFormat = EPercent;
   186 			break;
   187 		case 's': case 'S':
   188 			sFormat = ESamples;
   189 			break;
   190 		case 'e': case 'E':
   191 			sFormat = EExcel;
   192 			break;
   193 		default:
   194 			return EErrorCfgFile;
   195 			}
   196 		}
   197 
   198 	rc = GetPrivateProfileIntA(FORMAT_SECT, "ZeroValues", 0, aCfgFileName);
   199 	if (rc)
   200 		sOptions |= EZeros;
   201 
   202 	rc = GetPrivateProfileIntA(FORMAT_SECT, "NoOthers", 0, aCfgFileName);
   203 	if (rc)
   204 		sOptions |= ENoOther;
   205 
   206 	rc = GetPrivateProfileIntA(FORMAT_SECT, "TotalOnly", 0, aCfgFileName);
   207 	if (rc)
   208 		sOptions |= ETotalOnly;
   209 
   210 
   211 	char key[256];
   212 	for(int i=1;sprintf(key,"ObyFile%d",i),
   213 		GetPrivateProfileStringA(NON_XIP_SECT, key, "", buf, sizeof buf, aCfgFileName);i++)
   214 		gNonXIP.AddObyFile(buf);
   215 
   216 	for(i=1;sprintf(key,"RofsSymbolFile%d",i),
   217 		GetPrivateProfileStringA(NON_XIP_SECT, key, "", buf, sizeof buf, aCfgFileName);i++)
   218 		gNonXIP.AddSymbolFile(buf);
   219 
   220 	return EOk;
   221 	}
   222