PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - mysqlnd - mysqlnd_statistics.c
Test: PHP Code Coverage
Date: 2009-11-21 Instrumented lines: 19
Code covered: 89.5 % Executed lines: 17
Legend: not executed executed

       1                 : /*
       2                 :   +----------------------------------------------------------------------+
       3                 :   | PHP Version 6                                                        |
       4                 :   +----------------------------------------------------------------------+
       5                 :   | Copyright (c) 2006-2009 The PHP Group                                |
       6                 :   +----------------------------------------------------------------------+
       7                 :   | This source file is subject to version 3.01 of the PHP license,      |
       8                 :   | that is bundled with this package in the file LICENSE, and is        |
       9                 :   | available through the world-wide-web at the following url:           |
      10                 :   | http://www.php.net/license/3_01.txt                                  |
      11                 :   | If you did not receive a copy of the PHP license and are unable to   |
      12                 :   | obtain it through the world-wide-web, please send a note to          |
      13                 :   | license@php.net so we can mail you a copy immediately.               |
      14                 :   +----------------------------------------------------------------------+
      15                 :   | Authors: Georg Richter <georg@mysql.com>                             |
      16                 :   |          Andrey Hristov <andrey@mysql.com>                           |
      17                 :   |          Ulf Wendel <uwendel@mysql.com>                              |
      18                 :   +----------------------------------------------------------------------+
      19                 : */
      20                 : 
      21                 : /* $Id: mysqlnd_statistics.c 289855 2009-10-22 16:05:33Z uw $ */
      22                 : #include "php.h"
      23                 : #include "mysqlnd.h"
      24                 : #include "mysqlnd_priv.h"
      25                 : #include "mysqlnd_statistics.h"
      26                 : #include "mysqlnd_debug.h"
      27                 : 
      28                 : 
      29                 : #define STR_W_LEN(str)  str, (sizeof(str) - 1)
      30                 : 
      31                 : /* {{{ mysqlnd_stats_values_names 
      32                 :  */
      33                 : 
      34                 : const MYSQLND_STRING mysqlnd_stats_values_names[STAT_LAST] =
      35                 : {
      36                 :         { STR_W_LEN("bytes_sent") },
      37                 :         { STR_W_LEN("bytes_received") }, 
      38                 :         { STR_W_LEN("packets_sent") },
      39                 :         { STR_W_LEN("packets_received") },
      40                 :         { STR_W_LEN("protocol_overhead_in") },
      41                 :         { STR_W_LEN("protocol_overhead_out") },
      42                 :         { STR_W_LEN("bytes_received_ok_packet") }, 
      43                 :         { STR_W_LEN("bytes_received_eof_packet") }, 
      44                 :         { STR_W_LEN("bytes_received_rset_header_packet") }, 
      45                 :         { STR_W_LEN("bytes_received_rset_field_meta_packet") }, 
      46                 :         { STR_W_LEN("bytes_received_rset_row_packet") }, 
      47                 :         { STR_W_LEN("bytes_received_prepare_response_packet") }, 
      48                 :         { STR_W_LEN("bytes_received_change_user_packet") }, 
      49                 :         { STR_W_LEN("packets_sent_command") }, 
      50                 :         { STR_W_LEN("packets_received_ok") }, 
      51                 :         { STR_W_LEN("packets_received_eof") }, 
      52                 :         { STR_W_LEN("packets_received_rset_header") }, 
      53                 :         { STR_W_LEN("packets_received_rset_field_meta") }, 
      54                 :         { STR_W_LEN("packets_received_rset_row") }, 
      55                 :         { STR_W_LEN("packets_received_prepare_response") }, 
      56                 :         { STR_W_LEN("packets_received_change_user") }, 
      57                 :         { STR_W_LEN("result_set_queries") },
      58                 :         { STR_W_LEN("non_result_set_queries") },
      59                 :         { STR_W_LEN("no_index_used") },
      60                 :         { STR_W_LEN("bad_index_used") },
      61                 :         { STR_W_LEN("slow_queries") },
      62                 :         { STR_W_LEN("buffered_sets") },
      63                 :         { STR_W_LEN("unbuffered_sets") },
      64                 :         { STR_W_LEN("ps_buffered_sets") },
      65                 :         { STR_W_LEN("ps_unbuffered_sets") },
      66                 :         { STR_W_LEN("flushed_normal_sets") },
      67                 :         { STR_W_LEN("flushed_ps_sets") },
      68                 :         { STR_W_LEN("ps_prepared_never_executed") },
      69                 :         { STR_W_LEN("ps_prepared_once_executed") },
      70                 :         { STR_W_LEN("rows_fetched_from_server_normal") },
      71                 :         { STR_W_LEN("rows_fetched_from_server_ps") },
      72                 :         { STR_W_LEN("rows_buffered_from_client_normal") },
      73                 :         { STR_W_LEN("rows_buffered_from_client_ps") },
      74                 :         { STR_W_LEN("rows_fetched_from_client_normal_buffered") },
      75                 :         { STR_W_LEN("rows_fetched_from_client_normal_unbuffered") },
      76                 :         { STR_W_LEN("rows_fetched_from_client_ps_buffered") },
      77                 :         { STR_W_LEN("rows_fetched_from_client_ps_unbuffered") },
      78                 :         { STR_W_LEN("rows_fetched_from_client_ps_cursor") },
      79                 :         { STR_W_LEN("rows_affected_normal") },
      80                 :         { STR_W_LEN("rows_affected_ps") },
      81                 :         { STR_W_LEN("rows_skipped_normal") },
      82                 :         { STR_W_LEN("rows_skipped_ps") },
      83                 :         { STR_W_LEN("copy_on_write_saved") },
      84                 :         { STR_W_LEN("copy_on_write_performed") },
      85                 :         { STR_W_LEN("command_buffer_too_small") },
      86                 :         { STR_W_LEN("connect_success") },
      87                 :         { STR_W_LEN("connect_failure") },
      88                 :         { STR_W_LEN("connection_reused") },
      89                 :         { STR_W_LEN("reconnect") },
      90                 :         { STR_W_LEN("pconnect_success") },
      91                 :         { STR_W_LEN("active_connections") },
      92                 :         { STR_W_LEN("active_persistent_connections") },
      93                 :         { STR_W_LEN("explicit_close") },
      94                 :         { STR_W_LEN("implicit_close") },
      95                 :         { STR_W_LEN("disconnect_close") },
      96                 :         { STR_W_LEN("in_middle_of_command_close") },
      97                 :         { STR_W_LEN("explicit_free_result") },
      98                 :         { STR_W_LEN("implicit_free_result") },
      99                 :         { STR_W_LEN("explicit_stmt_close") },
     100                 :         { STR_W_LEN("implicit_stmt_close") },
     101                 :         { STR_W_LEN("mem_emalloc_count") },
     102                 :         { STR_W_LEN("mem_emalloc_ammount") },
     103                 :         { STR_W_LEN("mem_ecalloc_count") },
     104                 :         { STR_W_LEN("mem_ecalloc_ammount") },
     105                 :         { STR_W_LEN("mem_erealloc_count") },
     106                 :         { STR_W_LEN("mem_erealloc_ammount") },
     107                 :         { STR_W_LEN("mem_efree_count") },
     108                 :         { STR_W_LEN("mem_malloc_count") },
     109                 :         { STR_W_LEN("mem_malloc_ammount") },
     110                 :         { STR_W_LEN("mem_calloc_count") },
     111                 :         { STR_W_LEN("mem_calloc_ammount") },
     112                 :         { STR_W_LEN("mem_realloc_count") },
     113                 :         { STR_W_LEN("mem_realloc_ammount") },
     114                 :         { STR_W_LEN("mem_free_count") },
     115                 :         { STR_W_LEN("proto_text_fetched_null") },
     116                 :         { STR_W_LEN("proto_text_fetched_bit") },
     117                 :         { STR_W_LEN("proto_text_fetched_tinyint") },
     118                 :         { STR_W_LEN("proto_text_fetched_short") },
     119                 :         { STR_W_LEN("proto_text_fetched_int24") },
     120                 :         { STR_W_LEN("proto_text_fetched_int") },
     121                 :         { STR_W_LEN("proto_text_fetched_bigint") },
     122                 :         { STR_W_LEN("proto_text_fetched_decimal") },
     123                 :         { STR_W_LEN("proto_text_fetched_float") },
     124                 :         { STR_W_LEN("proto_text_fetched_double") },
     125                 :         { STR_W_LEN("proto_text_fetched_date") },
     126                 :         { STR_W_LEN("proto_text_fetched_year") },
     127                 :         { STR_W_LEN("proto_text_fetched_time") },
     128                 :         { STR_W_LEN("proto_text_fetched_datetime") },
     129                 :         { STR_W_LEN("proto_text_fetched_timestamp") },
     130                 :         { STR_W_LEN("proto_text_fetched_string") },
     131                 :         { STR_W_LEN("proto_text_fetched_blob") },
     132                 :         { STR_W_LEN("proto_text_fetched_enum") },
     133                 :         { STR_W_LEN("proto_text_fetched_set") },
     134                 :         { STR_W_LEN("proto_text_fetched_geometry") },
     135                 :         { STR_W_LEN("proto_text_fetched_other") },
     136                 :         { STR_W_LEN("proto_binary_fetched_null") },
     137                 :         { STR_W_LEN("proto_binary_fetched_bit") },
     138                 :         { STR_W_LEN("proto_binary_fetched_tinyint") },
     139                 :         { STR_W_LEN("proto_binary_fetched_short") },
     140                 :         { STR_W_LEN("proto_binary_fetched_int24") },
     141                 :         { STR_W_LEN("proto_binary_fetched_int") },
     142                 :         { STR_W_LEN("proto_binary_fetched_bigint") },
     143                 :         { STR_W_LEN("proto_binary_fetched_decimal") },
     144                 :         { STR_W_LEN("proto_binary_fetched_float") },
     145                 :         { STR_W_LEN("proto_binary_fetched_double") },
     146                 :         { STR_W_LEN("proto_binary_fetched_date") },
     147                 :         { STR_W_LEN("proto_binary_fetched_year") },
     148                 :         { STR_W_LEN("proto_binary_fetched_time") },
     149                 :         { STR_W_LEN("proto_binary_fetched_datetime") },
     150                 :         { STR_W_LEN("proto_binary_fetched_timestamp") },
     151                 :         { STR_W_LEN("proto_binary_fetched_string") },
     152                 :         { STR_W_LEN("proto_binary_fetched_blob") },
     153                 :         { STR_W_LEN("proto_binary_fetched_enum") },
     154                 :         { STR_W_LEN("proto_binary_fetched_set") },
     155                 :         { STR_W_LEN("proto_binary_fetched_geometry") },
     156                 :         { STR_W_LEN("proto_binary_fetched_other") },
     157                 :         { STR_W_LEN("init_command_executed_count") },
     158                 :         { STR_W_LEN("init_command_failed_count") },
     159                 :         { STR_W_LEN("com_quit") },
     160                 :         { STR_W_LEN("com_init_db") },
     161                 :         { STR_W_LEN("com_query") },
     162                 :         { STR_W_LEN("com_field_list") },
     163                 :         { STR_W_LEN("com_create_db") },
     164                 :         { STR_W_LEN("com_drop_db") },
     165                 :         { STR_W_LEN("com_refresh") },
     166                 :         { STR_W_LEN("com_shutdown") },
     167                 :         { STR_W_LEN("com_statistics") },
     168                 :         { STR_W_LEN("com_process_info") },
     169                 :         { STR_W_LEN("com_connect") },
     170                 :         { STR_W_LEN("com_process_kill") },
     171                 :         { STR_W_LEN("com_debug") },
     172                 :         { STR_W_LEN("com_ping") },
     173                 :         { STR_W_LEN("com_time") },
     174                 :         { STR_W_LEN("com_delayed_insert") },
     175                 :         { STR_W_LEN("com_change_user") },
     176                 :         { STR_W_LEN("com_binlog_dump") },
     177                 :         { STR_W_LEN("com_table_dump") },
     178                 :         { STR_W_LEN("com_connect_out") },
     179                 :         { STR_W_LEN("com_register_slave") },
     180                 :         { STR_W_LEN("com_stmt_prepare") },
     181                 :         { STR_W_LEN("com_stmt_execute") },
     182                 :         { STR_W_LEN("com_stmt_send_long_data") },
     183                 :         { STR_W_LEN("com_stmt_close") },
     184                 :         { STR_W_LEN("com_stmt_reset") },
     185                 :         { STR_W_LEN("com_stmt_set_option") },
     186                 :         { STR_W_LEN("com_stmt_fetch") },
     187                 :         { STR_W_LEN("com_deamon") }
     188                 : };
     189                 : /* }}} */
     190                 : 
     191                 : 
     192                 : /* {{{ mysqlnd_fill_stats_hash */
     193                 : void
     194                 : mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, zval *return_value TSRMLS_DC ZEND_FILE_LINE_DC)
     195              99 : {
     196                 :         unsigned int i;
     197                 : 
     198              99 :         mysqlnd_array_init(return_value, STAT_LAST);
     199           15147 :         for (i = 0; i < STAT_LAST; i++) {
     200                 : #if PHP_MAJOR_VERSION >= 6
     201                 :                 UChar *ustr, *tstr;
     202                 :                 int ulen, tlen;
     203                 : #endif
     204                 :                 char tmp[25];
     205                 :                 
     206           15048 :                 sprintf((char *)&tmp, MYSQLND_LLU_SPEC, stats->values[i]);
     207                 : #if PHP_MAJOR_VERSION >= 6
     208                 :                 zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, mysqlnd_stats_values_names[i].s,
     209                 :                                                                 mysqlnd_stats_values_names[i].l + 1 TSRMLS_CC);
     210                 :                 zend_string_to_unicode(UG(utf8_conv), &tstr, &tlen, tmp, strlen(tmp) + 1 TSRMLS_CC);
     211                 :                 add_u_assoc_unicode_ex(return_value, IS_UNICODE, ZSTR(ustr), ulen, tstr, 1);
     212                 :                 efree(ustr);
     213                 :                 efree(tstr);
     214                 : #else
     215           15048 :                 add_assoc_string_ex(return_value, mysqlnd_stats_values_names[i].s,
     216                 :                                                         mysqlnd_stats_values_names[i].l + 1, tmp, 1);
     217                 : #endif
     218                 :         }
     219              99 : }
     220                 : /* }}} */
     221                 : 
     222                 : 
     223                 : /* {{{ _mysqlnd_get_client_stats */
     224                 : PHPAPI void _mysqlnd_get_client_stats(zval *return_value TSRMLS_DC ZEND_FILE_LINE_DC)
     225              94 : {
     226              94 :         MYSQLND_STATS stats, *stats_ptr = mysqlnd_global_stats;
     227              94 :         DBG_ENTER("_mysqlnd_get_client_stats");
     228              94 :         if (!stats_ptr) {
     229               0 :                 memset(&stats, 0, sizeof(stats));
     230               0 :                 stats_ptr = &stats;
     231                 :         }
     232              94 :         mysqlnd_fill_stats_hash(stats_ptr, return_value TSRMLS_CC ZEND_FILE_LINE_CC);
     233                 :         DBG_VOID_RETURN;
     234                 : }
     235                 : /* }}} */
     236                 : 
     237                 : 
     238                 : /* {{{ mysqlnd_stats_init */
     239                 : void
     240                 : mysqlnd_stats_init(MYSQLND_STATS ** stats)
     241           17633 : {
     242           17633 :         *stats = calloc(1, sizeof(MYSQLND_STATS));
     243                 : #ifdef ZTS
     244                 :         (*stats)->LOCK_access = tsrm_mutex_alloc();
     245                 : #endif
     246                 : 
     247           17633 : }
     248                 : /* }}} */
     249                 : 
     250                 : 
     251                 : /* {{{ mysqlnd_stats_end */
     252                 : void
     253                 : mysqlnd_stats_end(MYSQLND_STATS * stats)
     254           17665 : {
     255                 : #ifdef ZTS
     256                 :         tsrm_mutex_free(stats->LOCK_access);
     257                 : #endif
     258                 :         /* mnd_free will reference LOCK_access and crash...*/
     259           17665 :         free(stats);
     260           17665 : }
     261                 : /* }}} */
     262                 : 
     263                 : 
     264                 : /*
     265                 :  * Local variables:
     266                 :  * tab-width: 4
     267                 :  * c-basic-offset: 4
     268                 :  * End:
     269                 :  * vim600: noet sw=4 ts=4 fdm=marker
     270                 :  * vim<600: noet sw=4 ts=4
     271                 :  */

Generated by: LTP GCOV extension version 1.5

Generated at Sat, 21 Nov 2009 12:27:03 +0000 (3 days ago)

Copyright © 2005-2009 The PHP Group
All rights reserved.