Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef MANTID_API_USAGESERVICE_H_
#define MANTID_API_USAGESERVICE_H_
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/DateAndTime.h"
#include "MantidKernel/SingletonHolder.h"
#include "MantidKernel/MultiThreaded.h"
#include <Poco/Timer.h>
#include <json/value.h>
#include <queue>
namespace Json
{
class Value;
}
namespace Mantid {
namespace API {
class Algorithm;
/** UsageService : The Usage Service is responsible for collating, and sending
all usage data.
This centralizes all the logic covering Usage Reporting including:
- Detecting if reporting is enabled
- Registering the startup of Mantid
- Sending Startup usage reports, immediately, and every 24 hours thereafter
- Registering feature usage, and storing in a feature usage buffer
- Sending Feature usage reports on application exit, and when the feature
usage buffer is above a size threshold.
Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class FeatureUsage {
public:
/// Constructor
FeatureUsage(const std::string &type, const std::string &name,
const Kernel::DateAndTime &start, const float& duration,
const std::string &details);
::Json::Value asJson() const;
std::string asString() const;
std::string type;
std::string name;
Kernel::DateAndTime start;
float duration;
std::string details;
};
class MANTID_API_DLL UsageServiceImpl {
public:
/// Registers the Startup of Mantid
void registerStartup();
/// Registers the use of a feature in mantid
void registerFeatureUsage(const std::string &type, const std::string &name,
const Kernel::DateAndTime &start,
const float& duration, const std::string &details);
void registerFeatureUsage(const std::string &type, const std::string &name,
const std::string &details = "");
void registerFeatureUsage(const Algorithm* alg, const float& duration);
/// Returns true if usage reporting is enabled
bool isEnabled() const;
/// flushes any buffers and sends any outstanding usage reports
void flush();
private:
friend struct Mantid::Kernel::CreateUsingNew<UsageServiceImpl>;
/// Constructor
UsageServiceImpl();
/// Private, unimplemented copy constructor
UsageServiceImpl(const UsageServiceImpl &);
/// Private, unimplemented copy assignment operator
UsageServiceImpl &operator=(const UsageServiceImpl &);
/// Destructor
~UsageServiceImpl();
/// Send startup Report
void sendStartupReport();
/// Send featureUsageReport
void sendFeatureUsageReport();
/// A method to handle the timerCallbacks
void timerCallback(Poco::Timer &);
/// Generate jsonfor calls to usage service
::Json::Value generateHeader();
/// a timer
Poco::Timer m_timer;
/// The number of timer ticks since the last reset
uint32_t m_timerTicks;
/// The number of timer ticks at which to reset
uint32_t m_timerTicksTarget;
std::queue<FeatureUsage> m_FeatureQueue;
size_t m_FeatureQueueSizeThreshold;
mutable Kernel::Mutex m_mutex;
::Json::Value m_cachedHeader;
};
/// Forward declaration of a specialization of SingletonHolder for
/// UsageServiceImpl (needed for dllexport/dllimport) and a typedef for
/// it.
#ifdef _WIN32
// this breaks new namespace declaration rules; need to find a better fix
template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<UsageServiceImpl>;
#endif /* _WIN32 */
typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<UsageServiceImpl>
UsageService;
} // namespace API
} // namespace Mantid
#endif /* MANTID_API_USAGESERVICE_H_ */