diff --git a/PerformanceMetrics/PerformanceMetrics.cpp b/PerformanceMetrics/PerformanceMetrics.cpp index 51b49b6a97..44678b74eb 100644 --- a/PerformanceMetrics/PerformanceMetrics.cpp +++ b/PerformanceMetrics/PerformanceMetrics.cpp @@ -45,24 +45,26 @@ namespace Plugin { string result; - if( ( config.ObservableCallsign.IsSet() == true ) && (config.ObservableClassname.IsSet() == true) ) { + if ((config.ObservableCallsign.IsSet() == true) && (config.ObservableClassname.IsSet() == true)) { result = _T("Both callsign and classname set to observe for metrics"); } - else if( ( config.ObservableCallsign.IsSet() == true ) && ( config.ObservableCallsign.Value().empty() == false ) ) { + else if ((config.ObservableCallsign.IsSet() == true) && ( config.ObservableCallsign.Value().empty() == false)) { _handler.reset(new CallsignPerfMetricsHandler(config.ObservableCallsign.Value())); } - else if( ( config.ObservableClassname.IsSet() == true ) && ( config.ObservableClassname.Value().empty() == false ) ) { + else if ((config.ObservableClassname.IsSet() == true) && ( config.ObservableClassname.Value().empty() == false)) { _handler.reset(new ClassnamePerfMetricsHandler(config.ObservableClassname.Value())); } else { result = _T("No callsign or classname set to observe for metrics"); } - if( result.empty() == true ) { + if (result.empty() == true) { ASSERT(_handler); _handler->Initialize(); service->Register(&_notification); } else { +#ifndef USE_THUNDER_R4 Deinitialize(service); +#endif } return result; @@ -70,7 +72,8 @@ namespace Plugin { void PerformanceMetrics::Deinitialize(PluginHost::IShell* service) { - if( _handler ) { + ASSERT(service != nullptr); + if (_handler) { service->Unregister(&_notification); // as we do this after the unregister the call to Deinitialize should be threadsafe, no more notifications can be received // if the deactivate of the observable did not happen we must clean up here @@ -103,23 +106,23 @@ namespace Plugin { Exchange::IWebBrowser* webbrowser = service.QueryInterface(); PluginHost::IStateControl* statecontrol = service.QueryInterface(); - if( webbrowser != nullptr ) { - TRACE(Trace::Information, (_T("Start oberserving %s as webbrowser"), Callsign().c_str()) ); + if (webbrowser != nullptr) { + TRACE(Trace::Information, (_T("Start oberserving %s as webbrowser"), Callsign().c_str())); _observable = Core::ProxyType>::Create(*this, service, *webbrowser, statecontrol); webbrowser->Release(); } else { Exchange::IBrowser* browser = service.QueryInterface(); - if( browser != nullptr ) { - TRACE(Trace::Information, (_T("Start oberserving %s as browser"), Callsign().c_str()) ); + if (browser != nullptr) { + TRACE(Trace::Information, (_T("Start oberserving %s as browser"), Callsign().c_str())); _observable = Core::ProxyType>::Create(*this, service, *browser, statecontrol); browser->Release(); } - else if( statecontrol != nullptr ) { - TRACE(Trace::Information, (_T("Start oberserving %s as statecontrol"), Callsign().c_str()) ); + else if (statecontrol != nullptr) { + TRACE(Trace::Information, (_T("Start oberserving %s as statecontrol"), Callsign().c_str())); _observable = Core::ProxyType>::Create(*this, service, statecontrol); } else { - TRACE(Trace::Information, (_T("Start oberserving %s as basic"), Callsign().c_str()) ); + TRACE(Trace::Information, (_T("Start oberserving %s as basic"), Callsign().c_str())); _observable = Core::ProxyType>::Create(*this, service); } } @@ -127,7 +130,7 @@ namespace Plugin { ASSERT(_observable.IsValid() == true); _observable->Enable(); - if( statecontrol != nullptr ) { + if (statecontrol != nullptr) { statecontrol->Release(); } } diff --git a/PerformanceMetrics/PerformanceMetrics.h b/PerformanceMetrics/PerformanceMetrics.h index f1364cb53b..ca5e9e9d0d 100644 --- a/PerformanceMetrics/PerformanceMetrics.h +++ b/PerformanceMetrics/PerformanceMetrics.h @@ -176,7 +176,7 @@ namespace Plugin { void Deinitialize() override { - if( _observable.IsValid() == true ) { + if (_observable.IsValid() == true) { _observable->Disable(); VARIABLE_IS_NOT_USED uint32_t result =_observable.Release(); ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED); @@ -186,7 +186,7 @@ namespace Plugin { void Activated(PluginHost::IShell& service) override { - if( service.Callsign() == _callsign ) { + if (service.Callsign() == _callsign) { ASSERT(_observable.IsValid() == false); CreateObservable(service); @@ -196,7 +196,7 @@ namespace Plugin { void Deactivated(PluginHost::IShell& service) override { - if( service.Callsign() == _callsign ) { + if (service.Callsign() == _callsign) { ASSERT(_observable.IsValid() == true); _observable->Deactivated(service); @@ -247,7 +247,7 @@ namespace Plugin { void Deinitialize() override { // no lock needed, no notification are possible here. - for( auto& observer : _observers ) { + for (auto& observer : _observers) { observer.second.Deinitialize(); } _observers.clear(); @@ -255,12 +255,12 @@ namespace Plugin { void Activated(PluginHost::IShell& service) override { - if( service.ClassName() == Classname() ) { + if (service.ClassName() == Classname()) { _adminLock.Lock(); auto result =_observers.emplace(std::piecewise_construct, std::forward_as_tuple(service.Callsign()), std::forward_as_tuple(service.Callsign())); - ASSERT( ( result.second == true ) && ( result.first != _observers.end() ) ); + ASSERT((result.second == true) && (result.first != _observers.end())); result.first->second.Initialize(); result.first->second.Activated(service); _adminLock.Unlock(); @@ -268,10 +268,10 @@ namespace Plugin { } void Deactivated(PluginHost::IShell& service) override { - if( service.ClassName() == Classname() ) { + if (service.ClassName() == Classname()) { _adminLock.Lock(); auto it =_observers.find(service.Callsign()); - if( it != _observers.end() ) { + if (it != _observers.end()) { it->second.Deactivated(service); it->second.Deinitialize(); _observers.erase(it); @@ -363,7 +363,7 @@ namespace Plugin { void Deactivated(PluginHost::IShell&) override { - Logger().Deactivated( Uptime() ); + Logger().Deactivated(Uptime()); } uint64_t ActivateTime() const @@ -373,7 +373,7 @@ namespace Plugin { uint32_t Uptime() const { - return ( Core::Time::Now().Ticks() - ActivateTime() ) / Core::Time::MicroSecondsPerSecond; + return (Core::Time::Now().Ticks() - ActivateTime()) / Core::Time::MicroSecondsPerSecond; } CallsignPerfMetricsHandler& Parent() const @@ -410,8 +410,8 @@ namespace Plugin { , _statecontrol(statecontrol) { // not very likely but it could happen that we have a Browser without StatControl - if(_statecontrol != nullptr) { - TRACE(Trace::Information, (_T("Observable supports Statecontrol")) ); + if (_statecontrol != nullptr) { + TRACE(Trace::Information, (_T("Observable supports Statecontrol"))); _statecontrol->AddRef(); } } @@ -425,7 +425,7 @@ namespace Plugin { { Base::Enable(); - if(_statecontrol != nullptr) { + if (_statecontrol != nullptr) { _statecontrol->Register(this); } @@ -439,9 +439,9 @@ namespace Plugin { void StateChange(const PluginHost::IStateControl::state state) override { - if( state == PluginHost::IStateControl::state::RESUMED ) { + if (state == PluginHost::IStateControl::state::RESUMED) { Logger().Resumed(); - } else if( state == PluginHost::IStateControl::state::SUSPENDED ) { + } else if (state == PluginHost::IStateControl::state::SUSPENDED) { Logger().Suspended(); } } @@ -453,7 +453,7 @@ namespace Plugin { private: void Cleanup() { - if(_statecontrol != nullptr) { + if (_statecontrol != nullptr) { _statecontrol->Unregister(this); _statecontrol->Release(); _statecontrol = nullptr; @@ -520,7 +520,7 @@ namespace Plugin { void LoadFinished(const string& URL) override { - if( URL != IBrowserMetricsLogger::startURL ) { + if (URL != IBrowserMetricsLogger::startURL) { ++_nbrloaded; } Logger().LoadFinished(URL, 0, true, _nbrloaded, 0); @@ -601,14 +601,14 @@ namespace Plugin { void LoadFinished(const string& URL, const int32_t httpstatus) override { - if( URL != IBrowserMetricsLogger::startURL ) { + if (URL != IBrowserMetricsLogger::startURL) { ++_nbrloadedsuccess; } Logger().LoadFinished(URL, httpstatus, true, _nbrloadedsuccess, _nbrloadedfailed); } void LoadFailed(const string& URL) override { - if( URL != IBrowserMetricsLogger::startURL ) { + if (URL != IBrowserMetricsLogger::startURL) { ++_nbrloadedfailed; } Logger().LoadFinished(URL, 0, false, _nbrloadedsuccess, _nbrloadedfailed); diff --git a/PerformanceMetrics/SyslogOutput.cpp b/PerformanceMetrics/SyslogOutput.cpp index b4c6b1c0c7..ed558c2a02 100644 --- a/PerformanceMetrics/SyslogOutput.cpp +++ b/PerformanceMetrics/SyslogOutput.cpp @@ -77,7 +77,7 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { URLLoadedMetrics& operator=(const URLLoadedMetrics& copy) { - if( this != © ) { + if (this != ©) { _total = copy._total; _free = copy._free; _swapped = copy._swapped; @@ -277,14 +277,14 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { _service = &service; _service->AddRef(); _memory = service.QueryInterface(); - if( _memory != nullptr ) { + if (_memory != nullptr) { Exchange::IMemoryExtended* extended = _memory->QueryInterface(); - if( extended != nullptr ) { + if (extended != nullptr) { Exchange::IMemoryExtended::IStringIterator* iterator = nullptr; - if( ( extended->Processes(iterator) == Core::ERROR_NONE ) && ( iterator != nullptr ) ) { + if ((extended->Processes(iterator) == Core::ERROR_NONE ) && ( iterator != nullptr)) { string processname; - while( iterator->Next(processname) == true ) { - if( processname == webProcessName ) { + while (iterator->Next(processname) == true) { + if (processname == webProcessName) { VARIABLE_IS_NOT_USED uint32_t result = extended->Process(webProcessName, _processmemory); ASSERT( ( result == Core::ERROR_NONE ) && (_processmemory != nullptr )); break; @@ -299,15 +299,15 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { void Disable() override { - if(_service != nullptr) { + if (_service != nullptr) { _service->Release(); _service = nullptr; } - if(_memory != nullptr) { + if (_memory != nullptr) { _memory->Release(); _memory = nullptr; } - if(_processmemory != nullptr) { + if (_processmemory != nullptr) { _processmemory->Release(); _processmemory = nullptr; } @@ -322,8 +322,7 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { void Deactivated(const uint32_t) override { PluginHost::IShell::reason reason = _service->Reason(); - if(reason == PluginHost::IShell::FAILURE || reason == PluginHost::IShell::MEMORY_EXCEEDED) - { + if (reason == PluginHost::IShell::FAILURE || reason == PluginHost::IShell::MEMORY_EXCEEDED) { SYSLOG(Logging::Notification, (_T("Browser::Deactivated ( \"URL\": %s , \"Reason\": %d )"), getHostName(_lastURL).c_str(), reason)); string eventName("BrowserDeactivation_accum"); string eventValue; @@ -347,29 +346,33 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { string getHostName(string _URL){ std::size_t startIdx = _URL.find("://"); - if(startIdx == std::string::npos) + if (startIdx == std::string::npos) { return _URL; + } else { startIdx += 3; // skip "://" size_t endIdx = _URL.find("/",startIdx); - if(endIdx == std::string::npos) + if (endIdx == std::string::npos) { return _URL.substr(startIdx); - else + } + else { return _URL.substr(startIdx, endIdx - startIdx); + } } } void LoadFinished(const string& URL, const int32_t, const bool success, const uint32_t totalsuccess, const uint32_t totalfailed) override { - if( URL != startURL ) { + if (URL != startURL) { _adminLock.Lock(); URLLoadedMetrics metrics(_urloadmetrics); _adminLock.Unlock(); uint64_t urllaunchtime_ms = ( ( Core::Time::Now().Ticks() - metrics.StartLoad() ) / Core::Time::TicksPerMillisecond); - if(strcmp(getHostName(URL).c_str(), _lastLoggedApp.c_str())) - _didLogLaunchMetrics = false; + if (strcmp(getHostName(URL).c_str(), _lastLoggedApp.c_str())) { + _didLogLaunchMetrics = false; + } OutputLoadFinishedMetrics(metrics, getHostName(URL), urllaunchtime_ms, success, totalsuccess + totalfailed); @@ -379,7 +382,7 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { void URLChange(const string& URL, const bool) override { - if( URL != startURL ) { + if (URL != startURL) { URLLoadedMetrics metrics; Core::SystemInfo::MemorySnapshot snapshot = Core::SystemInfo::Instance().TakeMemorySnapshot(); metrics.Total(snapshot.Total()); @@ -391,13 +394,13 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { metrics.AverageLoad()[2] = Core::SystemInfo::Instance().GetCpuLoadAvg()[2]; uint64_t resident = 0; - if( _processmemory != nullptr ) { + if (_processmemory != nullptr) { resident = _processmemory->Resident(); uint32_t pid = _processmemory->Identifier(); - if( pid != 0 ) { + if (pid != 0) { metrics.StatmLine(GetProcessStatmLine(pid)); } - } else if ( _memory != nullptr ) { + } else if (_memory != nullptr) { resident = _memory->Resident(); } @@ -407,8 +410,9 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { uint64_t timeLaunched = 0; timeLaunched = (Core::Time::Now().Ticks() - _timePluginStart) / Core::Time::MicroSecondsPerSecond; - if(timeLaunched < 2) + if (timeLaunched < 2) { metrics.SetColdLaunch(true); + } _adminLock.Lock(); _urloadmetrics = std::move(metrics); @@ -430,8 +434,9 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { const bool success, const uint32_t totalloaded) { - if(_didLogLaunchMetrics) + if (_didLogLaunchMetrics) { return; + } MetricsAsJson output; @@ -453,7 +458,7 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { output.ProcessRSS = urloadedmetrics.RSSMemProcess(); uint32_t pid = 0; - if( _processmemory != nullptr ) { + if (_processmemory != nullptr) { pid = _processmemory->Identifier(); } output.ProcessPID = pid; @@ -481,7 +486,7 @@ class SysLogOuput : public PerformanceMetrics::IBrowserMetricsLogger { Utils::Telemetry::sendMessage((char *)eventName.c_str(), (char *)eventValue.c_str()); - SYSLOG(Logging::Notification, (_T( "%s Launch Metrics: %s "), _callsign.c_str(), outputstring.c_str())); + SYSLOG(Logging::Notification, (_T( "%s Launch Metrics: %s "), _callsign.c_str(), outputstring.c_str())); _didLogLaunchMetrics = true; _lastLoggedApp = URL; } diff --git a/PerformanceMetrics/TraceOutput.cpp b/PerformanceMetrics/TraceOutput.cpp index a396d1e2c0..87b7d01df5 100644 --- a/PerformanceMetrics/TraceOutput.cpp +++ b/PerformanceMetrics/TraceOutput.cpp @@ -164,7 +164,7 @@ class MetricsTraceOuputBrowser : public PerformanceMetrics::IBrowserMetricsLogge void Deactivated(const uint32_t uptime) override { - TRACE(Trace::Metric, (_T("Plugin %s deactivated, uptime(s): %u"), _callsign.c_str(), (uptime/1000))); + TRACE(Trace::Metric, (_T("Plugin %s deactivated, uptime(s): %u"), _callsign.c_str(), uptime)); } void Resumed() override