1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
3 |
*
|
4 |
* Copyright (C) 2008 MySQL AB
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
18 |
*/
|
19 |
||
20 |
#include <drizzled/server_includes.h> |
|
21 |
#include <drizzled/error.h> |
|
22 |
#include <drizzled/session.h> |
|
23 |
||
24 |
using namespace std; |
|
25 |
||
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
26 |
class BenchmarkFunction :public Item_int_func |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
27 |
{
|
28 |
public: |
|
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
29 |
BenchmarkFunction() :Item_int_func() {} |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
30 |
int64_t val_int(); |
31 |
virtual void print(String *str, enum_query_type query_type); |
|
32 |
||
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
33 |
const char *func_name() const |
34 |
{
|
|
1030.3.8
by devananda
formatting cleanup |
35 |
return "benchmark"; |
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
36 |
}
|
37 |
||
38 |
void fix_length_and_dec() |
|
39 |
{
|
|
1030.3.8
by devananda
formatting cleanup |
40 |
max_length= 1; |
41 |
maybe_null= false; |
|
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
42 |
}
|
43 |
||
44 |
bool check_argument_count(int n) |
|
45 |
{
|
|
1030.3.8
by devananda
formatting cleanup |
46 |
return (n == 2); |
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
47 |
}
|
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
48 |
};
|
49 |
||
50 |
||
51 |
/* This function is just used to test speed of different functions */
|
|
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
52 |
int64_t BenchmarkFunction::val_int() |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
53 |
{
|
1030.3.8
by devananda
formatting cleanup |
54 |
assert(fixed == true); |
55 |
||
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
56 |
char buff[MAX_FIELD_WIDTH]; |
57 |
String tmp(buff,sizeof(buff), &my_charset_bin); |
|
58 |
my_decimal tmp_decimal; |
|
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
59 |
Session *session= current_session; |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
60 |
uint64_t loop_count; |
61 |
||
62 |
loop_count= (uint64_t) args[0]->val_int(); |
|
63 |
||
64 |
if (args[0]->null_value || |
|
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
65 |
(args[0]->unsigned_flag == false && (((int64_t) loop_count) < 0))) |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
66 |
{
|
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
67 |
if (args[0]->null_value == false) |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
68 |
{
|
69 |
llstr(((int64_t) loop_count), buff); |
|
70 |
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
|
71 |
ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE), |
|
72 |
"count", buff, "benchmark"); |
|
73 |
}
|
|
74 |
||
1030.3.8
by devananda
formatting cleanup |
75 |
null_value= true; |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
76 |
return 0; |
77 |
}
|
|
78 |
||
1030.3.8
by devananda
formatting cleanup |
79 |
null_value= false; |
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
80 |
|
81 |
uint64_t loop; |
|
82 |
for (loop= 0 ; loop < loop_count && !session->killed; loop++) |
|
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
83 |
{
|
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
84 |
switch (args[1]->result_type()) |
85 |
{
|
|
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
86 |
case REAL_RESULT: |
87 |
(void) args[1]->val_real(); |
|
88 |
break; |
|
89 |
case INT_RESULT: |
|
90 |
(void) args[1]->val_int(); |
|
91 |
break; |
|
92 |
case STRING_RESULT: |
|
93 |
(void) args[1]->val_str(&tmp); |
|
94 |
break; |
|
95 |
case DECIMAL_RESULT: |
|
96 |
(void) args[1]->val_decimal(&tmp_decimal); |
|
97 |
break; |
|
98 |
case ROW_RESULT: |
|
99 |
default: |
|
100 |
// This case should never be chosen
|
|
101 |
assert(0); |
|
102 |
return 0; |
|
103 |
}
|
|
104 |
}
|
|
105 |
return 0; |
|
106 |
}
|
|
107 |
||
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
108 |
void BenchmarkFunction::print(String *str, enum_query_type query_type) |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
109 |
{
|
110 |
str->append(STRING_WITH_LEN("benchmark(")); |
|
111 |
args[0]->print(str, query_type); |
|
112 |
str->append(','); |
|
113 |
args[1]->print(str, query_type); |
|
114 |
str->append(')'); |
|
115 |
}
|
|
116 |
||
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
117 |
Create_function<BenchmarkFunction> benchmarkudf(string("benchmark")); |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
118 |
|
119 |
static int initialize(PluginRegistry ®istry) |
|
120 |
{
|
|
121 |
registry.add(&benchmarkudf); |
|
122 |
return 0; |
|
123 |
}
|
|
124 |
||
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
125 |
static int finalize(PluginRegistry ®istry) |
126 |
{
|
|
127 |
registry.remove(&benchmarkudf); |
|
128 |
return 0; |
|
129 |
}
|
|
130 |
||
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
131 |
drizzle_declare_plugin(benchmark) |
132 |
{
|
|
133 |
"benchmark", |
|
1030.3.8
by devananda
formatting cleanup |
134 |
"1.0", |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
135 |
"Devananda van der Veen", |
136 |
"Measure time for repeated calls to a function.", |
|
137 |
PLUGIN_LICENSE_GPL, |
|
138 |
initialize, /* Plugin Init */ |
|
1030.3.7
by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup |
139 |
finalize, /* Plugin Deinit */ |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
140 |
NULL, /* status variables */ |
141 |
NULL, /* system variables */ |
|
142 |
NULL /* config options */ |
|
143 |
}
|
|
144 |
drizzle_declare_plugin_end; |