| Commit | Line | Data |
|---|---|---|
| d3d906c6 | 1 | <?php |
| d3d906c6 | 2 | |
| 904fdcab KB |
3 | /** |
| 4 | * @file | |
| 5 | * Install and update for Performance Logging | |
| baee206f | 6 | * |
| 904fdcab KB |
7 | * Copyright Khalid Baheyeldin 2008 of http://2bits.com |
| 8 | */ | |
| d3d906c6 | 9 | |
| a1cd2780 KB |
10 | // Minimum APC shm memory size to require |
| 11 | define('PERFORMANCE_MIN_MEMORY', 48); | |
| 12 | ||
| 397f7dc9 KB |
13 | function performance_schema() { |
| 14 | $schema = array(); | |
| 15 | ||
| 16 | $schema['performance_summary'] = array( | |
| 17 | 'fields' => array( | |
| 18 | 'path' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), | |
| 19 | 'last_access' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), | |
| 20 | 'bytes_max' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), | |
| 21 | 'bytes_avg' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), | |
| baee206f KB |
22 | 'ms_max' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), |
| 23 | 'ms_avg' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), | |
| 397f7dc9 KB |
24 | 'query_count_max' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), |
| 25 | 'query_count_avg' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), | |
| 26 | 'query_timer_max' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), | |
| 27 | 'query_timer_avg' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), | |
| 28 | 'num_accesses' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), | |
| 904fdcab | 29 | ), |
| 397f7dc9 KB |
30 | 'primary key' => array('path'), |
| 31 | 'indexes' => array( | |
| 904fdcab | 32 | 'last_access' => array('last_access')), |
| 397f7dc9 | 33 | ); |
| d3d906c6 | 34 | |
| 397f7dc9 KB |
35 | $schema['performance_detail'] = array( |
| 36 | 'fields' => array( | |
| 37 | 'pid' => array('type' => 'serial', 'not null' => TRUE, 'disp-width' => '11'), | |
| 904fdcab KB |
38 | 'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), |
| 39 | 'bytes' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), | |
| baee206f | 40 | 'ms' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), |
| 904fdcab KB |
41 | 'query_count' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), |
| 42 | 'query_timer' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), | |
| 43 | 'anon' => array('type' => 'int', 'not null' => FALSE, 'default' => 1, 'disp-width' => '1'), | |
| d4f8258b | 44 | 'path' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), |
| da53004a | 45 | 'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'), |
| 904fdcab | 46 | ), |
| 397f7dc9 KB |
47 | 'primary key' => array('pid'), |
| 48 | 'indexes' => array( | |
| 904fdcab | 49 | 'timestamp' => array('timestamp')), |
| 397f7dc9 | 50 | ); |
| d3d906c6 | 51 | |
| 397f7dc9 KB |
52 | return $schema; |
| 53 | } | |
| d3d906c6 | 54 | |
| 397f7dc9 | 55 | function performance_install() { |
| d3d906c6 KB |
56 | |
| 57 | // Set the weight so this module runs last | |
| 58 | db_query("UPDATE {system} SET weight = 3000 WHERE name = 'performance'"); | |
| 59 | } | |
| 60 | ||
| 61 | function performance_uninstall() { | |
| d3d906c6 KB |
62 | db_query("DELETE FROM {variable} WHERE name LIKE 'performance%'"); |
| 63 | } | |
| 5109bd01 KB |
64 | |
| 65 | function performance_requirements($phase) { | |
| 66 | $requirements = array(); | |
| 67 | ||
| 68 | if ($phase != 'runtime') { | |
| 69 | return $requirements; | |
| 70 | } | |
| 71 | ||
| 904fdcab KB |
72 | if (variable_get('performance_detail', 0)) { |
| 73 | $requirements['performance_detail'] = array( | |
| 74 | 'title' => t('Performance logging details'), | |
| 75 | 'value' => 'Enabled', | |
| 76 | 'severity' => REQUIREMENT_WARNING, | |
| 17507063 | 77 | 'description' => t('Performance detailed logging is <a href="@link">enabled</a>. This can cause severe issues on live sites.', array('@link' => url('admin/config/development/performance_logging'))), |
| 904fdcab KB |
78 | ); |
| 79 | } | |
| 80 | ||
| 1b6f0f46 | 81 | if (variable_get('devel_query_display', FALSE)) { |
| 904fdcab KB |
82 | if (variable_get('performance_detail', 0) || |
| 83 | variable_get('performance_summary_db', 0) || | |
| 84 | variable_get('performance_summary_apc', 0)) { | |
| 85 | $requirements['performance_query'] = array( | |
| 86 | 'title' => t('Performance logging query'), | |
| 87 | 'value' => 'Enabled', | |
| 88 | 'severity' => REQUIREMENT_WARNING, | |
| 17507063 | 89 | 'description' => t('Query timing and count logging is <a href="@link">enabled</a>. This can cause memory size per page to be larger than normal.', array('@link' => url('admin/config/development/performance_logging'))), |
| 904fdcab KB |
90 | ); |
| 91 | } | |
| 92 | } | |
| 93 | ||
| 94 | if (!function_exists('apc_fetch')) { | |
| 95 | $requirements['performance_apc'] = array( | |
| 96 | 'title' => t('Performance logging APC'), | |
| 97 | 'value' => 'Disabled', | |
| 98 | 'severity' => REQUIREMENT_WARNING, | |
| 99 | 'description' => t('Performance logging on live web sites works best if APC is enabled.'), | |
| 100 | ); | |
| 101 | } | |
| 102 | ||
| 103 | $shm_size = ini_get('apc.shm_size'); | |
| a1cd2780 | 104 | if (function_exists('apc_fetch') && $shm_size < PERFORMANCE_MIN_MEMORY) { |
| 904fdcab KB |
105 | $requirements['performance_apc_mem'] = array( |
| 106 | 'title' => t('Performance logging APC memory size'), | |
| 107 | 'value' => $shm_size, | |
| 108 | 'severity' => REQUIREMENT_WARNING, | |
| a1cd2780 | 109 | 'description' => t('APC has been configured for !size, which is less than the recommended !min_memory MB of memory. If you encounter errors when viewing the summary report, then try to increase that limit for APC.', array('!size' => 1*$shm_size, '!min_memory' => PERFORMANCE_MIN_MEMORY)), |
| 904fdcab | 110 | ); |
| 5109bd01 KB |
111 | } |
| 112 | ||
| 113 | return $requirements; | |
| 114 | } | |
| 31053899 KB |
115 | |
| 116 | function performance_update_1() { | |
| 117 | $ret = array(); | |
| 118 | db_drop_field($ret, 'performance_detail', 'title'); | |
| 119 | db_drop_field($ret, 'performance_summary', 'title'); | |
| 120 | return $ret; | |
| 121 | } | |
| da53004a KB |
122 | |
| 123 | function performance_update_2() { | |
| 124 | $ret = array(); | |
| 125 | db_add_field($ret, 'performance_detail', 'data', array('type' => 'blob', 'not null' => FALSE, 'size' => 'big')); | |
| 126 | return $ret; | |
| 127 | } | |
| baee206f KB |
128 | |
| 129 | /** | |
| 130 | * Harmonize notations for milliseconds to "ms". | |
| 131 | * | |
| 132 | * @return array | |
| 133 | */ | |
| 134 | function performance_update_7001() { | |
| 135 | $int_field = array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'); | |
| 136 | ||
| 98506466 KB |
137 | db_change_field('performance_summary', 'millisecs_max', 'ms_max', $int_field); |
| 138 | db_change_field('performance_summary', 'millisecs_avg', 'ms_avg', $int_field); | |
| 139 | db_change_field('performance_detail', 'millisecs', 'ms', $int_field); | |
| baee206f KB |
140 | |
| 141 | // We don't have a cache update method, so it's better to clear it | |
| 98506466 | 142 | if (function_exists('apc_fetch')) { |
| baee206f KB |
143 | apc_clear_cache('user'); |
| 144 | } | |
| baee206f | 145 | } |