~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/performance_dictionary/session_usage.cc

  • Committer: Brian Aker
  • Date: 2010-09-16 04:15:39 UTC
  • mto: (1787.4.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1790.
  • Revision ID: brian@tangent.org-20100916041539-rayzd1qz1lpnkr6i
First pass at session_usage.

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) 2010 Brian Aker
 
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; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include "plugin/performance_dictionary/dictionary.h"
 
24
 
 
25
#include <drizzled/atomics.h>
 
26
#include <drizzled/session.h>
 
27
 
 
28
#include <sys/resource.h>
 
29
 
 
30
#ifdef RUSAGE_THREAD
 
31
#define USAGE_VISABILITY RUSAGE_THREAD
 
32
#else
 
33
#define USAGE_VISABILITY  RUSAGE_SELF
 
34
#endif
 
35
 
 
36
using namespace drizzled;
 
37
using namespace std;
 
38
 
 
39
#define FUNCTION_NAME_LEN 64
 
40
 
 
41
performance_dictionary::SessionUsage::SessionUsage() :
 
42
  plugin::TableFunction("DATA_DICTIONARY", "SESSION_USAGE")
 
43
{
 
44
  add_field("QUERY", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
 
45
  add_field("USER_TIME_USED_SECONDS", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
 
46
  add_field("USER_TIME_USED_MICRO_SECONDS", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
 
47
  add_field("SYSTEM_TIME_USED_SECONDS", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
 
48
  add_field("SYSTEM_TIME_USED_MICRO_SECONDS", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
 
49
  add_field("INTEGRAL_MAX_RESIDENT_SET_SIZE", plugin::TableFunction::NUMBER, 0, false);
 
50
  add_field("INTEGRAL_SHARED_TEXT_MEMORY_SIZE", plugin::TableFunction::NUMBER, 0, false);
 
51
  add_field("INTEGRAL_UNSHARED_DATA_SIZE", plugin::TableFunction::NUMBER, 0, false);
 
52
  add_field("INTEGRAL_UNSHARED_STACK_SIZE", plugin::TableFunction::NUMBER, 0, false);
 
53
  add_field("PAGE_RECLAIMS", plugin::TableFunction::NUMBER, 0, false);
 
54
  add_field("PAGE_FAULTS", plugin::TableFunction::NUMBER, 0, false);
 
55
  add_field("SWAPS", plugin::TableFunction::NUMBER, 0, false);
 
56
  add_field("BLOCK_INPUT_OPERATIONS", plugin::TableFunction::NUMBER, 0, false);
 
57
  add_field("BLOCK_OUTPUT_OPERATIONS", plugin::TableFunction::NUMBER, 0, false);
 
58
  add_field("MESSAGES_SENT", plugin::TableFunction::NUMBER, 0, false);
 
59
  add_field("MESSAGES_RECEIVED", plugin::TableFunction::NUMBER, 0, false);
 
60
  add_field("SIGNALS_RECEIVED", plugin::TableFunction::NUMBER, 0, false);
 
61
  add_field("VOLUNTARY_CONTEXT_SWITCHES", plugin::TableFunction::NUMBER, 0, false);
 
62
  add_field("INVOLUNTARY_CONTEXT_SWITCHES", plugin::TableFunction::NUMBER, 0, false);
 
63
}
 
64
 
 
65
bool performance_dictionary::SessionUsage::Generator::populate()
 
66
{
 
67
  struct rusage r_usage;
 
68
 
 
69
  if (once)
 
70
    return false;
 
71
  once= true;
 
72
 
 
73
  if (getrusage(USAGE_VISABILITY, &r_usage))
 
74
  {
 
75
    return false;
 
76
  }
 
77
 
 
78
  /* USER_TIME_USED_SECONDS */
 
79
  push("CONNECT");
 
80
 
 
81
  /* USER_TIME_USED_SECONDS */
 
82
  push(static_cast<int64_t>(r_usage.ru_utime.tv_sec));
 
83
 
 
84
  /* USER_TIME_USED_MICRO_SECONDS */
 
85
  push(static_cast<int64_t>(r_usage.ru_utime.tv_usec));
 
86
 
 
87
  /* SYSTEM_TIME_USED_SECONDS */
 
88
  push(static_cast<int64_t>(r_usage.ru_stime.tv_sec));
 
89
 
 
90
  /* SYSTEM_TIME_USED_MICRO_SECONDS */
 
91
  push(static_cast<int64_t>(r_usage.ru_stime.tv_usec));
 
92
 
 
93
  /* INTEGRAL_MAX_RESIDENT_SET_SIZE */
 
94
  push(static_cast<int64_t>(r_usage.ru_maxrss));
 
95
 
 
96
  /* INTEGRAL_SHARED_TEXT_MEMORY_SIZE */
 
97
  push(static_cast<int64_t>(r_usage.ru_ixrss));
 
98
 
 
99
  /* INTEGRAL_UNSHARED_DATA_SIZE */
 
100
  push(static_cast<int64_t>(r_usage.ru_idrss));
 
101
 
 
102
  /* INTEGRAL_UNSHARED_STACK_SIZE */
 
103
  push(static_cast<int64_t>(r_usage.ru_isrss));
 
104
 
 
105
  /* PAGE_RECLAIMS */
 
106
  push(static_cast<int64_t>(r_usage.ru_minflt));
 
107
 
 
108
  /* PAGE_FAULTS */
 
109
  push(static_cast<int64_t>(r_usage.ru_majflt));
 
110
 
 
111
  /* SWAPS */
 
112
  push(static_cast<int64_t>(r_usage.ru_nswap));
 
113
 
 
114
  /* BLOCK_INPUT_OPERATIONS */
 
115
  push(static_cast<int64_t>(r_usage.ru_inblock));
 
116
 
 
117
  /* BLOCK_OUTPUT_OPERATIONS */
 
118
  push(static_cast<int64_t>(r_usage.ru_oublock));
 
119
 
 
120
  /* MESSAGES_SENT */
 
121
  push(static_cast<int64_t>(r_usage.ru_msgsnd));
 
122
 
 
123
  /* MESSAGES_RECEIVED */
 
124
  push(static_cast<int64_t>(r_usage.ru_msgrcv));
 
125
 
 
126
  /* SIGNALS_RECEIVED */
 
127
  push(static_cast<int64_t>(r_usage.ru_nsignals));
 
128
 
 
129
  /* VOLUNTARY_CONTEXT_SWITCHES */
 
130
  push(static_cast<int64_t>(r_usage.ru_nvcsw));
 
131
 
 
132
  /* INVOLUNTARY_CONTEXT_SWITCHES */
 
133
  push(static_cast<int64_t>(r_usage.ru_nivcsw));
 
134
 
 
135
  return true;
 
136
}