hacks/profiling/startupprofiling.cpp
branchsystem_startup
changeset 37 b8aae0a088d8
equal deleted inserted replaced
36:ec9266033bd7 37:b8aae0a088d8
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 //************************************************************************************************************
       
    17 //#include <bautils.h>
       
    18 #include <profiler.h>
       
    19 #include <e32debug.h>
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 //------------------------------------------------------------------------------------------------------------
       
    26 void startProfilerServer()
       
    27    {
       
    28 	RDebug::Print(_L("Startup Profiling - startProfilerServer()"));
       
    29 	_LIT(KParam,"");
       
    30 	RProcess p;
       
    31 	TInt err;   
       
    32 	
       
    33 	// Run the Sampling Profiler
       
    34 	err=p.Create(KProfilerName,KParam);
       
    35 	if (err == KErrNone)
       
    36 		{
       
    37 		p.Resume();
       
    38 		p.Close();
       
    39 		User::After(1000000);
       
    40 		}
       
    41 	else
       
    42 		{
       
    43 		RDebug::Print(_L("Startup Profiling - ERROR %d: Unable to execute Sampling Profiler\n"), err);
       
    44 		}
       
    45 	}
       
    46 
       
    47 
       
    48 	
       
    49 //************************************************************************************************************
       
    50 // PARSE PARAMETER
       
    51 //************************************************************************************************************
       
    52 TInt parseNumberL(TDes &aArgs, const TDesC &aParam)
       
    53    {
       
    54    TInt     pos, num, ret;
       
    55 	TBuf<100> argsTmp;
       
    56    TLex     lexArgs;	   
       
    57    
       
    58    pos = aArgs.Find(aParam);
       
    59    if (pos == KErrNotFound)
       
    60       User::Leave(KErrArgument);
       
    61 
       
    62    argsTmp.Insert(0,aArgs);
       
    63    argsTmp.Delete(0,pos + aParam.Length());
       
    64    lexArgs=argsTmp;
       
    65    ret=lexArgs.Val(num);
       
    66    
       
    67    if (ret != KErrNone)
       
    68       User::Leave(KErrArgument);
       
    69    
       
    70    return num;
       
    71    }
       
    72 
       
    73 
       
    74 
       
    75    
       
    76 //************************************************************************************************************
       
    77 //************************************************************************************************************
       
    78 //  MAIN
       
    79 //************************************************************************************************************
       
    80 //************************************************************************************************************
       
    81 void doMainL()
       
    82 	{
       
    83 	RDebug::Print(_L("Startup Profiling - doMainL"));
       
    84 
       
    85 	TBuf<100>       buf, args;
       
    86 	TInt            waittime(300000000), err;
       
    87 
       
    88    _LIT(KParamTime,	"time=");
       
    89 		
       
    90    // Get and prepare Command Line
       
    91 #ifndef __SECURE_API__
       
    92    RProcess().CommandLine(args);
       
    93 #else
       
    94    User::CommandLine(args);   
       
    95 #endif
       
    96    args.LowerCase();
       
    97    
       
    98 
       
    99    // Parse param and decide what to do  
       
   100    if (args.Find(KParamTime) != KErrNotFound) 
       
   101 		{
       
   102 		waittime  = parseNumberL(args, KParamTime);  
       
   103 		RDebug::Print(_L("Starting Profiler - Wait time requested: %d"), waittime);
       
   104 		}
       
   105 /*		
       
   106 	// ECOM should be already running on a real phone. Does not in testshell mode
       
   107 	REComSession ecom;
       
   108 	ecom.OpenL();
       
   109 	User::After(2000000);	      
       
   110 */
       
   111 	// Start the profiler server
       
   112 	startProfilerServer();
       
   113 	
       
   114 	
       
   115 	err=Profiler::Start();
       
   116 	if (err != KErrNone)
       
   117 		{
       
   118 		RDebug::Print(_L("Startup Profiling - ERROR %d : Unable to start Sampling Profiler.\n"),err);
       
   119 		User::Leave(err);
       
   120 		}
       
   121 	else
       
   122 		{
       
   123 		RDebug::Print(_L("Startup Profiling - Profiler Started OK"));
       
   124 		}
       
   125 		
       
   126 	// Now go to sleep until the alloted time (ie until we think boot-up should be complete)	
       
   127 	User::After(waittime);
       
   128 	RDebug::Print(_L("Startup Profiling - Time's Up, going to stop profiling now"));
       
   129 	
       
   130 	// Stop, close and unload the profiler properly
       
   131 	err=Profiler::Stop();
       
   132 	User::After(300000);
       
   133 	err=err | Profiler::Close();
       
   134 	User::After(300000);
       
   135 	err=err | Profiler::Unload();
       
   136 	User::After(300000);         
       
   137 	if (err != KErrNone)
       
   138 		{
       
   139 		RDebug::Print(_L("Startup Profiling - ERROR %d : Unable to Stop/Close/Unload Sampling Profiler\n"),err);
       
   140 		User::Leave(err);            
       
   141 		}
       
   142 	}
       
   143 
       
   144 
       
   145 
       
   146 //************************************************************************************************************
       
   147 //************************************************************************************************************
       
   148 // Program Entry
       
   149 //************************************************************************************************************
       
   150 //************************************************************************************************************
       
   151 GLDEF_C TInt E32Main()
       
   152 	{	
       
   153 	__UHEAP_MARK;
       
   154 	CActiveScheduler* rootScheduler = new CActiveScheduler;
       
   155 	CActiveScheduler::Install(rootScheduler);
       
   156 	CTrapCleanup* theCleanup=CTrapCleanup::New();
       
   157 
       
   158 	TRAPD(ret,doMainL());	
       
   159 	
       
   160 	delete theCleanup;	
       
   161 	delete rootScheduler;
       
   162 	__UHEAP_MARKEND;
       
   163 	return(KErrNone);
       
   164 	}