uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp
branchRCL_3
changeset 3 d8a3531bc6b8
parent 0 15bf7259bb7c
child 6 10534483575f
equal deleted inserted replaced
0:15bf7259bb7c 3:d8a3531bc6b8
    29 #include "goomconstants.hrh"
    29 #include "goomconstants.hrh"
    30 
    30 
    31 _LIT(KDummyWgName, "20");
    31 _LIT(KDummyWgName, "20");
    32 const TInt KPreallocatedSpaceForAppList = 50;
    32 const TInt KPreallocatedSpaceForAppList = 50;
    33 
    33 
       
    34 const TInt KAllowedMemUsageForApps = 50000;     //Allow upto 50K usage by app when killing apps
       
    35 
    34 const TUint KGOomTicksPerSecond = 1000;
    36 const TUint KGOomTicksPerSecond = 1000;
    35 
    37 
    36 typedef EGLBoolean (*NOK_resource_profiling)(EGLDisplay, EGLint, EGLint*, EGLint, EGLint*);
    38 typedef EGLBoolean (*NOK_resource_profiling)(EGLDisplay, EGLint, EGLint*, EGLint, EGLint*);
    37 
    39 
    38 CGOomWindowGroupList::TGOomWindowGroupProperties::TGOomWindowGroupProperties() :  iIdleTickTime(0), iDynamicPriority(EGOomPriorityNormal)
    40 CGOomWindowGroupList::TGOomWindowGroupProperties::TGOomWindowGroupProperties() :  iIdleTickTime(0), iDynamicPriority(EGOomPriorityNormal)
    76     
    78     
    77     EGLint data_count;
    79     EGLint data_count;
    78     EGLint* prof_data;
    80     EGLint* prof_data;
    79     TInt i(0);
    81     TInt i(0);
    80     RArray<TUint64> processIds;
    82     RArray<TUint64> processIds;
    81     //RArray<TUint> privMemUsed;
    83     RArray<TUint> privMemUsed;
       
    84     RArray<TUint64> systemProcessIds;
    82         
    85         
    83     EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    86     EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    84 
    87 
    85     /* Find out how much profiling data is available */
    88     /* Find out how much profiling data is available */
    86     eglQueryProfilingData(dpy, EGL_PROF_QUERY_GLOBAL_BIT_NOK|
    89     eglQueryProfilingData(dpy, EGL_PROF_QUERY_GLOBAL_BIT_NOK|
    98                                  prof_data,
   101                                  prof_data,
    99                                  data_count,
   102                                  data_count,
   100                                  &data_count);
   103                                  &data_count);
   101     
   104     
   102     /* Iterate over the returned data */
   105     /* Iterate over the returned data */
       
   106     TUint64 process_id;  
   103     while (i < data_count)
   107     while (i < data_count)
   104         {
   108         {
   105         TRACES2("RefreshL EGL_NOK_resource_profiling - index: %d data: %x", i, prof_data[i]);
   109         TRACES2("RefreshL EGL_NOK_resource_profiling - index: %d data: %x", i, prof_data[i]);
   106             
       
   107         switch (prof_data[i++])
   110         switch (prof_data[i++])
   108             {   
   111             {   
   109             case EGL_PROF_PROCESS_ID_NOK:
   112             case EGL_PROF_PROCESS_ID_NOK:
   110                 {
   113                 {
   111                 TUint64 process_id;
       
   112                 if (sizeof(EGLNativeProcessIdTypeNOK) == 8)
   114                 if (sizeof(EGLNativeProcessIdTypeNOK) == 8)
   113                     {
   115                     {
   114                     process_id = TUint64(prof_data[i]);
   116                     process_id = TUint64(prof_data[i]);
   115                     process_id += (TUint64(prof_data[i + 1]) << 32);
   117                     process_id += (TUint64(prof_data[i + 1]) << 32);
   116                     i+=2;
   118                     i+=2;
   118                 else
   120                 else
   119                     {
   121                     {
   120                     process_id = prof_data[i];
   122                     process_id = prof_data[i];
   121                     i++;
   123                     i++;
   122                     }
   124                     }
   123                 processIds.Append(process_id);
       
   124                 break;
   125                 break;
   125                 }
   126                 }
   126             case EGL_PROF_PROCESS_USED_PRIVATE_MEMORY_NOK:
   127             case EGL_PROF_PROCESS_USED_PRIVATE_MEMORY_NOK:
   127                 {
   128                 {
   128                 //TUint mem = prof_data[i];
   129                 TUint mem = prof_data[i];
   129                 //privMemUsed.Append(mem);
   130                 privMemUsed.Append(mem);
       
   131 
       
   132                 TRACES1("Memory Usage by app is %d", mem);
       
   133                 if(mem > KAllowedMemUsageForApps)
       
   134                     processIds.Append(process_id);
       
   135                 
   130                 i++;
   136                 i++;
   131                 break;
   137                 break;
   132                 }
   138                 }
   133             case EGL_PROF_PROCESS_USED_SHARED_MEMORY_NOK:
   139             case EGL_PROF_PROCESS_USED_SHARED_MEMORY_NOK:
       
   140                 {
       
   141                 TUint mem = prof_data[i];
       
   142                 TRACES1("Shared Memory Usage by app is %d", mem);
       
   143                 if(mem > KAllowedMemUsageForApps)
       
   144                     processIds.Append(process_id);
       
   145                 i++;
       
   146                 break;
       
   147                 }
   134             case EGL_PROF_USED_MEMORY_NOK:
   148             case EGL_PROF_USED_MEMORY_NOK:
   135             case EGL_PROF_TOTAL_MEMORY_NOK:
   149             case EGL_PROF_TOTAL_MEMORY_NOK:
   136             default:
   150             default:
   137                 {
   151                 {
   138                 TRACES2("RefreshL index %d, data: %d\n", i, prof_data[i]);
   152                 TRACES2("RefreshL index %d, data: %d\n", i, prof_data[i]);
   225             TInt psecid = process.SecureId();
   239             TInt psecid = process.SecureId();
   226             if(secureId == psecid)
   240             if(secureId == psecid)
   227                 {
   241                 {
   228                 found = 1;
   242                 found = 1;
   229                 process.Close();
   243                 process.Close();
   230                 TRACES2("RefreshL Process id %x, wgindex %d, using gfx memory. Added to list", psecid, index);
   244                 TRACES3("RefreshL Process id %x, wgid %d, using gfx memory %d. Added to list", psecid, iWgIds[index].iId, privMemUsed[i]);
   231                 break;
   245                 break;
   232                 }
   246                 }
   233             process.Close();
   247             process.Close();
   234             }
   248             }
   235       
   249         
   236         if(!found)
   250         if(!found)
   237             {
   251             {
   238             iWgIds.Remove(index);
   252             iWgIds.Remove(index);
   239             continue;
   253             continue;
   240             }
   254             }
   241       
   255       
       
   256         //check if it is system app
       
   257         if(iWgName->IsSystem() /*|| iWgName->Hidden()*/)
       
   258             {
       
   259             TRACES3("System/Hidden app found %x, ISystem %d, IsHidden %d",secureId, iWgName->IsSystem()?1:0, iWgName->Hidden()?1:0);  
       
   260             systemProcessIds.Append(secureId);
       
   261             }
       
   262       
       
   263         }
       
   264        
       
   265     processIds.Close();
       
   266     privMemUsed.Close();      
       
   267     
       
   268     //check if any system apps are included
       
   269     index = iWgIds.Count();
       
   270     while (index--)
       
   271         {
       
   272         TBool skipped = EFalse;
       
   273         for(i = 0; i < systemProcessIds.Count(); i++)
       
   274             {
       
   275             if(AppId(index,ETrue) == systemProcessIds[i])
       
   276                 {
       
   277                 TRACES2("WgId %d belongs to system app %x. Removing from Kill List",iWgIds[index].iId, systemProcessIds[i]);
       
   278                 iWgIds.Remove(index);
       
   279                 skipped = ETrue;
       
   280                 break;
       
   281                 }
       
   282             }
       
   283         
       
   284         if(skipped)
       
   285             continue;
       
   286         
   242         // See if there is a tick count entry for each window in the list
   287         // See if there is a tick count entry for each window in the list
   243         TGOomWindowGroupProperties* wgProperties = iWgToPropertiesMapping.Find(iWgIds[index].iId);
   288         TGOomWindowGroupProperties* wgProperties = iWgToPropertiesMapping.Find(iWgIds[index].iId);
   244         
   289         
   245         if (!wgProperties)
   290         if (!wgProperties)
   246             {
   291             {
   248             wgProperties.iIdleTickTime = User::NTickCount();
   293             wgProperties.iIdleTickTime = User::NTickCount();
   249             // If there is no idle tick entry for this window then add one
   294             // If there is no idle tick entry for this window then add one
   250             iWgToPropertiesMapping.InsertL(iWgIds[index].iId, wgProperties);
   295             iWgToPropertiesMapping.InsertL(iWgIds[index].iId, wgProperties);
   251             }
   296             }
   252         }
   297         }
   253        
   298     
   254     processIds.Close();
   299     systemProcessIds.Close();
   255     //privMemUsed.Close();       
       
   256     
   300     
   257     }
   301     }
   258 
   302 
   259 
   303 
   260 
   304 
   465 
   509 
   466 
   510 
   467 void CGOomWindowGroupList::SetPriorityBusy(TInt aWgId)
   511 void CGOomWindowGroupList::SetPriorityBusy(TInt aWgId)
   468     {
   512     {
   469     FUNC_LOG;
   513     FUNC_LOG;
   470 
       
   471     //Refresh();
       
   472     
   514     
   473     TInt parentId;
   515     TInt parentId;
   474     TRAPD(err, parentId = FindParentIdL(aWgId));
   516     TRAPD(err, parentId = FindParentIdL(aWgId));
   475     if (err)
   517     if (err)
   476         {
   518         {
   477         parentId = aWgId;
   519         parentId = aWgId;
   478         }
   520         }
   479     
   521         
   480     TRACES2("CGOomWindowGroupList::SetPriorityBusy aWgId = %d, parentId = %d", aWgId, parentId);
   522     TRACES2("CGOomWindowGroupList::SetPriorityBusy aWgId = %d, parentId = %d", aWgId, parentId);
   481     
   523         
   482     TGOomWindowGroupProperties* wgProperties = iWgToPropertiesMapping.Find(parentId);
   524     TGOomWindowGroupProperties* wgProperties = iWgToPropertiesMapping.Find(parentId);
   483     if (wgProperties)
   525     if (wgProperties)
   484         {
   526         {
   485         wgProperties->iDynamicPriority = EGOomPriorityBusy;
   527         wgProperties->iDynamicPriority = EGOomPriorityBusy;
   486         }
   528         }
   487     
   529         
   488     // If we can't find the window group then ignore it
   530     // If we can't find the window group then ignore it
   489     }
   531     }
   490 
   532 
   491 
   533 
   492 TInt CGOomWindowGroupList::FindParentIdL(TInt aWgId)
   534 TInt CGOomWindowGroupList::FindParentIdL(TInt aWgId)
   531     }
   573     }
   532 
   574 
   533 
   575 
   534 TBool CGOomWindowGroupList::IsBusy(TInt aWgIndex)
   576 TBool CGOomWindowGroupList::IsBusy(TInt aWgIndex)
   535     {
   577     {
       
   578     FUNC_LOG;
   536     if (aWgIndex < 0 || aWgIndex >= iWgIds.Count())
   579     if (aWgIndex < 0 || aWgIndex >= iWgIds.Count())
   537         {
   580         {
   538         return EFalse;
   581         return EFalse;
   539         }
   582         }
   540             
   583             
   574 
   617 
   575 void CGOomWindowGroupList::SetPriorityNormal(TInt aWgId)
   618 void CGOomWindowGroupList::SetPriorityNormal(TInt aWgId)
   576     {
   619     {
   577     FUNC_LOG;
   620     FUNC_LOG;
   578 
   621 
   579     //Refresh();
       
   580     
       
   581     TInt parentId;
   622     TInt parentId;
   582     TRAPD(err, parentId = FindParentIdL(aWgId));
   623     TRAPD(err, parentId = FindParentIdL(aWgId));
   583     if (err)
   624     if (err)
   584         {
   625         {
   585         parentId = aWgId;
   626         parentId = aWgId;
   597 
   638 
   598 void CGOomWindowGroupList::SetPriorityHigh(TInt aWgId)
   639 void CGOomWindowGroupList::SetPriorityHigh(TInt aWgId)
   599     {
   640     {
   600     FUNC_LOG;
   641     FUNC_LOG;
   601 
   642 
   602     //Refresh();
       
   603 
       
   604     TInt parentId;
   643     TInt parentId;
   605     TRAPD(err, parentId = FindParentIdL(aWgId));
   644     TRAPD(err, parentId = FindParentIdL(aWgId));
   606     if (err)
   645     if (err)
   607         {
   646         {
   608         parentId = aWgId;
   647         parentId = aWgId;
   637     if (!appFoundInWindowGroupList)
   676     if (!appFoundInWindowGroupList)
   638         indexInGroupList = KAppNotInWindowGroupList;
   677         indexInGroupList = KAppNotInWindowGroupList;
   639 
   678 
   640     return indexInGroupList;
   679     return indexInGroupList;
   641     }
   680     }
       
   681 
       
   682 // Find the specificed application in the window group list and return the index
       
   683 TInt CGOomWindowGroupList::GetIndexFromWgId(TInt aWgId) const
       
   684     {
       
   685     FUNC_LOG;
       
   686 
       
   687     TInt indexInGroupList = Count();
       
   688     TBool appFoundInWindowGroupList = EFalse;
       
   689     
       
   690     while (indexInGroupList--)
       
   691         {
       
   692         if (iWgIds[indexInGroupList].iId == aWgId)
       
   693             {
       
   694             appFoundInWindowGroupList = ETrue;
       
   695             break;
       
   696             }
       
   697         }
       
   698     
       
   699     if (!appFoundInWindowGroupList)
       
   700         indexInGroupList = KAppNotInWindowGroupList;
       
   701 
       
   702     return indexInGroupList;
       
   703     }
       
   704 
       
   705 void CGOomWindowGroupList::GetAllWgIdsMatchingAppId(TInt aWgId, RArray<TInt> & WgIdList) const
       
   706     {
       
   707     TInt32 appId = AppIdfromWgId(aWgId, ETrue);
       
   708     TInt indexInGroupList = Count();
       
   709     WgIdList.Reset();
       
   710     
       
   711     while (indexInGroupList--)
       
   712         {
       
   713         if (AppIdfromWgId(iWgIds[indexInGroupList].iId, ETrue) == appId)
       
   714             {
       
   715             WgIdList.Append(iWgIds[indexInGroupList].iId);
       
   716             }
       
   717         }
       
   718     }