Merge lp:~lefred/percona-playback/percona-playback into lp:percona-playback

Proposed by Frederic Descamps
Status: Merged
Merged at revision: 165
Proposed branch: lp:~lefred/percona-playback/percona-playback
Merge into: lp:percona-playback
Diff against target: 345 lines (+312/-1)
5 files modified
percona-playback.spec (+1/-1)
percona_playback/error_report/error_report.cc (+107/-0)
percona_playback/error_report/plugin.ini (+6/-0)
percona_playback/full_report/full_report.cc (+192/-0)
percona_playback/full_report/plugin.ini (+6/-0)
To merge this branch: bzr merge lp:~lefred/percona-playback/percona-playback
Reviewer Review Type Date Requested Status
Percona core Pending
Review via email: mp+127710@code.launchpad.net

Description of the change

Add two experimental reports plugins:

report_error: displays all queries that are slower
report_full: displays some statistics related to query types (SELECT, INSERT, UPDATE...)

the way I define the types should be improved, but I don't really know the best method ? using regex ?

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'percona-playback.spec'
2--- percona-playback.spec 2012-09-14 05:34:21 +0000
3+++ percona-playback.spec 2012-10-03 10:52:21 +0000
4@@ -23,7 +23,7 @@
5
6 Name: percona-playback
7 Version: 0.4
8-Release: 1%{?dist}
9+Release: 2%{?dist}
10 Summary: A tool for replaying captured database server load
11
12 License: GPL
13
14=== added directory 'percona_playback/error_report'
15=== added file 'percona_playback/error_report/error_report.cc'
16--- percona_playback/error_report/error_report.cc 1970-01-01 00:00:00 +0000
17+++ percona_playback/error_report/error_report.cc 2012-10-03 10:52:21 +0000
18@@ -0,0 +1,107 @@
19+/* BEGIN LICENSE
20+ * Copyright (C) 2011-2012 Percona Inc.
21+ * This program is free software: you can redistribute it and/or modify it
22+ * under the terms of the GNU General Public License version 2, as published
23+ * by the Free Software Foundation.
24+ *
25+ * This program is distributed in the hope that it will be useful, but
26+ * WITHOUT ANY WARRANTY; without even the implied warranties of
27+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
28+ * PURPOSE. See the GNU General Public License for more details.
29+ *
30+ * You should have received a copy of the GNU General Public License along
31+ * with this program. If not, see <http://www.gnu.org/licenses/>.
32+ * END LICENSE */
33+
34+#include <cstdio>
35+#include <cstdlib>
36+#include <iostream>
37+#define __STDC_FORMAT_MACROS
38+#include <inttypes.h>
39+
40+#include <boost/foreach.hpp>
41+#include <boost/program_options.hpp>
42+
43+#include <tbb/tbb_stddef.h>
44+
45+/* We're all conditional here because TBB in CentOS 6 is old */
46+#if TBB_VERSION_MAJOR < 3
47+#include <boost/unordered_map.hpp>
48+#include <tbb/mutex.h>
49+#else
50+#include <tbb/concurrent_unordered_map.h>
51+#endif
52+
53+#include <tbb/atomic.h>
54+#include <percona_playback/plugin.h>
55+#include <percona_playback/query_result.h>
56+#include <percona_playback/gettext.h>
57+
58+class ErrorReportPlugin : public percona_playback::ReportPlugin
59+{
60+private:
61+ tbb::atomic<uint64_t> total_execution_time_ms;
62+ tbb::atomic<uint64_t> expected_total_execution_time_ms;
63+ tbb::atomic<uint64_t> nr_quicker_queries;
64+ std::string full_report;
65+
66+#if TBB_VERSION_MAJOR < 3
67+ tbb::mutex connection_query_count_mutex;
68+ typedef boost::unordered_map<uint64_t, tbb::atomic<uint64_t> > ConnectionQueryCountMap;
69+#else
70+ typedef tbb::concurrent_unordered_map<uint64_t, tbb::atomic<uint64_t> > ConnectionQueryCountMap;
71+#endif
72+
73+ typedef std::pair<uint64_t, tbb::atomic<uint64_t> > ConnectionQueryCountPair;
74+ typedef std::map<uint64_t, uint64_t> SortedConnectionQueryCountMap;
75+ typedef std::pair<uint64_t, uint64_t> SortedConnectionQueryCountPair;
76+
77+ ConnectionQueryCountMap connection_query_counts;
78+
79+
80+public:
81+ ErrorReportPlugin(std::string _name) : ReportPlugin(_name)
82+ {
83+ total_execution_time_ms= 0;
84+ expected_total_execution_time_ms= 0;
85+ nr_quicker_queries= 0;
86+ full_report = "";
87+ }
88+
89+ virtual void query_execution(const uint64_t thread_id,
90+ const std::string &query,
91+ const QueryResult &expected,
92+ const QueryResult &actual)
93+ {
94+ // fprintf(stderr,_("Error query: %s\n"), query.c_str());
95+
96+ total_execution_time_ms.fetch_and_add(actual.getDuration().total_microseconds());
97+
98+ if (expected.getDuration().total_microseconds())
99+ {
100+ expected_total_execution_time_ms.fetch_and_add(expected.getDuration().total_microseconds());
101+ if (actual.getDuration().total_microseconds() > expected.getDuration().total_microseconds())
102+ {
103+ printf(_("thread %" PRIu64 " slower query was run in %" PRIu64 " microseconds instead of %" PRIu64 "\n <--\n%s -->\n"),
104+ uint64_t(thread_id),
105+ uint64_t(actual.getDuration().total_microseconds()),
106+ uint64_t(expected.getDuration().total_microseconds()),
107+ query.c_str());
108+ }
109+ }
110+ }
111+
112+ virtual void print_report()
113+ {
114+ printf(_("Error Report finished\n\n\n"));
115+ }
116+
117+
118+};
119+
120+static void init_plugin(percona_playback::PluginRegistry &r)
121+{
122+ r.add("error_report", new ErrorReportPlugin("error_report"));
123+}
124+
125+PERCONA_PLAYBACK_PLUGIN(init_plugin);
126
127=== added file 'percona_playback/error_report/plugin.ini'
128--- percona_playback/error_report/plugin.ini 1970-01-01 00:00:00 +0000
129+++ percona_playback/error_report/plugin.ini 2012-10-03 10:52:21 +0000
130@@ -0,0 +1,6 @@
131+[plugin]
132+title=Error Reporter
133+description=This provides an error report of the run
134+version=0.1
135+static=yes
136+load_by_default=yes
137
138=== added directory 'percona_playback/full_report'
139=== added file 'percona_playback/full_report/full_report.cc'
140--- percona_playback/full_report/full_report.cc 1970-01-01 00:00:00 +0000
141+++ percona_playback/full_report/full_report.cc 2012-10-03 10:52:21 +0000
142@@ -0,0 +1,192 @@
143+/* BEGIN LICENSE
144+ * Copyright (C) 2011-2012 Percona Inc.
145+ * This program is free software: you can redistribute it and/or modify it
146+ * under the terms of the GNU General Public License version 2, as published
147+ * by the Free Software Foundation.
148+ *
149+ * This program is distributed in the hope that it will be useful, but
150+ * WITHOUT ANY WARRANTY; without even the implied warranties of
151+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
152+ * PURPOSE. See the GNU General Public License for more details.
153+ *
154+ * You should have received a copy of the GNU General Public License along
155+ * with this program. If not, see <http://www.gnu.org/licenses/>.
156+ * END LICENSE */
157+
158+#include <cstdio>
159+#include <cstdlib>
160+#include <iostream>
161+#define __STDC_FORMAT_MACROS
162+#include <inttypes.h>
163+
164+#include <boost/foreach.hpp>
165+#include <boost/program_options.hpp>
166+
167+#include <tbb/tbb_stddef.h>
168+
169+/* We're all conditional here because TBB in CentOS 6 is old */
170+#if TBB_VERSION_MAJOR < 3
171+#include <boost/unordered_map.hpp>
172+#include <tbb/mutex.h>
173+#else
174+#include <tbb/concurrent_unordered_map.h>
175+#endif
176+
177+#include <tbb/atomic.h>
178+#include <percona_playback/plugin.h>
179+#include <percona_playback/query_result.h>
180+#include <percona_playback/gettext.h>
181+
182+class FullReportPlugin : public percona_playback::ReportPlugin
183+{
184+private:
185+ tbb::atomic<uint64_t> nr_select;
186+ tbb::atomic<uint64_t> nr_select_faster;
187+ tbb::atomic<uint64_t> nr_select_slower;
188+ tbb::atomic<uint64_t> nr_update;
189+ tbb::atomic<uint64_t> nr_update_faster;
190+ tbb::atomic<uint64_t> nr_update_slower;
191+ tbb::atomic<uint64_t> nr_insert;
192+ tbb::atomic<uint64_t> nr_insert_faster;
193+ tbb::atomic<uint64_t> nr_insert_slower;
194+ tbb::atomic<uint64_t> nr_delete;
195+ tbb::atomic<uint64_t> nr_delete_faster;
196+ tbb::atomic<uint64_t> nr_delete_slower;
197+ tbb::atomic<uint64_t> nr_replace;
198+ tbb::atomic<uint64_t> nr_replace_faster;
199+ tbb::atomic<uint64_t> nr_replace_slower;
200+ tbb::atomic<uint64_t> nr_drop;
201+ tbb::atomic<uint64_t> nr_drop_faster;
202+ tbb::atomic<uint64_t> nr_drop_slower;
203+ tbb::atomic<uint64_t> total_execution_time_ms;
204+ tbb::atomic<uint64_t> expected_total_execution_time_ms;
205+
206+#if TBB_VERSION_MAJOR < 3
207+ tbb::mutex connection_query_count_mutex;
208+ typedef boost::unordered_map<uint64_t, tbb::atomic<uint64_t> > ConnectionQueryCountMap;
209+#else
210+ typedef tbb::concurrent_unordered_map<uint64_t, tbb::atomic<uint64_t> > ConnectionQueryCountMap;
211+#endif
212+
213+ typedef std::pair<uint64_t, tbb::atomic<uint64_t> > ConnectionQueryCountPair;
214+ typedef std::map<uint64_t, uint64_t> SortedConnectionQueryCountMap;
215+ typedef std::pair<uint64_t, uint64_t> SortedConnectionQueryCountPair;
216+
217+ ConnectionQueryCountMap connection_query_counts;
218+
219+ bool show_connection_query_count;
220+
221+public:
222+ FullReportPlugin(std::string _name) : ReportPlugin(_name)
223+ {
224+ nr_select= 0;
225+ nr_select_faster= 0;
226+ nr_select_slower= 0;
227+ nr_update= 0;
228+ nr_update_faster= 0;
229+ nr_update_slower= 0;
230+ nr_insert= 0;
231+ nr_insert_faster= 0;
232+ nr_insert_slower= 0;
233+ nr_delete= 0;
234+ nr_delete_faster= 0;
235+ nr_delete_slower= 0;
236+ nr_replace= 0;
237+ nr_replace_faster= 0;
238+ nr_replace_slower= 0;
239+ nr_drop= 0;
240+ nr_drop_faster= 0;
241+ nr_drop_slower= 0;
242+ total_execution_time_ms= 0;
243+ expected_total_execution_time_ms= 0;
244+ }
245+
246+
247+ virtual void query_execution(const uint64_t thread_id,
248+ const std::string &query,
249+ const QueryResult &expected,
250+ const QueryResult &actual)
251+ {
252+ (void)thread_id;
253+ (void)expected;
254+ (void)actual;
255+ int faster= 0;
256+ int slower= 0;
257+
258+ total_execution_time_ms.fetch_and_add(actual.getDuration().total_microseconds());
259+
260+ if (expected.getDuration().total_microseconds())
261+ {
262+ expected_total_execution_time_ms.fetch_and_add(expected.getDuration().total_microseconds());
263+ if (actual.getDuration().total_microseconds() < expected.getDuration().total_microseconds())
264+ {
265+ faster= 1;
266+ slower= 0;
267+ }
268+ else
269+ {
270+ faster= 0;
271+ slower= 1;
272+ }
273+ }
274+
275+ std::string new_query = boost::to_upper_copy(query);
276+
277+ if (new_query.find("\nSELECT ") != std::string::npos)
278+ {
279+ nr_select++;
280+ nr_select_faster+= faster;
281+ nr_select_slower+= slower;
282+ }
283+ else if (new_query.find("\nUPDATE ") != std::string::npos)
284+ {
285+ nr_update++;
286+ nr_update_faster+= faster;
287+ nr_update_slower+= slower;
288+ }
289+ else if (new_query.find("\nINSERT ") != std::string::npos)
290+ {
291+ nr_insert++;
292+ nr_insert_faster+= faster;
293+ nr_insert_slower+= slower;
294+ }
295+ else if (new_query.find("\nDELETE ") != std::string::npos)
296+ {
297+ nr_delete++;
298+ nr_delete_faster+= faster;
299+ nr_delete_slower+= slower;
300+ }
301+ else if (new_query.find("\nREPLACE ") != std::string::npos)
302+ {
303+ nr_replace++;
304+ nr_replace_faster+= faster;
305+ nr_replace_slower+= slower;
306+ }
307+ else if (new_query.find("\nDROP ") != std::string::npos)
308+ {
309+ nr_drop++;
310+ nr_drop_faster+= faster;
311+ nr_drop_slower+= slower;
312+ }
313+
314+ }
315+
316+ virtual void print_report()
317+ {
318+ printf(_("Detailed Report\n----------------\n"));
319+ printf(_("SELECTs : %" PRIu64 " queries (%" PRIu64 " faster, %" PRIu64 " slower)\n"), uint64_t(nr_select), uint64_t(nr_select_faster), uint64_t(nr_select_slower));
320+ printf(_("INSERTs : %" PRIu64 " queries (%" PRIu64 " faster, %" PRIu64 " slower)\n"), uint64_t(nr_insert), uint64_t(nr_insert_faster), uint64_t(nr_insert_slower));
321+ printf(_("UPDATEs : %" PRIu64 " queries (%" PRIu64 " faster, %" PRIu64 " slower)\n"), uint64_t(nr_update), uint64_t(nr_update_faster), uint64_t(nr_update_slower));
322+ printf(_("DELETEs : %" PRIu64 " queries (%" PRIu64 " faster, %" PRIu64 " slower)\n"), uint64_t(nr_delete), uint64_t(nr_delete_faster), uint64_t(nr_delete_slower));
323+ printf(_("REPLACEs : %" PRIu64 " queries (%" PRIu64 " faster, %" PRIu64 " slower)\n"), uint64_t(nr_replace), uint64_t(nr_replace_faster), uint64_t(nr_replace_slower));
324+ printf(_("DROPs : %" PRIu64 " queries (%" PRIu64 " faster, %" PRIu64 " slower)\n\n\n"), uint64_t(nr_drop), uint64_t(nr_drop_faster), uint64_t(nr_drop_slower));
325+ }
326+
327+};
328+
329+static void init_plugin(percona_playback::PluginRegistry &r)
330+{
331+ r.add("full_report", new FullReportPlugin("full_report"));
332+}
333+
334+PERCONA_PLAYBACK_PLUGIN(init_plugin);
335
336=== added file 'percona_playback/full_report/plugin.ini'
337--- percona_playback/full_report/plugin.ini 1970-01-01 00:00:00 +0000
338+++ percona_playback/full_report/plugin.ini 2012-10-03 10:52:21 +0000
339@@ -0,0 +1,6 @@
340+[plugin]
341+title=Full Reporter
342+description=This provides a full report of the run
343+version=0.1
344+static=yes
345+load_by_default=yes

Subscribers

People subscribed via source and target branches