From 3541dc60347b55dbe2a54f29abb3e3b0e5434498 Mon Sep 17 00:00:00 2001 From: Matthew Andrew <matthew.andrew@stfc.ac.uk> Date: Thu, 8 Feb 2018 11:28:26 +0000 Subject: [PATCH] Re #21709 Added starttime tracking --- Framework/Kernel/inc/MantidKernel/CrashService.h | 2 ++ Framework/Kernel/inc/MantidKernel/UsageService.h | 3 +++ Framework/Kernel/src/CrashService.cpp | 9 ++++++--- Framework/Kernel/src/UsageService.cpp | 9 ++++++--- MantidPlot/src/Mantid/MantidApplication.cpp | 5 +++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Framework/Kernel/inc/MantidKernel/CrashService.h b/Framework/Kernel/inc/MantidKernel/CrashService.h index d8f89e20d97..c216cc2c41d 100644 --- a/Framework/Kernel/inc/MantidKernel/CrashService.h +++ b/Framework/Kernel/inc/MantidKernel/CrashService.h @@ -36,6 +36,7 @@ namespace Kernel { class MANTID_KERNEL_DLL CrashServiceImpl { public: CrashServiceImpl(std::string application); + CrashServiceImpl(std::string application, std::string startTime); void sendCrashReport(); protected: @@ -46,6 +47,7 @@ class MANTID_KERNEL_DLL CrashServiceImpl { private: int sendCrashAsyncImpl(const std::string &message); const std::string m_application; + const std::string m_startTime; /// Async method for sending startup notifications Poco::ActiveMethod<int, std::string, CrashServiceImpl> m_crashActiveMethod; }; diff --git a/Framework/Kernel/inc/MantidKernel/UsageService.h b/Framework/Kernel/inc/MantidKernel/UsageService.h index 936bbec93b0..3d06c159db5 100644 --- a/Framework/Kernel/inc/MantidKernel/UsageService.h +++ b/Framework/Kernel/inc/MantidKernel/UsageService.h @@ -84,6 +84,8 @@ public: /// flushes any buffers and sends any outstanding usage reports void flush(); void shutdown(); + /// gets the uptime of this mantid instance + std::string getStartTime(); protected: /// Constructor @@ -131,6 +133,7 @@ private: bool m_isEnabled; mutable std::mutex m_mutex; std::string m_application; + std::string m_startTime; /// Async method for sending startup notifications Poco::ActiveMethod<int, std::string, UsageServiceImpl> m_startupActiveMethod; diff --git a/Framework/Kernel/src/CrashService.cpp b/Framework/Kernel/src/CrashService.cpp index 54023d148bb..745a4383882 100644 --- a/Framework/Kernel/src/CrashService.cpp +++ b/Framework/Kernel/src/CrashService.cpp @@ -28,9 +28,10 @@ const std::string CRASH_URL("http://crashreports.mantidproject.org/api/crash"); //---------------------------------------------------------------------------------------------- // Constructor for CrashServiceImpl CrashServiceImpl::CrashServiceImpl(std::string application) - : m_application(application), m_crashActiveMethod(this, &CrashServiceImpl::sendCrashAsyncImpl) { - -} + : m_application(application), m_startTime(""), m_crashActiveMethod(this, &CrashServiceImpl::sendCrashAsyncImpl) {} + +CrashServiceImpl::CrashServiceImpl(std::string application, std::string startTime) + : m_application(application), m_startTime(startTime), m_crashActiveMethod(this, &CrashServiceImpl::sendCrashAsyncImpl) {} void CrashServiceImpl::sendCrashReport() { try { @@ -73,6 +74,8 @@ std::string CrashServiceImpl::generateCrashMessage() { message["dateTime"] = Types::Core::DateAndTime::getCurrentTime().toISO8601String(); + message["startTime"] = m_startTime; + message["application"] = m_application; message["facility"] = ConfigService::Instance().getFacility().name(); diff --git a/Framework/Kernel/src/UsageService.cpp b/Framework/Kernel/src/UsageService.cpp index ea4c8a7e27b..f4cac93b6e7 100644 --- a/Framework/Kernel/src/UsageService.cpp +++ b/Framework/Kernel/src/UsageService.cpp @@ -131,6 +131,10 @@ void UsageServiceImpl::flush() { } } +std::string UsageServiceImpl::getStartTime() { + return m_startTime; +} + void UsageServiceImpl::shutdown() { try { // stop the timer @@ -145,8 +149,8 @@ void UsageServiceImpl::shutdown() { void UsageServiceImpl::sendStartupReport() { try { + m_startTime = Types::Core::DateAndTime::getCurrentTime().toISO8601String(); std::string message = this->generateStartupMessage(); - // send the report Poco::ActiveResult<int> result = m_startupActiveMethod(message); } catch (std::exception &ex) { @@ -227,8 +231,7 @@ std::string UsageServiceImpl::generateStartupMessage() { message["mantidSha1"] = MantidVersion::revisionFull(); // mantid version and sha1 - message["dateTime"] = - Types::Core::DateAndTime::getCurrentTime().toISO8601String(); + message["dateTime"] = m_startTime; message["application"] = m_application; diff --git a/MantidPlot/src/Mantid/MantidApplication.cpp b/MantidPlot/src/Mantid/MantidApplication.cpp index 15c9aec430f..4123caf6bed 100644 --- a/MantidPlot/src/Mantid/MantidApplication.cpp +++ b/MantidPlot/src/Mantid/MantidApplication.cpp @@ -4,9 +4,10 @@ #include "MantidApplication.h" #include "MantidQtWidgets/Common/MantidDialog.h" +#include "MantidKernel/ConfigService.h" +#include "MantidKernel/CrashService.h" #include "MantidKernel/Logger.h" #include "MantidKernel/UsageService.h" -#include "MantidKernel/CrashService.h" #include <QMessageBox> #include <QPushButton> @@ -41,7 +42,7 @@ bool MantidApplication::notify(QObject *receiver, QEvent *event) { int reportingEnabled = 0; int retVal = Mantid::Kernel::ConfigService::Instance().getValue("usagereports.enabled", reportingEnabled); if (reportingEnabled && retVal == 1){ - Mantid::Kernel::CrashServiceImpl crashService("mantidplot"); + Mantid::Kernel::CrashServiceImpl crashService("mantidplot", Mantid::Kernel::UsageService::Instance().getStartTime()); crashService.sendCrashReport(); } -- GitLab