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 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
20 |
#include "config.h" |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
21 |
#include <drizzled/error.h> |
22 |
#include <drizzled/session.h> |
|
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
23 |
#include "drizzled/internal/m_string.h" |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
24 |
|
25 |
using namespace std; |
|
1093.1.62
by Monty Taylor
Moved UDFs to slot organization. |
26 |
using namespace drizzled; |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
27 |
|
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 |
28 |
class BenchmarkFunction :public Item_int_func |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
29 |
{
|
30 |
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 |
31 |
BenchmarkFunction() :Item_int_func() {} |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
32 |
int64_t val_int(); |
33 |
virtual void print(String *str, enum_query_type query_type); |
|
34 |
||
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 |
35 |
const char *func_name() const |
36 |
{
|
|
1030.3.8
by devananda
formatting cleanup |
37 |
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 |
38 |
}
|
39 |
||
40 |
void fix_length_and_dec() |
|
41 |
{
|
|
1030.3.8
by devananda
formatting cleanup |
42 |
max_length= 1; |
43 |
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 |
44 |
}
|
45 |
||
46 |
bool check_argument_count(int n) |
|
47 |
{
|
|
1030.3.8
by devananda
formatting cleanup |
48 |
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 |
49 |
}
|
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
50 |
};
|
51 |
||
52 |
||
53 |
/* 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 |
54 |
int64_t BenchmarkFunction::val_int() |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
55 |
{
|
1030.3.8
by devananda
formatting cleanup |
56 |
assert(fixed == true); |
57 |
||
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
58 |
char buff[MAX_FIELD_WIDTH]; |
59 |
String tmp(buff,sizeof(buff), &my_charset_bin); |
|
60 |
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 |
61 |
Session *session= current_session; |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
62 |
uint64_t loop_count; |
63 |
||
64 |
loop_count= (uint64_t) args[0]->val_int(); |
|
65 |
||
66 |
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 |
67 |
(args[0]->unsigned_flag == false && (((int64_t) loop_count) < 0))) |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
68 |
{
|
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 |
69 |
if (args[0]->null_value == false) |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
70 |
{
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
71 |
internal::int64_t10_to_str((int64_t)loop_count, buff, -10); |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
72 |
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
73 |
ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE), |
|
74 |
"count", buff, "benchmark"); |
|
75 |
}
|
|
76 |
||
1030.3.8
by devananda
formatting cleanup |
77 |
null_value= true; |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
78 |
return 0; |
79 |
}
|
|
80 |
||
1030.3.8
by devananda
formatting cleanup |
81 |
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 |
82 |
|
83 |
uint64_t loop; |
|
1910.2.8
by Brian Aker
Enapsulate Kill. |
84 |
for (loop= 0 ; loop < loop_count && not session->getKilled(); loop++) |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
85 |
{
|
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 |
86 |
switch (args[1]->result_type()) |
87 |
{
|
|
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
88 |
case REAL_RESULT: |
89 |
(void) args[1]->val_real(); |
|
90 |
break; |
|
91 |
case INT_RESULT: |
|
92 |
(void) args[1]->val_int(); |
|
93 |
break; |
|
94 |
case STRING_RESULT: |
|
95 |
(void) args[1]->val_str(&tmp); |
|
96 |
break; |
|
97 |
case DECIMAL_RESULT: |
|
98 |
(void) args[1]->val_decimal(&tmp_decimal); |
|
99 |
break; |
|
100 |
case ROW_RESULT: |
|
101 |
default: |
|
102 |
// This case should never be chosen
|
|
103 |
assert(0); |
|
104 |
return 0; |
|
105 |
}
|
|
106 |
}
|
|
107 |
return 0; |
|
108 |
}
|
|
109 |
||
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 |
110 |
void BenchmarkFunction::print(String *str, enum_query_type query_type) |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
111 |
{
|
112 |
str->append(STRING_WITH_LEN("benchmark(")); |
|
113 |
args[0]->print(str, query_type); |
|
114 |
str->append(','); |
|
115 |
args[1]->print(str, query_type); |
|
116 |
str->append(')'); |
|
117 |
}
|
|
118 |
||
1093.1.62
by Monty Taylor
Moved UDFs to slot organization. |
119 |
plugin::Create_function<BenchmarkFunction> *benchmarkudf= NULL; |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
120 |
|
1530.2.6
by Monty Taylor
Moved plugin::Context to module::Context. |
121 |
static int initialize(module::Context &context) |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
122 |
{
|
1093.1.62
by Monty Taylor
Moved UDFs to slot organization. |
123 |
benchmarkudf= new plugin::Create_function<BenchmarkFunction>("benchmark"); |
1324.2.2
by Monty Taylor
Use the plugin::Context everywhere. |
124 |
context.add(benchmarkudf); |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
125 |
return 0; |
126 |
}
|
|
127 |
||
1228.1.5
by Monty Taylor
Merged in some naming things. |
128 |
DRIZZLE_DECLARE_PLUGIN
|
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
129 |
{
|
1241.10.2
by Monty Taylor
Added support for embedding the drizzle version number in the plugin file. |
130 |
DRIZZLE_VERSION_ID, |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
131 |
"benchmark", |
1030.3.8
by devananda
formatting cleanup |
132 |
"1.0", |
1030.3.5
by devananda
refactored function/benchmark into plugin/benchmark |
133 |
"Devananda van der Veen", |
134 |
"Measure time for repeated calls to a function.", |
|
135 |
PLUGIN_LICENSE_GPL, |
|
136 |
initialize, /* Plugin Init */ |
|
137 |
NULL, /* system variables */ |
|
138 |
NULL /* config options */ |
|
139 |
}
|
|
1228.1.5
by Monty Taylor
Merged in some naming things. |
140 |
DRIZZLE_DECLARE_PLUGIN_END; |