perfsrv/piprofiler/plugins/PWRplugin/src/PwrPlugin.cpp
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
equal deleted inserted replaced
56:aa2539c91954 62:1c2bb2fc7c87
    17 
    17 
    18 #include "PwrPlugin.h"
    18 #include "PwrPlugin.h"
    19 #include <piprofiler/ProfilerTraces.h>
    19 #include <piprofiler/ProfilerTraces.h>
    20 
    20 
    21 #include <centralrepository.h>
    21 #include <centralrepository.h>
    22 #include <HWRMPower.h>
    22 #include <hwrmpower.h>
    23 #include <HWRMLight.h>
    23 #include <hwrmlight.h>
    24 #include <hwrm/hwrmpowerdomaincrkeys.h>
    24 #include <hwrm/hwrmpowerdomaincrkeys.h>
    25 
    25 
    26 
    26 
    27 // texts for notes
    27 // texts for notes
    28 _LIT(KPowerTextLine1, "Power sampler:");
    28 _LIT(KPowerTextLine1, "Power sampler:");
   322     iPwrSamplingPeriod(0),
   322     iPwrSamplingPeriod(0),
   323     iOriginalReportingPeriod(0),
   323     iOriginalReportingPeriod(0),
   324     iNominalCapa(0),
   324     iNominalCapa(0),
   325     iVoltage(0), 
   325     iVoltage(0), 
   326     iCurrent(0),
   326     iCurrent(0),
   327     iPowerAPI(0)
   327     iPowerAPI(0),
   328 #ifdef PWR_SAMPLER_BACKLIGHT
   328     iLightAPI(0),
   329     ,iLightAPI(0),
       
   330     iBackLightStatus(CHWRMLight::ELightStatusUnknown)
   329     iBackLightStatus(CHWRMLight::ELightStatusUnknown)
   331 #endif
       
   332 
   330 
   333     {
   331     {
   334     LOGTEXT(_L("CProfilerPowerListener::CProfilerPowerListener() - konstuktori"));
   332     LOGTEXT(_L("CProfilerPowerListener::CProfilerPowerListener() - konstuktori"));
   335     this->iSampler = aSampler;
   333     this->iSampler = aSampler;
   336     LOGTEXT(_L("CProfilerPowerListener::CProfilerPowerListener() - konstuktori exit"));
   334     LOGTEXT(_L("CProfilerPowerListener::CProfilerPowerListener() - konstuktori exit"));
   361     if (iPowerAPI)
   359     if (iPowerAPI)
   362         {
   360         {
   363         delete iPowerAPI;
   361         delete iPowerAPI;
   364         iPowerAPI = 0;
   362         iPowerAPI = 0;
   365         }
   363         }
   366 #ifdef PWR_SAMPLER_BACKLIGHT
   364 
   367     if (iLightAPI)
   365     if (iLightAPI)
   368         {
   366         {
   369         delete iLightAPI;
   367         delete iLightAPI;
   370         iLightAPI = 0;
   368         iLightAPI = 0;
   371         }
   369         }
   372 #endif
       
   373 
   370 
   374     LOGTEXT(_L("CProfilerPowerListener::~CProfilerPowerListener() - exit"));
   371     LOGTEXT(_L("CProfilerPowerListener::~CProfilerPowerListener() - exit"));
   375     }
   372     }
   376 
   373 
   377 TInt CProfilerPowerListener::DisplayNotifierL(const TDesC& aLine1, const TDesC& aLine2, const TDesC& aButton1, const TDesC& aButton2)
   374 TInt CProfilerPowerListener::DisplayNotifierL(const TDesC& aLine1, const TDesC& aLine2, const TDesC& aButton1, const TDesC& aButton2)
   427     iPowerAPI = CHWRMPower::NewL();
   424     iPowerAPI = CHWRMPower::NewL();
   428     iPowerAPI->SetPowerReportObserver(this);
   425     iPowerAPI->SetPowerReportObserver(this);
   429 
   426 
   430     // Read HWRM reporting settings from central repository
   427     // Read HWRM reporting settings from central repository
   431     CRepository* centRep = CRepository::NewL(KCRUidPowerSettings);
   428     CRepository* centRep = CRepository::NewL(KCRUidPowerSettings);
       
   429     CleanupStack::PushL( centRep );
       
   430 
   432     TInt baseInterval(0);
   431     TInt baseInterval(0);
   433     User::LeaveIfError(centRep->Get(KPowerBaseTimeInterval, baseInterval));
   432     User::LeaveIfError(centRep->Get(KPowerBaseTimeInterval, baseInterval));
   434     User::LeaveIfError(centRep->Get(KPowerMaxReportingPeriod, iOriginalReportingPeriod));
   433     User::LeaveIfError(centRep->Get(KPowerMaxReportingPeriod, iOriginalReportingPeriod));
   435 
   434 
   436     LOGSTRING2("CProfilerPowerListener::StartL() - HWRM base power report interval: %d", baseInterval);
   435     LOGSTRING2("CProfilerPowerListener::StartL() - HWRM base power report interval: %d", baseInterval);
   437     LOGSTRING2("CProfilerPowerListener::StartL() - Original HWRM max power reporting period: %d", iOriginalReportingPeriod);
   436     LOGSTRING2("CProfilerPowerListener::StartL() - Original HWRM max power reporting period: %d", iOriginalReportingPeriod);
   438 
   437 
   439     User::LeaveIfError(centRep->Set(KPowerMaxReportingPeriod, KReportingPeriodInfinite));
   438     User::LeaveIfError(centRep->Set(KPowerMaxReportingPeriod, KReportingPeriodInfinite));
       
   439     CleanupStack::PopAndDestroy();
   440 
   440 
   441     // Power reporting interval reading may return too low value sometimes. Minimum value expected to be 250ms.
   441     // Power reporting interval reading may return too low value sometimes. Minimum value expected to be 250ms.
   442     if ( baseInterval < KMinSampleInterval )
   442     if ( baseInterval < KMinSampleInterval )
   443         {
   443         {
   444         baseInterval = KMinSampleInterval;
   444         baseInterval = KMinSampleInterval;
   466         DisplayNotifierL(KPowerTextLine1, KPowerTextLine2, KButtonOk, KNullDesC);
   466         DisplayNotifierL(KPowerTextLine1, KPowerTextLine2, KButtonOk, KNullDesC);
   467 
   467 
   468         return status.Int();
   468         return status.Int();
   469         }
   469         }
   470 
   470 
   471 #ifdef PWR_SAMPLER_BACKLIGHT
       
   472     // Start monitoring backlight status
   471     // Start monitoring backlight status
   473     iLightAPI = CHWRMLight::NewL(this);
   472     iLightAPI = CHWRMLight::NewL(this);
   474 #endif
       
   475 
   473 
   476     LOGTEXT(_L("CProfilerPowerListener::StartL() - exit"));
   474     LOGTEXT(_L("CProfilerPowerListener::StartL() - exit"));
   477     return KErrNone;
   475     return KErrNone;
   478     }
   476     }
   479 
   477 
   503     TUint32 sampleTime = User::NTickCount() - iSampleStartTime;
   501     TUint32 sampleTime = User::NTickCount() - iSampleStartTime;
   504     LOGSTRING2("CProfilerPowerListener::Sample() - Sample time: %d", sampleTime);
   502     LOGSTRING2("CProfilerPowerListener::Sample() - Sample time: %d", sampleTime);
   505     LOGSTRING2("CProfilerPowerListener::Sample() - Nominal capacitance: %d", iNominalCapa);
   503     LOGSTRING2("CProfilerPowerListener::Sample() - Nominal capacitance: %d", iNominalCapa);
   506     LOGSTRING2("CProfilerPowerListener::Sample() - Voltage: %d", iVoltage);
   504     LOGSTRING2("CProfilerPowerListener::Sample() - Voltage: %d", iVoltage);
   507     LOGSTRING2("CProfilerPowerListener::Sample() - Current: %d", iCurrent);
   505     LOGSTRING2("CProfilerPowerListener::Sample() - Current: %d", iCurrent);
   508 #ifdef PWR_SAMPLER_BACKLIGHT
       
   509     LOGSTRING2("CProfilerPowerListener::Sample() - Backlight status: %d", (TUint8)iBackLightStatus);
   506     LOGSTRING2("CProfilerPowerListener::Sample() - Backlight status: %d", (TUint8)iBackLightStatus);
   510 #endif
       
   511 
   507 
   512     iSample[0] = iNominalCapa;
   508     iSample[0] = iNominalCapa;
   513     iSample[1] = iNominalCapa >> 8;
   509     iSample[1] = iNominalCapa >> 8;
   514     iSample[2] = iVoltage;
   510     iSample[2] = iVoltage;
   515     iSample[3] = iVoltage >> 8;
   511     iSample[3] = iVoltage >> 8;
   516     iSample[4] = iCurrent;
   512     iSample[4] = iCurrent;
   517     iSample[5] = iCurrent >> 8;
   513     iSample[5] = iCurrent >> 8;
   518     iSample[6] = iCurrent >> 16;
   514     iSample[6] = iCurrent >> 16;
   519     iSample[7] = iCurrent >> 24;
   515     iSample[7] = iCurrent >> 24;
   520 #ifdef PWR_SAMPLER_BACKLIGHT
       
   521     iSample[8] = (TUint8)iBackLightStatus;
   516     iSample[8] = (TUint8)iBackLightStatus;
   522     iSample[9] = sampleTime;
   517     iSample[9] = sampleTime;
   523     iSample[10] = sampleTime >> 8;
   518     iSample[10] = sampleTime >> 8;
   524     iSample[11] = sampleTime >> 16;
   519     iSample[11] = sampleTime >> 16;
   525     iSample[12] = sampleTime >> 24;
   520     iSample[12] = sampleTime >> 24;
   526 
   521 
   527     iSampler->AddSample(iSample, 13, 0);
   522     iSampler->AddSample(iSample, 13, 0);
   528 #else
       
   529     iSample[8] = sampleTime;
       
   530     iSample[9] = sampleTime >> 8;
       
   531     iSample[10] = sampleTime >> 16;
       
   532     iSample[11] = sampleTime >> 24;
       
   533 
       
   534     iSampler->AddSample(iSample, 12, 0);
       
   535 #endif
       
   536 
   523 
   537     LOGTEXT(_L("CProfilerPowerListener::Sample() - exit"));
   524     LOGTEXT(_L("CProfilerPowerListener::Sample() - exit"));
   538     }
   525     }
   539 
   526 
   540 TInt CProfilerPowerListener::Stop() 
   527 TInt CProfilerPowerListener::Stop() 
   568             if(err != KErrNone)
   555             if(err != KErrNone)
   569                 {
   556                 {
   570                 LOGSTRING2("CProfilerPowerListener::Stop() - Failed to restore max sampling period: %d", err);
   557                 LOGSTRING2("CProfilerPowerListener::Stop() - Failed to restore max sampling period: %d", err);
   571                 }
   558                 }
   572             }
   559             }
   573         }
   560         if (centRep)
   574 #ifdef PWR_SAMPLER_BACKLIGHT
   561             {
       
   562             delete centRep;
       
   563             }
       
   564         }
       
   565 
   575     if (iLightAPI)
   566     if (iLightAPI)
   576         {
   567         {
   577         delete iLightAPI;
   568         delete iLightAPI;
   578         iLightAPI = 0;
   569         iLightAPI = 0;
   579         }
   570         }
   580 #endif
       
   581 
   571 
   582     LOGTEXT(_L("CProfilerPowerListener::Stop() - exit"));
   572     LOGTEXT(_L("CProfilerPowerListener::Stop() - exit"));
   583     return KErrNone;
   573     return KErrNone;
   584     }
   574     }
   585 
   575 
   602         DisplayNotifierL(KPowerTextLine1, KPowerTextErrorSampling, KButtonOk, KNullDesC);
   592         DisplayNotifierL(KPowerTextLine1, KPowerTextErrorSampling, KButtonOk, KNullDesC);
   603         }
   593         }
   604     LOGTEXT(_L("CProfilerPowerListener::PowerMeasurement - exit"));
   594     LOGTEXT(_L("CProfilerPowerListener::PowerMeasurement - exit"));
   605     }
   595     }
   606 
   596 
   607 #ifdef PWR_SAMPLER_BACKLIGHT
       
   608 void CProfilerPowerListener::LightStatusChanged(TInt aTarget, CHWRMLight::TLightStatus aStatus)
   597 void CProfilerPowerListener::LightStatusChanged(TInt aTarget, CHWRMLight::TLightStatus aStatus)
   609     {
   598     {
   610     LOGTEXT(_L("CProfilerPowerListener::LightStatusChanged - entry"));
   599     LOGTEXT(_L("CProfilerPowerListener::LightStatusChanged - entry"));
   611     LOGSTRING3("CProfilerPowerListener::LightStatusChanged - Target: %d Status: %d", aTarget, aStatus);
   600     LOGSTRING3("CProfilerPowerListener::LightStatusChanged - Target: %d Status: %d", aTarget, aStatus);
   612 
   601 
   618 
   607 
   619         this->Sample();
   608         this->Sample();
   620         }
   609         }
   621     LOGTEXT(_L("CProfilerPowerListener::LightStatusChanged - exit"));
   610     LOGTEXT(_L("CProfilerPowerListener::LightStatusChanged - exit"));
   622     }
   611     }
   623 #endif