Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 15... Línea 15...
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
17
/**
17
/**
18
 * Store performance test run + output script.
18
 * Store performance test run + output script.
19
 *
19
 *
20
 * @package    core
20
 * @package    core_cache
21
 * @category   cache
21
 * @category   cache
22
 * @copyright  2012 Sam Hemelryk
22
 * @copyright  2012 Sam Hemelryk
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Línea 24... Línea 24...
24
 */
24
 */
25
 
25
 
26
require_once('../config.php');
-
 
Línea 27... Línea 26...
27
require_once($CFG->dirroot.'/lib/adminlib.php');
26
require_once('../config.php');
28
require_once($CFG->dirroot.'/cache/locallib.php');
27
require_once($CFG->dirroot . '/lib/adminlib.php');
29
 
28
 
Línea 30... Línea 29...
30
$count = optional_param('count', 100, PARAM_INT);
29
$count = optional_param('count', 100, PARAM_INT);
Línea 31... Línea 30...
31
$count = min($count, 100000);
30
$count = min($count, 100000);
32
$count = max($count, 0);
31
$count = max($count, 0);
33
 
32
 
34
admin_externalpage_setup('cachetestperformance');
33
admin_externalpage_setup('cachetestperformance');
35
 
34
 
36
$applicationtable = new html_table();
35
$applicationtable = new html_table();
37
$applicationtable->head = array(
36
$applicationtable->head = [
38
    get_string('plugin', 'cache'),
37
    get_string('plugin', 'cache'),
39
    get_string('result', 'cache'),
38
    get_string('result', 'cache'),
40
    get_string('set', 'cache'),
39
    get_string('set', 'cache'),
41
    get_string('gethit', 'cache'),
40
    get_string('gethit', 'cache'),
42
    get_string('getmiss', 'cache'),
41
    get_string('getmiss', 'cache'),
Línea 43... Línea 42...
43
    get_string('delete', 'cache'),
42
    get_string('delete', 'cache'),
Línea 56... Línea 55...
56
$struntestable = new lang_string('untestable', 'cache');
55
$struntestable = new lang_string('untestable', 'cache');
57
$strtested = new lang_string('tested', 'cache');
56
$strtested = new lang_string('tested', 'cache');
58
$strnotready = new lang_string('storenotready', 'cache');
57
$strnotready = new lang_string('storenotready', 'cache');
Línea 59... Línea 58...
59
 
58
 
60
foreach (core_component::get_plugin_list_with_file('cachestore', 'lib.php', true) as $plugin => $path) {
-
 
61
 
59
foreach (core_component::get_plugin_list_with_file('cachestore', 'lib.php', true) as $plugin => $path) {
62
    $class = 'cachestore_'.$plugin;
60
    $class = 'cachestore_' . $plugin;
Línea 63... Línea 61...
63
    $plugin = get_string('pluginname', 'cachestore_'.$plugin);
61
    $plugin = get_string('pluginname', 'cachestore_' . $plugin);
64
 
62
 
65
    if (!class_exists($class) || !method_exists($class, 'initialise_test_instance') || !$class::are_requirements_met()) {
63
    if (!class_exists($class) || !method_exists($class, 'initialise_test_instance') || !$class::are_requirements_met()) {
66
        $applicationtable->data[] = array($plugin, $strinvalidplugin, '-', '-', '-', '-');
64
        $applicationtable->data[] = [$plugin, $strinvalidplugin, '-', '-', '-', '-'];
67
        $sessiontable->data[] = array($plugin, $strinvalidplugin, '-', '-', '-', '-');
65
        $sessiontable->data[] = [$plugin, $strinvalidplugin, '-', '-', '-', '-'];
68
        $requesttable->data[] = array($plugin, $strinvalidplugin, '-', '-', '-', '-');
66
        $requesttable->data[] = [$plugin, $strinvalidplugin, '-', '-', '-', '-'];
Línea 69... Línea 67...
69
        continue;
67
        continue;
70
    }
68
    }
71
 
69
 
72
    if (!$class::is_supported_mode(cache_store::MODE_APPLICATION)) {
70
    if (!$class::is_supported_mode(cache_store::MODE_APPLICATION)) {
73
        $applicationtable->data[] = array($plugin, $strunsupportedmode, '-', '-', '-', '-');
71
        $applicationtable->data[] = [$plugin, $strunsupportedmode, '-', '-', '-', '-'];
74
    } else {
72
    } else {
75
        $store = $class::initialise_test_instance($application);
73
        $store = $class::initialise_test_instance($application);
76
        if ($store === false) {
74
        if ($store === false) {
77
            $applicationtable->data[] = array($plugin, $struntestable, '-', '-', '-', '-');
75
            $applicationtable->data[] = [$plugin, $struntestable, '-', '-', '-', '-'];
78
        } else if (!$store->is_ready()) {
76
        } else if (!$store->is_ready()) {
79
            $applicationtable->data[] = array($plugin, $strnotready, '-', '-', '-', '-');
77
            $applicationtable->data[] = [$plugin, $strnotready, '-', '-', '-', '-'];
80
        } else {
78
        } else {
81
            $result = array($plugin, $strtested, 0, 0, 0);
79
            $result = [$plugin, $strtested, 0, 0, 0];
82
            $start = microtime(true);
80
            $start = microtime(true);
83
            for ($i = 0; $i < $count; $i++) {
81
            for ($i = 0; $i < $count; $i++) {
Línea 84... Línea 82...
84
                $store->set('key'.$i, 'test data '.$i);
82
                $store->set('key' . $i, 'test data ' . $i);
85
            }
83
            }
86
            $result[2] = sprintf('%01.4f', microtime(true) - $start);
84
            $result[2] = sprintf('%01.4f', microtime(true) - $start);
87
 
85
 
88
            $start = microtime(true);
86
            $start = microtime(true);
Línea 89... Línea 87...
89
            for ($i = 0; $i < $count; $i++) {
87
            for ($i = 0; $i < $count; $i++) {
90
                $store->get('key'.$i);
88
                $store->get('key' . $i);
91
            }
89
            }
92
            $result[3] = sprintf('%01.4f', microtime(true) - $start);
90
            $result[3] = sprintf('%01.4f', microtime(true) - $start);
93
 
91
 
Línea 94... Línea 92...
94
            $start = microtime(true);
92
            $start = microtime(true);
95
            for ($i = 0; $i < $count; $i++) {
93
            for ($i = 0; $i < $count; $i++) {
96
                $store->get('fake'.$i);
94
                $store->get('fake' . $i);
97
            }
95
            }
98
            $result[4] = sprintf('%01.4f', microtime(true) - $start);
96
            $result[4] = sprintf('%01.4f', microtime(true) - $start);
99
 
97
 
100
            $start = microtime(true);
98
            $start = microtime(true);
101
            for ($i = 0; $i < $count; $i++) {
99
            for ($i = 0; $i < $count; $i++) {
102
                $store->delete('key'.$i);
100
                $store->delete('key' . $i);
Línea 103... Línea 101...
103
            }
101
            }
104
            $result[5] = sprintf('%01.4f', microtime(true) - $start);
102
            $result[5] = sprintf('%01.4f', microtime(true) - $start);
105
            $applicationtable->data[] = $result;
103
            $applicationtable->data[] = $result;
106
            $store->instance_deleted();
104
            $store->instance_deleted();
107
        }
105
        }
108
    }
106
    }
109
 
107
 
110
    if (!$class::is_supported_mode(cache_store::MODE_SESSION)) {
108
    if (!$class::is_supported_mode(cache_store::MODE_SESSION)) {
111
        $sessiontable->data[] = array($plugin, $strunsupportedmode, '-', '-', '-', '-');
109
        $sessiontable->data[] = [$plugin, $strunsupportedmode, '-', '-', '-', '-'];
112
    } else {
110
    } else {
113
        $store = $class::initialise_test_instance($session);
111
        $store = $class::initialise_test_instance($session);
114
        if ($store === false) {
112
        if ($store === false) {
115
            $sessiontable->data[] = array($plugin, $struntestable, '-', '-', '-', '-');
113
            $sessiontable->data[] = [$plugin, $struntestable, '-', '-', '-', '-'];
116
        } else if (!$store->is_ready()) {
114
        } else if (!$store->is_ready()) {
117
            $sessiontable->data[] = array($plugin, $strnotready, '-', '-', '-', '-');
115
            $sessiontable->data[] = [$plugin, $strnotready, '-', '-', '-', '-'];
Línea 118... Línea 116...
118
        } else {
116
        } else {
119
            $result = array($plugin, $strtested, 0, 0, 0);
117
            $result = [$plugin, $strtested, 0, 0, 0];
120
            $start = microtime(true);
118
            $start = microtime(true);
121
            for ($i = 0; $i < $count; $i++) {
119
            for ($i = 0; $i < $count; $i++) {
122
                $store->set('key'.$i, 'test data '.$i);
120
                $store->set('key' . $i, 'test data ' . $i);
Línea 123... Línea 121...
123
            }
121
            }
124
            $result[2] = sprintf('%01.4f', microtime(true) - $start);
122
            $result[2] = sprintf('%01.4f', microtime(true) - $start);
125
 
123
 
126
            $start = microtime(true);
124
            $start = microtime(true);
127
            for ($i = 0; $i < $count; $i++) {
125
            for ($i = 0; $i < $count; $i++) {
Línea 128... Línea 126...
128
                $store->get('key'.$i);
126
                $store->get('key' . $i);
129
            }
127
            }
130
            $result[3] = sprintf('%01.4f', microtime(true) - $start);
128
            $result[3] = sprintf('%01.4f', microtime(true) - $start);
131
 
129
 
132
            $start = microtime(true);
130
            $start = microtime(true);
133
            for ($i = 0; $i < $count; $i++) {
131
            for ($i = 0; $i < $count; $i++) {
134
                $store->get('fake'.$i);
132
                $store->get('fake' . $i);
135
            }
133
            }
136
            $result[4] = sprintf('%01.4f', microtime(true) - $start);
134
            $result[4] = sprintf('%01.4f', microtime(true) - $start);
Línea 137... Línea 135...
137
 
135
 
138
            $start = microtime(true);
136
            $start = microtime(true);
139
            for ($i = 0; $i < $count; $i++) {
137
            for ($i = 0; $i < $count; $i++) {
140
                $store->delete('key'.$i);
138
                $store->delete('key' . $i);
141
            }
139
            }
142
            $result[5] = sprintf('%01.4f', microtime(true) - $start);
140
            $result[5] = sprintf('%01.4f', microtime(true) - $start);
143
            $sessiontable->data[] = $result;
141
            $sessiontable->data[] = $result;
144
            $store->instance_deleted();
142
            $store->instance_deleted();
145
        }
143
        }
146
    }
144
    }
147
 
145
 
148
    if (!$class::is_supported_mode(cache_store::MODE_REQUEST)) {
146
    if (!$class::is_supported_mode(cache_store::MODE_REQUEST)) {
149
        $requesttable->data[] = array($plugin, $strunsupportedmode, '-', '-', '-', '-');
147
        $requesttable->data[] = [$plugin, $strunsupportedmode, '-', '-', '-', '-'];
150
    } else {
148
    } else {
151
        $store = $class::initialise_test_instance($request);
149
        $store = $class::initialise_test_instance($request);
Línea 152... Línea 150...
152
        if ($store === false) {
150
        if ($store === false) {
153
            $requesttable->data[] = array($plugin, $struntestable, '-', '-', '-', '-');
151
            $requesttable->data[] = [$plugin, $struntestable, '-', '-', '-', '-'];
154
        } else if (!$store->is_ready()) {
152
        } else if (!$store->is_ready()) {
155
            $requesttable->data[] = array($plugin, $strnotready, '-', '-', '-', '-');
153
            $requesttable->data[] = [$plugin, $strnotready, '-', '-', '-', '-'];
156
        } else {
154
        } else {
Línea 157... Línea 155...
157
            $result = array($plugin, $strtested, 0, 0, 0);
155
            $result = [$plugin, $strtested, 0, 0, 0];
158
            $start = microtime(true);
156
            $start = microtime(true);
159
            for ($i = 0; $i < $count; $i++) {
157
            for ($i = 0; $i < $count; $i++) {
160
                $store->set('key'.$i, 'test data '.$i);
158
                $store->set('key' . $i, 'test data ' . $i);
161
            }
159
            }
Línea 162... Línea 160...
162
            $result[2] = sprintf('%01.4f', microtime(true) - $start);
160
            $result[2] = sprintf('%01.4f', microtime(true) - $start);
163
 
161
 
164
            $start = microtime(true);
162
            $start = microtime(true);
165
            for ($i = 0; $i < $count; $i++) {
163
            for ($i = 0; $i < $count; $i++) {
166
                $store->get('key'.$i);
164
                $store->get('key' . $i);
167
            }
165
            }
168
            $result[3] = sprintf('%01.4f', microtime(true) - $start);
166
            $result[3] = sprintf('%01.4f', microtime(true) - $start);
169
 
167
 
170
            $start = microtime(true);
168
            $start = microtime(true);
171
            for ($i = 0; $i < $count; $i++) {
-
 
172
                $store->get('fake'.$i);
169
            for ($i = 0; $i < $count; $i++) {
Línea 173... Línea 170...
173
            }
170
                $store->get('fake' . $i);
174
            $result[4] = sprintf('%01.4f', microtime(true) - $start);
171
            }
Línea 175... Línea 172...
175
 
172
            $result[4] = sprintf('%01.4f', microtime(true) - $start);
176
            $start = microtime(true);
173
 
177
            for ($i = 0; $i < $count; $i++) {
174
            $start = microtime(true);
178
                $store->delete('key'.$i);
175
            for ($i = 0; $i < $count; $i++) {
179
            }
176
                $store->delete('key' . $i);
180
            $result[5] = sprintf('%01.4f', microtime(true) - $start);
177
            }
181
            $requesttable->data[] = $result;
178
            $result[5] = sprintf('%01.4f', microtime(true) - $start);
182
            $store->instance_deleted();
179
            $requesttable->data[] = $result;