~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/benchmark/benchmarkudf.cc

  • Committer: Brian Aker
  • Date: 2009-08-21 18:46:31 UTC
  • mto: This revision was merged to the branch mainline in revision 1123.
  • Revision ID: brian@gaz-20090821184631-e11gja79070fvhk4
Cleanup around page checksum removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
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 
 
18
 */
 
19
 
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/error.h>
 
22
#include <drizzled/session.h>
 
23
 
 
24
using namespace std;
 
25
using namespace drizzled;
 
26
 
 
27
class BenchmarkFunction :public Item_int_func
 
28
{
 
29
public:
 
30
  BenchmarkFunction() :Item_int_func() {}
 
31
  int64_t val_int();
 
32
  virtual void print(String *str, enum_query_type query_type);
 
33
 
 
34
  const char *func_name() const
 
35
  { 
 
36
    return "benchmark"; 
 
37
  }
 
38
 
 
39
  void fix_length_and_dec()
 
40
  { 
 
41
    max_length= 1; 
 
42
    maybe_null= false;
 
43
  }
 
44
 
 
45
  bool check_argument_count(int n)
 
46
  { 
 
47
    return (n == 2); 
 
48
  }
 
49
};
 
50
 
 
51
 
 
52
/* This function is just used to test speed of different functions */
 
53
int64_t BenchmarkFunction::val_int()
 
54
{
 
55
  assert(fixed == true);
 
56
 
 
57
  char buff[MAX_FIELD_WIDTH];
 
58
  String tmp(buff,sizeof(buff), &my_charset_bin);
 
59
  my_decimal tmp_decimal;
 
60
  Session *session= current_session;
 
61
  uint64_t loop_count;
 
62
 
 
63
  loop_count= (uint64_t) args[0]->val_int();
 
64
 
 
65
  if (args[0]->null_value ||
 
66
      (args[0]->unsigned_flag == false && (((int64_t) loop_count) < 0)))
 
67
  {
 
68
    if (args[0]->null_value == false)
 
69
    {
 
70
      llstr(((int64_t) loop_count), buff);
 
71
      push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
72
                          ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
 
73
                          "count", buff, "benchmark");
 
74
    }
 
75
 
 
76
    null_value= true;
 
77
    return 0;
 
78
  }
 
79
 
 
80
  null_value= false;
 
81
 
 
82
  uint64_t loop;
 
83
  for (loop= 0 ; loop < loop_count && !session->killed; loop++)
 
84
  {
 
85
    switch (args[1]->result_type()) 
 
86
    {
 
87
    case REAL_RESULT:
 
88
      (void) args[1]->val_real();
 
89
      break;
 
90
    case INT_RESULT:
 
91
      (void) args[1]->val_int();
 
92
      break;
 
93
    case STRING_RESULT:
 
94
      (void) args[1]->val_str(&tmp);
 
95
      break;
 
96
    case DECIMAL_RESULT:
 
97
      (void) args[1]->val_decimal(&tmp_decimal);
 
98
      break;
 
99
    case ROW_RESULT:
 
100
    default:
 
101
      // This case should never be chosen
 
102
      assert(0);
 
103
      return 0;
 
104
    }
 
105
  }
 
106
  return 0;
 
107
}
 
108
 
 
109
void BenchmarkFunction::print(String *str, enum_query_type query_type)
 
110
{
 
111
  str->append(STRING_WITH_LEN("benchmark("));
 
112
  args[0]->print(str, query_type);
 
113
  str->append(',');
 
114
  args[1]->print(str, query_type);
 
115
  str->append(')');
 
116
}
 
117
 
 
118
plugin::Create_function<BenchmarkFunction> *benchmarkudf= NULL;
 
119
 
 
120
static int initialize(plugin::Registry &registry)
 
121
{
 
122
  benchmarkudf= new plugin::Create_function<BenchmarkFunction>("benchmark");
 
123
  registry.function.add(benchmarkudf);
 
124
  return 0;
 
125
}
 
126
 
 
127
static int finalize(plugin::Registry &registry)
 
128
{
 
129
   registry.function.remove(benchmarkudf);
 
130
   delete benchmarkudf;
 
131
   return 0;
 
132
}
 
133
 
 
134
drizzle_declare_plugin(benchmark)
 
135
{
 
136
  "benchmark",
 
137
  "1.0",
 
138
  "Devananda van der Veen",
 
139
  "Measure time for repeated calls to a function.",
 
140
  PLUGIN_LICENSE_GPL,
 
141
  initialize, /* Plugin Init */
 
142
  finalize,   /* Plugin Deinit */
 
143
  NULL,   /* status variables */
 
144
  NULL,   /* system variables */
 
145
  NULL    /* config options */
 
146
}
 
147
drizzle_declare_plugin_end;