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/enum.hpp>
12#include <boost/python/reference_existing_object.hpp>
13
14#include <mutex>
15
18using namespace boost::python;
19using ExtractStdString = boost::python::extract<std::string>;
21
23
24namespace {
25
26std::once_flag INIT_FLAG;
27
34UsageServiceImpl &instance() {
35 // start the framework (if necessary)
36 auto &svc = UsageService::Instance();
37 std::call_once(INIT_FLAG, []() {
38 PyRun_SimpleString("import atexit\n"
39 "from mantid.kernel import UsageService\n"
40 "atexit.register(lambda: UsageService.shutdown())");
41 });
42 return svc;
43}
44
46void registerFeatureUsage(UsageServiceImpl &self, const Mantid::Kernel::FeatureType &type, const object &paths,
47 const bool internal) {
48 ExtractStdString singleString(paths);
49 if (singleString.check()) {
50 self.registerFeatureUsage(type, singleString(), internal);
51 } else {
52 self.registerFeatureUsage(type, PySequenceToVector<std::string>(paths)(), internal);
53 }
54}
55
56} // namespace
57
59 enum_<Mantid::Kernel::FeatureType>("FeatureType")
62 .value("Feature", Mantid::Kernel::FeatureType::Feature);
63
64 class_<UsageServiceImpl, boost::noncopyable>("UsageServiceImpl", no_init)
65 .def("flush", &UsageServiceImpl::flush, arg("self"), "Sends any pending usage information.")
66 .def("shutdown", &UsageServiceImpl::shutdown, arg("self"),
67 "Sends any pending usage information, and disables the usage "
68 "service.")
69 .def("getUpTime", &UsageServiceImpl::getUpTime, arg("self"),
70 "Returns the time that the instance of mantid has been running")
71 .def("isEnabled", &UsageServiceImpl::isEnabled, arg("self"), "Returns if the usage service is enabled.")
72 .def("setEnabled", &UsageServiceImpl::setEnabled, (arg("self"), arg("enabled")),
73 "Enables or disables the usage service.")
74 .def("setInterval", &UsageServiceImpl::setEnabled, (arg("self"), arg("seconds")),
75 "Sets the interval that the timer checks for tasks.")
76 .def("setApplicationName", &UsageServiceImpl::setApplicationName, (arg("self"), arg("name")),
77 "Sets the application name that has invoked Mantid.")
78 .def("getApplicationName", &UsageServiceImpl::getApplicationName, arg("self"),
79 "Gets the application name that has invoked Mantid.")
80 .def("registerStartup", &UsageServiceImpl::registerStartup, arg("self"), "Registers the startup of Mantid.")
81 .def("registerFeatureUsage", &registerFeatureUsage, (arg("self"), arg("type"), arg("name"), arg("internal")),
82 "Registers the use of a feature in Mantid.")
83 .def("getStartTime", &UsageServiceImpl::getStartTime, (arg("self")),
84 "Returns the time at which Mantid was started")
85 .def("Instance", instance, return_value_policy<reference_existing_object>(),
86 "Returns a reference to the UsageService")
87 .staticmethod("Instance");
88}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition: GetPointer.h:17
boost::python::extract< std::string > ExtractStdString
void export_UsageService()
Manage the lifetime of a class intended to be a singleton.
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.
std::string getApplicationName() const
Returns the application name that has invoked Mantid.
void flush()
flushes any buffers and sends any outstanding usage reports
Types::Core::DateAndTime getStartTime()
Gets the start time of this mantid instance.
Definition: UsageService.h:93
bool isEnabled() const
Returns true if usage reporting is enabled.
Types::Core::time_duration getUpTime()
gets the uptime of this mantid instance
FeatureType
An enum specifying the 4 possible features types that can be logged in the usage service.
Definition: UsageService.h:28
Converts a Python sequence type to a C++ std::vector, where the element type is defined by the templa...