# HG changeset patch # User hgs # Date 1278417360 -10800 # Node ID dd05fdd05078550836a5a7c0010c3723652e684c # Parent 69409653e8637c05b7518aad0f0d4af0e2c9c0c9 201027 diff -r 69409653e863 -r dd05fdd05078 uiacceltk/hitchcock/goommonitor/inc/goomactionlist.h --- a/uiacceltk/hitchcock/goommonitor/inc/goomactionlist.h Tue Jun 22 12:40:35 2010 +0300 +++ b/uiacceltk/hitchcock/goommonitor/inc/goomactionlist.h Tue Jul 06 14:56:00 2010 +0300 @@ -225,6 +225,10 @@ void ConstructL(CGOomConfig& aConfig); + TBool IsOkToKillApp(TInt aAppId); + + TBool AppCloseActionAlreadyExists(CGOomWindowGroupList& aWindowGroupList, TInt32 appId); + private: //data RWsSession& iWs; diff -r 69409653e863 -r dd05fdd05078 uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp --- a/uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp Tue Jun 22 12:40:35 2010 +0300 +++ b/uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp Tue Jul 06 14:56:00 2010 +0300 @@ -230,6 +230,8 @@ */ iRunningKillAppActions = ETrue; + TInt oldcount = iActionRefs.Count(); + if (aWindowGroupList.Count()) { // Go through each item in the wglist, create an app close action for this application @@ -252,6 +254,12 @@ // This sets the window group name TInt32 appId = aWindowGroupList.AppId(wgIndex, ETrue); + if(AppCloseActionAlreadyExists(aWindowGroupList, appId)) + { + wgIndex--; + continue; + } + CApaWindowGroupName* wgName = aWindowGroupList.WgName(); __ASSERT_DEBUG(wgName, GOomMonitorPanic(KInvalidWgName)); @@ -314,10 +322,24 @@ } } - TRACES1("BuildActionListL: Action list built with %d items",iActionRefs.Count()); + TRACES1("BuildActionListL: Action list built with %d new items",iActionRefs.Count()- oldcount); } +TBool CGOomActionList::AppCloseActionAlreadyExists(CGOomWindowGroupList& aWindowGroupList, TInt32 appId) + { + for(TInt i = 0 ; i < iActionRefs.Count() ; i++) + { + TActionRef ref = iActionRefs[i]; + if(ref.Type() == TActionRef::EAppClose ) + { + if(aWindowGroupList.AppIdfromWgId(ref.WgId(), ETrue) == appId) + return ETrue; + } + } + return EFalse; + } + // Execute the OOM actions according to their priority // Run batches of OOM actions according to their sync mode void CGOomActionList::FreeMemory(TInt aMaxPriority) @@ -364,48 +386,9 @@ ref.iAppPlugin = action; - //Double checking again if this app is now in foreground, if yes then we dont kill - CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(iWs, iWs.GetFocusWindowGroup()); - - TInt32 fgApp = wgName->AppUid().iUid; TInt32 appId = iMonitor.GetWindowGroupList()->AppIdfromWgId(ref.WgId(), ETrue); - - if(appId == fgApp) - { - TRACES1("Foreground App wgid %x, spared by GOOM", appId); - - iCurrentActionIndex++; - CleanupStack::PopAndDestroy(); - continue; - } - //check if this is not parent of foreground app - TBool spared = EFalse; - TRACES1("CGOomActionList::FreeMemory - Going to kill Appid %x ",appId); - TInt prevWgId = 0; - while(prevWgId != KErrNotFound) - { - wgName->FindByAppUid(wgName->AppUid(), iWs, prevWgId); - - if(prevWgId == KErrNotFound) - break; - - TInt parentId = 0; - TRAPD(err, parentId = iMonitor.GetWindowGroupList()->FindParentIdL(prevWgId)); - TRACES2("CGOomActionList::FreeMemory - Foreground App wgid %d, parent wgid %d",prevWgId, parentId); - if( err == KErrNone && parentId != 0) - { - TInt32 parentAppId = iMonitor.GetWindowGroupList()->AppIdfromWgId(parentId, ETrue); - if(parentAppId == appId) - { - TRACES3("Parent App %x (wgId %d), of Foreground App %x, spared by GOOM", parentAppId, parentId, fgApp); - spared = ETrue; - break; - } - } - } - CleanupStack::PopAndDestroy(); - if(spared) + if(!IsOkToKillApp(appId)) { iCurrentActionIndex++; if (iCurrentActionIndex >= iActionRefs.Count()) @@ -427,6 +410,7 @@ iFreeingMemory = ETrue; TRACES2("CGOomActionList::FreeMemory: Running action %d which has priority %d", iCurrentActionIndex,ref.Priority()); + iCurrentActionIndex++; action->FreeMemory(iCurrentTarget - memoryEstimate, iUseSwRendering); iCurrentPluginRun = 0; memoryFreeingActionRun = ETrue; @@ -449,18 +433,16 @@ if ((ref.SyncMode() == ECheckRam) || (numberOfRunningActions >= maxBatchSize) || estimatedEnoughMemoryFreed - || globalConfig.ForceCheckAtPriority(iActionRefs[iCurrentActionIndex].Priority())) + || globalConfig.ForceCheckAtPriority(iActionRefs[iCurrentActionIndex-1].Priority())) // If this actions requires a RAM check then wait for it to complete // Also force a check if we've reached the maximum number of concurrent operations // Also check if we estimate that we have already freed enough memory (assuming that the sync mode is "estimate" { // Return from the loop - we will be called back (in CGOomActionList::StateChanged()) when the running actions complete - iCurrentActionIndex++; TRACES("CGOomActionList::FreeMemory: Exiting run action loop"); return; } // ... otherwise continue running actions, don't wait for any existing ones to complete - iCurrentActionIndex++; if (iCurrentActionIndex >= iActionRefs.Count()) { @@ -493,6 +475,55 @@ } } +TBool CGOomActionList::IsOkToKillApp(TInt aAppId) + { + + //Double checking again if this app is now in foreground, if yes then we dont kill + TUid fgAppuid = TUid::Uid(iMonitor.ForegroundAppUid()); + TInt32 fgApp = fgAppuid.iUid; + TRACES1("Foreground Appuid %x", fgApp); + + if (aAppId == fgApp) + { + TRACES1("Foreground App wgid %x, spared by GOOM", aAppId); + return EFalse; + } + + //check if this is not parent of foreground app + TBool spared = EFalse; + TRACES2("CGOomActionList::FreeMemory - Going to kill Appid %x, Foreground app %x ", aAppId, fgApp); + TInt prevWgId = 0; + + CApaWindowGroupName::FindByAppUid(fgAppuid, iWs, prevWgId); + TInt i = 0; + while ((prevWgId == KErrNotFound) && (i++ < 3)) //try 3 times before quiting. It takes time to get the wgid info when app is starting + { + TRACES1("Cannot find any more parent, trying again %d",i); + User::After(200000); + prevWgId = 0; + CApaWindowGroupName::FindByAppUid(fgAppuid, iWs, prevWgId); + } + + while (prevWgId != KErrNotFound) + { + TInt parentId = 0; + TRAPD(err, parentId = iMonitor.GetWindowGroupList()->FindParentIdL(prevWgId)); + TRACES3("CGOomActionList::FreeMemory - Foreground App AppId %x, wgid %d, parent wgid %d", fgApp, prevWgId, parentId); + if (err == KErrNone && parentId > 0) + { + TInt32 parentAppId = iMonitor.GetWindowGroupList()->AppIdfromWgId(parentId, ETrue); + if (parentAppId == aAppId) + { + TRACES3("Parent App %x (wgId %d), of Foreground App %x, spared by GOOM", parentAppId, parentId, fgApp); + spared = ETrue; + break; + } + } + CApaWindowGroupName::FindByAppUid(fgAppuid, iWs, prevWgId); + } + return !spared; + } + // Should be called when the memory situation is good // It results in notifications of the good memory state to all plugins with an outstanding FreeMemory request void CGOomActionList::MemoryGood() diff -r 69409653e863 -r dd05fdd05078 uiacceltk/hitchcock/goommonitor/src/goomcloseapp.cpp --- a/uiacceltk/hitchcock/goommonitor/src/goomcloseapp.cpp Tue Jun 22 12:40:35 2010 +0300 +++ b/uiacceltk/hitchcock/goommonitor/src/goomcloseapp.cpp Tue Jul 06 14:56:00 2010 +0300 @@ -153,6 +153,7 @@ // Start a timer and the thread watcher iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppClosing); iAppCloseTimer->After(iCloseTimeout * 1000); + iAppCloseWatcher->Start(iCurrentTask); // Tell the app to close // We are not asking system applications to exit anyway, so we'll send legacy event only // even we have powermgmt capability @@ -184,7 +185,8 @@ } if(IsConsumingMemory(iWgId)) - { + { + TRACES1("REST IN PEACE - App wgid %d", iWgId); iCurrentTask.KillTask(); iAppCloserRunning = EFalse; // not sure if intended (?) iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled); @@ -192,9 +194,10 @@ } else { // application has released its graphics resources -> we are no more interested about it - CloseAppEvent(); + //CloseAppEvent(); + iAppCloserRunning = EFalse; + MemoryFreed(KErrNone); } - //MemoryFreed(KErrNone); } void CGOomCloseApp::KillTaskWaitDone() diff -r 69409653e863 -r dd05fdd05078 uiacceltk/hitchcock/goommonitor/src/goommemorymonitor.cpp --- a/uiacceltk/hitchcock/goommonitor/src/goommemorymonitor.cpp Tue Jun 22 12:40:35 2010 +0300 +++ b/uiacceltk/hitchcock/goommonitor/src/goommemorymonitor.cpp Tue Jul 06 14:56:00 2010 +0300 @@ -612,6 +612,7 @@ /* Allocate room for the profiling data */ prof_data = (EGLint*)User::Alloc(data_count * sizeof(EGLint)); + TRACES("eglQueryProfilingData - alloc for data done"); if (prof_data == NULL) { TRACES1("eglQueryProfilingData - could not alloc: %d", data_count * sizeof(EGLint)); @@ -625,7 +626,9 @@ prof_data, data_count, &data_count); - + + TRACES("eglQueryProfilingData - profiling data acquired"); + /* Iterate over the returned data */ while (i < data_count) { diff -r 69409653e863 -r dd05fdd05078 uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp --- a/uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp Tue Jun 22 12:40:35 2010 +0300 +++ b/uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp Tue Jul 06 14:56:00 2010 +0300 @@ -231,6 +231,7 @@ processIds.Close(); privMemUsed.Close(); TRACES("Only WServ using GFX mem, no need for app actions"); + iWgIds.Reset(); return; } } diff -r 69409653e863 -r dd05fdd05078 uiacceltk/hitchcock/plugins/alfoogmplugin/src/alfoogmplugin.cpp --- a/uiacceltk/hitchcock/plugins/alfoogmplugin/src/alfoogmplugin.cpp Tue Jun 22 12:40:35 2010 +0300 +++ b/uiacceltk/hitchcock/plugins/alfoogmplugin/src/alfoogmplugin.cpp Tue Jul 06 14:56:00 2010 +0300 @@ -90,10 +90,16 @@ // TAny* CreatePlugin() { - CAlfOogmMonitorPlugin* plugin = new(ELeave) CAlfOogmMonitorPlugin; - CleanupStack::PushL(plugin); - plugin->ConstructL(); - CleanupStack::Pop(plugin); + CAlfOogmMonitorPlugin* plugin = new CAlfOogmMonitorPlugin; + if ( plugin ) + { + TRAPD( err, plugin->ConstructL() ); + if ( err != KErrNone ) + { + delete plugin; + plugin = NULL; + } + } return plugin; }