~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/embedded_innodb/status_table_function.cc

  • Committer: Brian Aker
  • Date: 2010-04-16 18:34:36 UTC
  • mfrom: (1283.28.40)
  • Revision ID: brian@gaz-20100416183436-e1rr7divbn4rvghi
Merge Stewart.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2010 Stewart Smith
 
3
 
 
4
  This program is free software; you can redistribute it and/or
 
5
  modify it under the terms of the GNU General Public License
 
6
  as published by the Free Software Foundation; either version 2
 
7
  of the License, or (at your option) any later version.
 
8
 
 
9
  This program is distributed in the hope that it will be useful,
 
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
  GNU General Public License for more details.
 
13
 
 
14
  You should have received a copy of the GNU General Public License
 
15
  along with this program; if not, write to the Free Software
 
16
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
17
*/
 
18
 
 
19
#include "config.h"
 
20
#include "drizzled/plugin/table_function.h"
 
21
 
 
22
#include "embedded_innodb-1.0/innodb.h"
 
23
 
 
24
#include "status_table_function.h"
 
25
 
 
26
using namespace std;
 
27
using namespace drizzled;
 
28
 
 
29
class LibInnoDBStatusTool : public drizzled::plugin::TableFunction
 
30
{
 
31
public:
 
32
 
 
33
  LibInnoDBStatusTool();
 
34
 
 
35
  LibInnoDBStatusTool(const char *table_arg) :
 
36
    drizzled::plugin::TableFunction("data_dictionary", table_arg)
 
37
  { }
 
38
 
 
39
  ~LibInnoDBStatusTool() {}
 
40
 
 
41
  class Generator : public drizzled::plugin::TableFunction::Generator
 
42
  {
 
43
  private:
 
44
    uint32_t names_next;
 
45
  public:
 
46
    Generator(drizzled::Field **arg);
 
47
    ~Generator();
 
48
 
 
49
    bool populate();
 
50
  };
 
51
 
 
52
  LibInnoDBStatusTool::Generator *generator(drizzled::Field **arg)
 
53
  {
 
54
    return new Generator(arg);
 
55
  }
 
56
};
 
57
 
 
58
static const char*      libinnodb_status_var_names[] = {
 
59
  "read_req_pending",
 
60
  "write_req_pending",
 
61
  "fsync_req_pending",
 
62
  "write_req_done",
 
63
  "read_req_done",
 
64
  "fsync_req_done",
 
65
  "bytes_total_written",
 
66
  "bytes_total_read",
 
67
 
 
68
  "buffer_pool_current_size",
 
69
  "buffer_pool_data_pages",
 
70
  "buffer_pool_dirty_pages",
 
71
  "buffer_pool_misc_pages",
 
72
  "buffer_pool_free_pages",
 
73
  "buffer_pool_read_reqs",
 
74
  "buffer_pool_reads",
 
75
  "buffer_pool_waited_for_free",
 
76
  "buffer_pool_pages_flushed",
 
77
  "buffer_pool_write_reqs",
 
78
  "buffer_pool_total_pages",
 
79
  "buffer_pool_pages_read",
 
80
  "buffer_pool_pages_written",
 
81
 
 
82
  "double_write_pages_written",
 
83
  "double_write_invoked",
 
84
 
 
85
  "log_buffer_slot_waits",
 
86
  "log_write_reqs",
 
87
  "log_write_flush_count",
 
88
  "log_bytes_written",
 
89
  "log_fsync_req_done",
 
90
  "log_write_req_pending",
 
91
  "log_fsync_req_pending",
 
92
 
 
93
  "lock_row_waits",
 
94
  "lock_row_waiting",
 
95
  "lock_total_wait_time_in_secs",
 
96
  "lock_wait_time_avg_in_secs",
 
97
  "lock_max_wait_time_in_secs",
 
98
 
 
99
  "row_total_read",
 
100
  "row_total_inserted",
 
101
  "row_total_updated",
 
102
  "row_total_deleted",
 
103
 
 
104
  "page_size",
 
105
  "have_atomic_builtins",
 
106
  NULL
 
107
};
 
108
 
 
109
LibInnoDBStatusTool::LibInnoDBStatusTool() :
 
110
  plugin::TableFunction("DATA_DICTIONARY", "INNODB_STATUS")
 
111
{
 
112
  add_field("NAME");
 
113
  add_field("VALUE", plugin::TableFunction::NUMBER);
 
114
}
 
115
 
 
116
LibInnoDBStatusTool::Generator::Generator(Field **arg) :
 
117
  plugin::TableFunction::Generator(arg),
 
118
  names_next(0)
 
119
{
 
120
}
 
121
 
 
122
LibInnoDBStatusTool::Generator::~Generator()
 
123
{
 
124
}
 
125
 
 
126
bool LibInnoDBStatusTool::Generator::populate()
 
127
{
 
128
  if (libinnodb_status_var_names[names_next] != NULL)
 
129
  {
 
130
    const char* config_name= libinnodb_status_var_names[names_next];
 
131
 
 
132
    push(config_name);
 
133
 
 
134
    ib_i64_t value;
 
135
    ib_err_t err= ib_status_get_i64(config_name, &value);
 
136
    assert(err == DB_SUCCESS);
 
137
 
 
138
    push(value);
 
139
 
 
140
    names_next++;
 
141
    return true;
 
142
  }
 
143
 
 
144
  return false; // No more rows
 
145
}
 
146
 
 
147
static LibInnoDBStatusTool *status_tool;
 
148
 
 
149
int status_table_function_initialize(drizzled::plugin::Context &context)
 
150
{
 
151
  status_tool= new(std::nothrow)LibInnoDBStatusTool();
 
152
  context.add(status_tool);
 
153
 
 
154
  return 0;
 
155
}