Merge lp:~matthias-brantner/zorba/auditing into lp:zorba

Proposed by Matthias Brantner
Status: Merged
Approved by: Till Westmann
Approved revision: 10480
Merged at revision: 10483
Proposed branch: lp:~matthias-brantner/zorba/auditing
Merge into: lp:zorba
Diff against target: 180 lines (+78/-15)
4 files modified
include/zorba/audit.h (+2/-0)
include/zorba/audit_scoped.h (+19/-3)
src/api/auditimpl.cpp (+9/-0)
test/unit/test_audit.cpp (+48/-12)
To merge this branch: bzr merge lp:~matthias-brantner/zorba/auditing
Reviewer Review Type Date Requested Status
Till Westmann Approve
Review via email: mp+77600@code.launchpad.net

Commit message

This fix adds a new scoped auditor for auditing in the granularity of micro seconds (MicroDurationAuditor). Also, it fixes a bug that caused a crash if a ScopedAuditor was created with a 0-pointer event.

Description of the change

This fix adds a new scoped auditor for auditing in the granularity of micro seconds (MicroDurationAuditor). Also, it fixes a bug that caused a crash if a ScopedAuditor was created with a 0-pointer event.

To post a comment you must log in.
Revision history for this message
Till Westmann (tillw) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job auditing-2011-09-30T23-31-11.344Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/zorba/audit.h'
2--- include/zorba/audit.h 2011-08-19 23:22:48 +0000
3+++ include/zorba/audit.h 2011-09-29 19:54:29 +0000
4@@ -95,6 +95,8 @@
5
6 class ZORBA_DLL_PUBLIC Event {
7 public:
8+ static Event* get();
9+
10 virtual bool audit(const Property&) const = 0;
11 virtual bool audit(const String&) const = 0;
12
13
14=== modified file 'include/zorba/audit_scoped.h'
15--- include/zorba/audit_scoped.h 2011-08-19 23:22:48 +0000
16+++ include/zorba/audit_scoped.h 2011-09-29 19:54:29 +0000
17@@ -28,8 +28,10 @@
18
19 class ZORBA_DLL_PUBLIC ScopedRecord {
20 public:
21- ScopedRecord(Event* event) : theEvent(event), theRecord(0) {
22- assert(event);
23+ ScopedRecord(Event* event)
24+ : theEvent(event ? event : Event::get()),
25+ theRecord(0) {
26+ assert(theEvent);
27 }
28
29 ~ScopedRecord() {
30@@ -104,6 +106,7 @@
31 typedef ScopedAuditor<const int> IntAuditor;
32 typedef ScopedAuditor<zorba::time::Timer> DurationAuditor;
33 typedef ScopedAuditor<zorba::time::Timer, 0x1> TimestampAuditor;
34+ typedef ScopedAuditor<zorba::time::Timer, 0x2> MicroDurationAuditor;
35
36 template<> struct AuditorTraits<const std::string> {
37 typedef const std::string value_type;
38@@ -141,7 +144,7 @@
39 static inline void start(value_type& value) {
40 }
41 static inline audit_type end(value_type& value) {
42- return value;
43+ return static_cast<audit_type>(value);
44 }
45 };
46
47@@ -189,6 +192,19 @@
48 return static_cast<audit_type>(value.getStart());
49 }
50 };
51+
52+ template<> struct AuditorTraits<zorba::time::Timer, 0x2> {
53+ typedef zorba::time::Timer value_type;
54+ typedef long long audit_type;
55+ static inline void start(value_type& value) {
56+ value.start();
57+ }
58+ static inline audit_type end(value_type& value) {
59+ return static_cast<audit_type>(value.elapsed() * 1000);
60+ }
61+
62+ };
63+
64 }
65 }
66 #endif
67
68=== modified file 'src/api/auditimpl.cpp'
69--- src/api/auditimpl.cpp 2011-08-19 23:22:48 +0000
70+++ src/api/auditimpl.cpp 2011-09-29 19:54:29 +0000
71@@ -395,6 +395,15 @@
72 NOPEventImpl NOP_EVENT_IMPL;
73
74 //************************************************************************
75+// Event
76+//************************************************************************
77+
78+Event*
79+Event::get() {
80+ return &NOP_EVENT_IMPL;
81+}
82+
83+//************************************************************************
84 // ProviderImpl
85 //************************************************************************
86
87
88=== modified file 'test/unit/test_audit.cpp'
89--- test/unit/test_audit.cpp 2011-07-28 15:28:16 +0000
90+++ test/unit/test_audit.cpp 2011-09-29 19:54:29 +0000
91@@ -21,14 +21,12 @@
92 #include <zorba/zorba.h>
93 #include <zorba/store_manager.h>
94 #include <zorba/audit.h>
95+#include <zorba/audit_scoped.h>
96
97-int
98-test_audit(int argc, char* argv[])
99+bool
100+test_audit_1(zorba::Zorba* aZorba)
101 {
102- void* store = zorba::StoreManager::getStore();
103- zorba::Zorba* lZorbaInstance = zorba::Zorba::getInstance(store);
104-
105- zorba::audit::Provider* lAuditProvider = lZorbaInstance->getAuditProvider();
106+ zorba::audit::Provider* lAuditProvider = aZorba->getAuditProvider();
107 zorba::audit::Configuration* config = lAuditProvider->createConfiguration();
108 std::vector<zorba::String> property_names;
109 zorba::audit::Configuration::getPropertyNames(property_names);
110@@ -52,8 +50,8 @@
111
112 zorba::audit::Event* event = lAuditProvider->createEvent(config);
113
114- zorba::XQuery_t query = lZorbaInstance->createQuery();
115- zorba::StaticContext_t lStaticContext = lZorbaInstance->createStaticContext();
116+ zorba::XQuery_t query = aZorba->createQuery();
117+ zorba::StaticContext_t lStaticContext = aZorba->createStaticContext();
118
119 lStaticContext->setAuditEvent(event);
120
121@@ -64,7 +62,7 @@
122 query->execute(std::cout, &lSerOptions);
123
124 if (event->size() != 2) {
125- return 1;
126+ return false;
127 } else {
128 // one record for the eval query and one for the main query
129 const zorba::audit::Record* lRecord = event->at(0);
130@@ -74,9 +72,47 @@
131 std::cerr << *event << std::endl;
132 }
133
134-
135- lZorbaInstance->getAuditProvider()->submitEvent(event);
136- lZorbaInstance->getAuditProvider()->destroyConfiguration(config);
137+ aZorba->getAuditProvider()->submitEvent(event);
138+ aZorba->getAuditProvider()->destroyConfiguration(config);
139+
140+ return true;
141+}
142+
143+bool
144+test_audit_2(zorba::Zorba* aZorba)
145+{
146+ zorba::audit::Provider* lAuditProvider = aZorba->getAuditProvider();
147+ zorba::audit::Configuration* config = lAuditProvider->createConfiguration();
148+
149+ {
150+ // test to make sure that auditing doesn't crash if the record is initialized
151+ // with a 0 event pointer
152+ zorba::audit::ScopedRecord sar(0);
153+ zorba::time::Timer lTimer;
154+ zorba::audit::MicroDurationAuditor auditor(sar, "blub", lTimer);
155+ }
156+
157+
158+ aZorba->getAuditProvider()->destroyConfiguration(config);
159+
160+ return true;
161+}
162+
163+int
164+test_audit(int argc, char* argv[])
165+{
166+ void* store = zorba::StoreManager::getStore();
167+ zorba::Zorba* lZorbaInstance = zorba::Zorba::getInstance(store);
168+
169+ if (!test_audit_1(lZorbaInstance))
170+ {
171+ return 1;
172+ }
173+
174+ if (!test_audit_2(lZorbaInstance))
175+ {
176+ return 2;
177+ }
178
179 return 0;
180 }

Subscribers

People subscribed via source and target branches