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