-
Notifications
You must be signed in to change notification settings - Fork 0
/
perfmon.pages.inc
231 lines (205 loc) · 6.34 KB
/
perfmon.pages.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
/**
* @file
* TODO: Enter file description here.
*/
/**
* Page callback for run & review.
*/
function perfmon_page() {
$tests = array();
$output = array();
// Retrieve the testlist.
module_load_include('inc', 'perfmon');
$testlist = perfmon_get_testlist();
// Retrieve results from last run of the testlist.
$tests = perfmon_get_stored_results();
// Only users with the proper permission can run the testlist.
if (user_access('run performance tests')) {
$output += drupal_get_form('perfmon_run_form', $tests);
}
if (!empty($tests)) {
// We have prior results, so display them.
$output['results'] = perfmon_reviewed($testlist, $tests);
}
else {
// If they haven't configured the site, prompt them to do so.
drupal_set_message(t('It appears this is your first time using the performance testlist.'));
}
return $output;
}
/**
* Main page output.
*/
function perfmon_reviewed($testlist, $tests) {
$items = array();
$last_run = variable_get('perfmon_last_run', '');
$date = !empty($last_run) ? format_date($last_run) : '';
$header = t('Review results from last run !date', array('!date' => $date));
$desc = t("Here you can review the results from the last run of the testlist. You can run the testlist again by expanding the fieldset above.");
foreach ($tests as $test) {
// Skip this iteration if the result has no matching item in the testlist.
if (!isset($testlist[$test['testname']])) {
continue;
}
$message = $testlist[$test['testname']]['title'];
$title = t('OK');
$class = 'ok';
$bold = FALSE;
if ($test['testname'] == 'config') {
$bold = TRUE;
}
$items[] = array(
'title' => $title,
'bold' => $bold,
'value' => $test['result'],
'class' => $class,
'message' => $message,
'help_link' => l(t('Details'), 'admin/reports/perfmon/help/' . $test['testname']),
);
}
$output = theme('perfmon_reviewed', array(
'items' => $items,
'header' => $header,
'description' => $desc,
));
// @todo #markup?
return array('#markup' => $output);
}
/**
* Mysql settings page.
*/
function perfmon_mysql_page() {
$output = array();
// Retrieve the testlist.
module_load_include('inc', 'perfmon');
$performance_variables = perfmon_get_mysql_performance_variables();
if (!empty($performance_variables)) {
// We have prior results, so display them.
$output['results'] = perfmon_mysql_reviewed($performance_variables);
}
else {
// If they haven't configured the site, prompt them to do so.
drupal_set_message(t('Unable to get mysql global status'));
}
return $output;
}
/**
* Mysql settings page output.
*/
function perfmon_mysql_reviewed($performance_variables) {
$items = array();
$header = t('MySQL Performance');
$desc = t("Here you can review the results from checks mysql status and variables.");
foreach ($performance_variables as $param_name => $param) {
$message = $param['message'];
$title = $param['title'];
$class = $param['class'];
$value = $param['display_value'];
$bold = FALSE;
$items[] = array(
'title' => $title,
'bold' => $bold,
'value' => $value,
'class' => $class,
'message' => $message,
);
}
$output = theme('perfmon_mysql_reviewed', array(
'items' => $items,
'header' => $header,
'description' => $desc,
));
return array('#markup' => $output);
}
/**
* Run button.
*/
function perfmon_run_form($form, &$form_state, $tests = NULL) {
$form['run_form'] = array(
'#type' => 'fieldset',
'#title' => t('Run'),
'#description' => t('Click the button below to run the performance testlist and review the results.'),
'#collapsible' => TRUE,
'#collapsed' => empty($tests) ? FALSE : TRUE,
);
$form['run_form']['submit'] = array(
'#type' => 'submit',
'#value' => t('Run testlist'),
);
return $form;
}
/**
* Run all tests in batch.
*/
function perfmon_run_form_submit($form, &$form_state) {
module_load_include('inc', 'perfmon');
$testlist = perfmon_get_testlist();
// Use Batch to process the testlist.
$batch = array(
'operations' => array(),
'title' => t('Performance test'),
'progress_message' => t('Progress @current out of @total.'),
'error_message' => t('An error occurred. Rerun the process or consult the logs.'),
'finished' => '_perfmon_batch_finished',
);
$log = variable_get('perfmon_log', TRUE);
foreach ($testlist as $test_name => $test) {
// Each test is its own operation. There could be a case where a single
// test needs to run itself a batch operation, perhaps @todo?
$batch['operations'][] = array(
'_perfmon_batch_op',
array($test_name, $test, $log),
);
}
batch_set($batch);
}
/**
* Theme main report.
*/
function theme_perfmon_reviewed($variables) {
$output = '<h3>' . $variables['header'] . '</h3>';
$output .= '<p>' . $variables['description'] . '</p>';
$output .= '<table class="system-status-report">';
if (!empty($variables['items'])) {
foreach ($variables['items'] as $item) {
if ($item['bold']) {
$output .= '<tr class="' . $item['class'] . '" style="font-size:medium; font-weight:bold;">';
}
else {
$output .= '<tr class="' . $item['class'] . '">';
}
$output .= '<td class="status-icon"><div title="' . $item['title'] .
'"><span class="element-invisible">' . $item['title'] . '</span></div></td>';
$output .= '<td>' . $item['message'] . '</td>';
$output .= '<td>' . $item['value'] . '</td>';
$output .= '</tr>';
}
}
$output .= '</table>';
return $output;
}
/**
* Theme mysql report.
*/
function theme_perfmon_mysql_reviewed($variables) {
$output = '<h3>' . $variables['header'] . '</h3>';
$output .= '<p>' . $variables['description'] . '</p>';
$output .= '<table class="system-status-report">';
if (!empty($variables['items'])) {
foreach ($variables['items'] as $item) {
if ($item['bold']) {
$output .= '<tr class="' . $item['class'] . '" style="font-size:medium; font-weight:bold;">';
}
else {
$output .= '<tr class="' . $item['class'] . '">';
}
$output .= '<td>' . $item['title'] . '</td>';
$output .= '<td>' . $item['value'] . '</td>';
$output .= '<td>' . $item['message'] . '</td>';
$output .= '</tr>';
}
}
$output .= '</table>';
return $output;
}