loadgen/engine/src/loadgen_utils.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     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 "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 // INCLUDE FILES
       
    20 #include <e32math.h> 
       
    21 #include <u32hal.h>
       
    22 #include <hal.h> 
       
    23 
       
    24 #include "loadgen_utils.h"
       
    25 #include "loadgen.hrh"
       
    26 
       
    27 inline TInt64 INIT_SEED()
       
    28 {
       
    29     TTime now; 
       
    30     now.HomeTime(); 
       
    31     return now.Int64();
       
    32 }
       
    33 
       
    34 TInt64 CLoadGenUtils::iRandomNumberSeed = INIT_SEED();
       
    35 
       
    36 TThreadPriority CLoadGenUtils::SettingItemToThreadPriority(TInt aIndex)
       
    37     {
       
    38     TThreadPriority threadPriority = EPriorityNull;
       
    39     
       
    40     switch ( aIndex )
       
    41         {
       
    42         case EThreadPriorityTypeMuchLess:
       
    43             {
       
    44             threadPriority = EPriorityMuchLess; break;
       
    45             }
       
    46         case EThreadPriorityTypeLess:
       
    47             {
       
    48             threadPriority = EPriorityLess; break;
       
    49             }
       
    50         case EThreadPriorityTypeNormal:
       
    51             {
       
    52             threadPriority = EPriorityNormal; break;
       
    53             }
       
    54         case EThreadPriorityTypeMore:
       
    55             {
       
    56             threadPriority = EPriorityMore; break;
       
    57             }
       
    58         case EThreadPriorityTypeMuchMore:
       
    59             {
       
    60             threadPriority = EPriorityMuchMore; break;
       
    61             }
       
    62         case EThreadPriorityTypeRealTime:
       
    63             {
       
    64             threadPriority = EPriorityRealTime; break;
       
    65             }
       
    66         case EThreadPriorityTypeAbsoluteVeryLow:
       
    67             {
       
    68             threadPriority = EPriorityAbsoluteVeryLow; break;
       
    69             }
       
    70         case EThreadPriorityTypeAbsoluteLow:
       
    71             {
       
    72             threadPriority = EPriorityAbsoluteLow; break;
       
    73             }
       
    74         case EThreadPriorityTypeAbsoluteBackground:
       
    75             {
       
    76             threadPriority = EPriorityAbsoluteBackground; break;
       
    77             }
       
    78         case EThreadPriorityTypeAbsoluteForeground:
       
    79             {
       
    80             threadPriority = EPriorityAbsoluteForeground; break;
       
    81             }
       
    82         case EThreadPriorityTypeAbsoluteHigh:
       
    83             {
       
    84             threadPriority = EPriorityAbsoluteHigh; break;
       
    85             }
       
    86 
       
    87         default:
       
    88             {
       
    89             User::Panic(_L("Wrong tp index"), 276);
       
    90             break;
       
    91             }
       
    92         }
       
    93 
       
    94     return threadPriority;
       
    95     }
       
    96 
       
    97 // --------------------------------------------------------------------------------------------
       
    98 
       
    99 void CLoadGenUtils::SettingItemToThreadDescription(TInt aIndex, TDes& aBuf)
       
   100     {
       
   101     switch ( aIndex )
       
   102         {
       
   103         case EThreadPriorityTypeMuchLess:
       
   104             {
       
   105             aBuf.Append(_L("ML(-20)")); break;
       
   106             }
       
   107         case EThreadPriorityTypeLess:
       
   108             {
       
   109             aBuf.Append(_L("L(-10)")); break;
       
   110             }
       
   111         case EThreadPriorityTypeNormal:
       
   112             {
       
   113             aBuf.Append(_L("NO(0)")); break;
       
   114             }
       
   115         case EThreadPriorityTypeMore:
       
   116             {
       
   117             aBuf.Append(_L("M(10)")); break;
       
   118             }
       
   119         case EThreadPriorityTypeMuchMore:
       
   120             {
       
   121             aBuf.Append(_L("MM(20)")); break;
       
   122             }
       
   123         case EThreadPriorityTypeRealTime:
       
   124             {
       
   125             aBuf.Append(_L("RL(30)")); break;
       
   126             }
       
   127         case EThreadPriorityTypeAbsoluteVeryLow:
       
   128             {
       
   129             aBuf.Append(_L("AVL(100)")); break;
       
   130             }
       
   131         case EThreadPriorityTypeAbsoluteLow:
       
   132             {
       
   133             aBuf.Append(_L("AL(200)")); break;
       
   134             }
       
   135         case EThreadPriorityTypeAbsoluteBackground:
       
   136             {
       
   137             aBuf.Append(_L("ABG(300)")); break;
       
   138             }
       
   139         case EThreadPriorityTypeAbsoluteForeground:
       
   140             {
       
   141             aBuf.Append(_L("AFG(400)")); break;
       
   142             }
       
   143         case EThreadPriorityTypeAbsoluteHigh:
       
   144             {
       
   145             aBuf.Append(_L("AH(500)")); break;
       
   146             }
       
   147 
       
   148         default:
       
   149             {
       
   150             User::Panic(_L("Wrong td index"), 277);
       
   151             break;
       
   152             }
       
   153         }
       
   154     }
       
   155 
       
   156 // --------------------------------------------------------------------------------------------
       
   157 
       
   158 void CLoadGenUtils::SettingItemToSourceDescription(TInt aIndex, TDes& aBuf)
       
   159     {
       
   160     switch ( aIndex )
       
   161         {
       
   162         case EMemoryEatSourceTypeRAM:
       
   163             {
       
   164             aBuf.Append(_L("RAM")); break;
       
   165             }
       
   166         case EMemoryEatSourceTypeDriveC:
       
   167             {
       
   168             aBuf.Append(_L("C:")); break;
       
   169             }
       
   170         case EMemoryEatSourceTypeDriveD:
       
   171             {
       
   172             aBuf.Append(_L("D:")); break;
       
   173             }            
       
   174         case EMemoryEatSourceTypeDriveE:
       
   175             {
       
   176             aBuf.Append(_L("E:")); break;
       
   177             }            
       
   178         case EMemoryEatSourceTypeDriveF:
       
   179             {
       
   180             aBuf.Append(_L("F:")); break;
       
   181             }            
       
   182         case EMemoryEatSourceTypeDriveG:
       
   183             {
       
   184             aBuf.Append(_L("G:")); break;
       
   185             }            
       
   186         case EMemoryEatSourceTypeDriveH:
       
   187             {
       
   188             aBuf.Append(_L("H:")); break;
       
   189             }            
       
   190         case EMemoryEatSourceTypeDriveI:
       
   191             {
       
   192             aBuf.Append(_L("I:")); break;
       
   193             }            
       
   194         case EMemoryEatSourceTypeDriveJ:
       
   195             {
       
   196             aBuf.Append(_L("J:")); break;
       
   197             }            
       
   198         case EMemoryEatSourceTypeDriveK:
       
   199             {
       
   200             aBuf.Append(_L("K:")); break;
       
   201             }            
       
   202         case EMemoryEatSourceTypeDriveL:
       
   203             {
       
   204             aBuf.Append(_L("L:")); break;
       
   205             }            
       
   206         case EMemoryEatSourceTypeDriveM:
       
   207             {
       
   208             aBuf.Append(_L("M:")); break;
       
   209             }            
       
   210         case EMemoryEatSourceTypeDriveN:
       
   211             {
       
   212             aBuf.Append(_L("N:")); break;
       
   213             }            
       
   214 
       
   215         default:
       
   216             {
       
   217             User::Panic(_L("Wrong src index"), 278);
       
   218             break;
       
   219             }
       
   220         }
       
   221     }
       
   222         
       
   223 // --------------------------------------------------------------------------------------------
       
   224 
       
   225 TInt CLoadGenUtils::MilliSecondsToMicroSeconds(TInt aMilliSeconds, TInt aRandomVariance)
       
   226     {
       
   227     __ASSERT_ALWAYS(aRandomVariance >= 0 && aRandomVariance <= 100, User::Panic(_L("Inv.var."), 180));
       
   228     __ASSERT_ALWAYS(aMilliSeconds >=0, User::Panic(_L("Inv.ms."), 181));
       
   229     
       
   230     // if no variance defined, just do a quick conversion
       
   231     if (aRandomVariance == 0 || aMilliSeconds == 0)
       
   232         return aMilliSeconds * 1000;
       
   233     
       
   234     // otherwise calculate difference
       
   235     TInt diff = 1000 * aMilliSeconds / 2 * aRandomVariance / 100;  
       
   236     
       
   237     return RandomNumber(aMilliSeconds*1000-diff, aMilliSeconds*1000+diff);
       
   238     }
       
   239 
       
   240 // --------------------------------------------------------------------------------------------
       
   241 
       
   242 TInt CLoadGenUtils::RandomNumber(TInt aMin, TInt aMax)
       
   243     {
       
   244     TInt range = (aMax > aMin ? aMax - aMin : aMin - aMax) + 1;
       
   245     TInt random = (TInt) (range * Math::FRand(iRandomNumberSeed));
       
   246     
       
   247     random = (random % range) + aMin;
       
   248 
       
   249     if (random > aMax)
       
   250         random = aMax;
       
   251     else if (random < aMin)
       
   252         random = aMin;
       
   253     
       
   254     return random;
       
   255     }
       
   256 
       
   257 // --------------------------------------------------------------------------------------------
       
   258 
       
   259 TSize CLoadGenUtils::ScreenSize()
       
   260     {    
       
   261     TInt x = 0;
       
   262     TInt y = 0;
       
   263     HAL::Get(HALData::EDisplayXPixels, x);
       
   264     HAL::Get(HALData::EDisplayYPixels, y);
       
   265     return TSize(x, y);
       
   266     }