Mantid
Loading...
Searching...
No Matches
UsageService.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10#include <boost/python/class.hpp>
11#include <boost/python/copy_const_reference.hpp>
12#include <boost/python/enum.hpp>
13#include <boost/python/reference_existing_object.hpp>
14
15#include <mutex>
16
19using namespace boost::python;
20using ExtractStdString = boost::python::extract<std::string>;
22
24
25namespace {
26
27std::once_flag INIT_FLAG;
28
35UsageServiceImpl &instance() {
36 // start the framework (if necessary)
37 auto &svc = UsageService::Instance();
38 std::call_once(INIT_FLAG, []() {
39 PyRun_SimpleString("import atexit\n"
40 "from mantid.kernel import UsageService\n"
41 "atexit.register(lambda: UsageService.shutdown())");
42 });
43 return svc;
44}
45
47void registerFeatureUsage(UsageServiceImpl &self, const Mantid::Kernel::FeatureType &type, const object &paths,
48 const bool internal) {
49 ExtractStdString singleString(paths);
50 if (singleString.check()) {
51 self.registerFeatureUsage(type, singleString(), internal);
52 } else {
53 self.registerFeatureUsage(type, PySequenceToVector<std::string>(paths)(), internal);
54 }
55}
56
57} // namespace
58
60 enum_<Mantid::Kernel::FeatureType>("FeatureType")
63 .value("Feature", Mantid::Kernel::FeatureType::Feature);
64
65 class_<UsageServiceImpl, boost::noncopyable>("UsageServiceImpl", no_init)
66 .def("flush", &UsageServiceImpl::flush, arg("self"), "Sends any pending usage information.")
67 .def("shutdown", &UsageServiceImpl::shutdown, arg("self"),
68 "Sends any pending usage information, and disables the usage "
69 "service.")
70 .def("getUpTime", &UsageServiceImpl::getUpTime, arg("self"),
71 "Returns the time that the instance of mantid has been running")
72 .def("isEnabled", &UsageServiceImpl::isEnabled, arg("self"), "Returns if the usage service is enabled.")
73 .def("setEnabled", &UsageServiceImpl::setEnabled, (arg("self"), arg("enabled")),
74 "Enables or disables the usage service.")
75 .def("setInterval", &UsageServiceImpl::setEnabled, (arg("self"), arg("seconds")),
76 "Sets the interval that the timer checks for tasks.")
77 .def("setApplicationName", &UsageServiceImpl::setApplicationName, (arg("self"), arg("name")),
78 "Sets the application name that has invoked Mantid.")
79 .def("getApplicationName", &UsageServiceImpl::getApplicationName, arg("self"),
80 return_value_policy<copy_const_reference>(), "Gets the application name that has invoked Mantid.")
81 .def("registerStartup", &UsageServiceImpl::registerStartup, arg("self"), "Registers the startup of Mantid.")
82 .def("registerFeatureUsage", &registerFeatureUsage, (arg("self"), arg("type"), arg("name"), arg("internal")),
83 "Registers the use of a feature in Mantid.")
84 .def("getStartTime", &UsageServiceImpl::getStartTime, (arg("self")),
85 "Returns the time at which Mantid was started")
86 .def("Instance", instance, return_value_policy<reference_existing_object>(),
87 "Returns a reference to the UsageService")
88 .staticmethod("Instance");
89}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition GetPointer.h:17
boost::python::extract< std::string > ExtractStdString
void export_UsageService()
const std::string & getApplicationName() const
Returns the application name that has invoked Mantid.
void registerFeatureUsage(const FeatureType &type, const std::vector< std::string > &name, const bool internal)
registerFeatureUsage registers the use of a feature in mantid.
void setApplicationName(const std::string &name)
Sets the application name that has invoked Mantid.
void setEnabled(const bool enabled)
Sets whether the UsageReporter is enabled.
void registerStartup()
Registers the Startup of Mantid.
void flush()
flushes any buffers and sends any outstanding usage reports
Types::Core::DateAndTime getStartTime()
Gets the start time of this mantid instance.
bool isEnabled() const
Returns true if usage reporting is enabled.
Types::Core::time_duration getUpTime()
gets the uptime of this mantid instance
Mantid::Kernel::SingletonHolder< UsageServiceImpl > UsageService
FeatureType
An enum specifying the 4 possible features types that can be logged in the usage service.
Converts a Python sequence type to a C++ std::vector, where the element type is defined by the templa...