summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugin/proc_info/CMakeLists.txt1
-rw-r--r--plugin/proc_info/mysql-test/proc_info/basic.test3
-rw-r--r--plugin/proc_info/mysql-test/proc_info/suite.opt1
-rw-r--r--plugin/proc_info/mysql-test/proc_info/suite.pm13
-rw-r--r--plugin/proc_info/proc_info.cc76
5 files changed, 94 insertions, 0 deletions
diff --git a/plugin/proc_info/CMakeLists.txt b/plugin/proc_info/CMakeLists.txt
new file mode 100644
index 00000000000..8a97c6bd5b9
--- /dev/null
+++ b/plugin/proc_info/CMakeLists.txt
@@ -0,0 +1 @@
+MYSQL_ADD_PLUGIN(PROC_INFO proc_info.cc RECOMPILE_FOR_EMBEDDED)
diff --git a/plugin/proc_info/mysql-test/proc_info/basic.test b/plugin/proc_info/mysql-test/proc_info/basic.test
new file mode 100644
index 00000000000..c3c48387c76
--- /dev/null
+++ b/plugin/proc_info/mysql-test/proc_info/basic.test
@@ -0,0 +1,3 @@
+SHOW CREATE TABLE INFORMATION_SCHEMA.PROC_MEMINFO;
+query_vertical SELECT PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_TYPE, PLUGIN_AUTHOR, PLUGIN_DESCRIPTION, PLUGIN_LICENSE, PLUGIN_MATURITY FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME='proc_meminfo';
+SELECT * FROM INFORMATION_SCHEMA.PROC_MEMINFO;
diff --git a/plugin/proc_info/mysql-test/proc_info/suite.opt b/plugin/proc_info/mysql-test/proc_info/suite.opt
new file mode 100644
index 00000000000..516e733128a
--- /dev/null
+++ b/plugin/proc_info/mysql-test/proc_info/suite.opt
@@ -0,0 +1 @@
+--plugin-load-add=$PROC_INFO_SO --plugin-proc-meminfo=ON
diff --git a/plugin/proc_info/mysql-test/proc_info/suite.pm b/plugin/proc_info/mysql-test/proc_info/suite.pm
new file mode 100644
index 00000000000..d66d091fd89
--- /dev/null
+++ b/plugin/proc_info/mysql-test/proc_info/suite.pm
@@ -0,0 +1,13 @@
+package My::Suite::Proc_info;
+
+@ISA = qw(My::Suite);
+
+return "No PROC_INFO plugin" unless
+ $ENV{PROC_INFO_SO} or
+ $::mysqld_variables{'proc-info'} eq "ON";
+
+return "Not run for embedded server" if $::opt_embedded_server;
+
+sub is_default { 1 }
+
+bless { };
diff --git a/plugin/proc_info/proc_info.cc b/plugin/proc_info/proc_info.cc
new file mode 100644
index 00000000000..1ad867f27b4
--- /dev/null
+++ b/plugin/proc_info/proc_info.cc
@@ -0,0 +1,76 @@
+#include <my_global.h>
+#include <table.h>
+#include <sql_show.h>
+#include <sql_class.h>
+#include <mysql/plugin.h>
+
+
+static ST_FIELD_INFO fields[]=
+{
+ { "NAME", 100, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE },
+ { "VALUE", 21, MYSQL_TYPE_LONG, 0, MY_I_S_UNSIGNED, 0, SKIP_OPEN_TABLE },
+ { 0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0 }
+};
+
+
+static int fill(MYSQL_THD thd, TABLE_LIST *tables, COND *cond)
+{
+ TABLE *table= tables->table;
+ char name[1024];
+ unsigned long value;
+ FILE *fp;
+ int res;
+
+ if (!(fp= fopen("/proc/meminfo", "r")))
+ return 1;
+
+ while ((res= fscanf(fp, "%[^:]: %lu kB\n", name, &value)) != EOF)
+ {
+ if (res != 2)
+ continue;
+ table->field[0]->store(name, strlen(name), system_charset_info);
+ table->field[1]->store(value);
+ if (schema_table_store_record(thd, table))
+ {
+ fclose(fp);
+ return 1;
+ }
+ }
+ fclose(fp);
+
+ return 0;
+}
+
+
+static int init(void *p)
+{
+ ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *) p;
+
+ schema->fields_info= fields;
+ schema->fill_table= fill;
+
+ return 0;
+}
+
+
+static struct st_mysql_information_schema plugin=
+{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };
+
+
+maria_declare_plugin(proc_info)
+{
+ MYSQL_INFORMATION_SCHEMA_PLUGIN, /* type */
+ &plugin, /* information schema */
+ "PROC_MEMINFO", /* name */
+ "" , /* author */
+ "Useful information from /proc", /* description */
+ PLUGIN_LICENSE_BSD, /* license */
+ init, /* init callback */
+ 0, /* deinit callback */
+ 0x0100, /* version as hex */
+ NULL, /* status variables */
+ NULL, /* system variables */
+ "1.0", /* version as a string */
+ MariaDB_PLUGIN_MATURITY_EXPERIMENTAL
+}
+maria_declare_plugin_end;