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

LCOV - code coverage report
Current view: top level - ext/standard - microtime.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 51 53 96.2 %
Date: 2015-06-27 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2015 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             :    | Author: Paul Panotzki - Bunyip Information Systems                   |
      16             :    +----------------------------------------------------------------------+
      17             :  */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #include "php.h"
      22             : 
      23             : #ifdef HAVE_SYS_TYPES_H
      24             : #include <sys/types.h>
      25             : #endif
      26             : #ifdef PHP_WIN32
      27             : #include "win32/time.h"
      28             : #include "win32/getrusage.h"
      29             : #elif defined(NETWARE)
      30             : #include <sys/timeval.h>
      31             : #include <sys/time.h>
      32             : #else
      33             : #include <sys/time.h>
      34             : #endif
      35             : #ifdef HAVE_SYS_RESOURCE_H
      36             : #include <sys/resource.h>
      37             : #endif
      38             : #ifdef HAVE_UNISTD_H
      39             : #include <unistd.h>
      40             : #endif
      41             : #include <stdlib.h>
      42             : #include <string.h>
      43             : #include <stdio.h>
      44             : #include <errno.h>
      45             : 
      46             : #include "microtime.h"
      47             : #include "ext/date/php_date.h"
      48             : 
      49             : #define NUL  '\0'
      50             : #define MICRO_IN_SEC 1000000.00
      51             : #define SEC_IN_MIN 60
      52             : 
      53             : #ifdef HAVE_GETTIMEOFDAY
      54      313394 : static void _php_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, int mode)
      55             : {
      56      313394 :         zend_bool get_as_float = 0;
      57      313394 :         struct timeval tp = {0};
      58             : 
      59      313394 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &get_as_float) == FAILURE) {
      60          10 :                 return;
      61             :         }
      62             : 
      63      313384 :         if (gettimeofday(&tp, NULL)) {
      64           0 :                 RETURN_FALSE;
      65             :         }
      66             : 
      67      313384 :         if (get_as_float) {
      68      213367 :                 RETURN_DOUBLE((double)(tp.tv_sec + tp.tv_usec / MICRO_IN_SEC));
      69             :         }
      70             : 
      71      100017 :         if (mode) {
      72             :                 timelib_time_offset *offset;
      73             : 
      74          12 :                 offset = timelib_get_time_zone_info(tp.tv_sec, get_timezone_info());
      75             : 
      76          12 :                 array_init(return_value);
      77          12 :                 add_assoc_long(return_value, "sec", tp.tv_sec);
      78          12 :                 add_assoc_long(return_value, "usec", tp.tv_usec);
      79             : 
      80          12 :                 add_assoc_long(return_value, "minuteswest", -offset->offset / SEC_IN_MIN);
      81          12 :                 add_assoc_long(return_value, "dsttime", offset->is_dst);
      82             : 
      83          12 :                 timelib_time_offset_dtor(offset);
      84             :         } else {
      85             :                 char ret[100];
      86             : 
      87      100005 :                 snprintf(ret, 100, "%.8F %ld", tp.tv_usec / MICRO_IN_SEC, tp.tv_sec);
      88      200010 :                 RETURN_STRING(ret);
      89             :         }
      90             : }
      91             : 
      92             : /* {{{ proto mixed microtime([bool get_as_float])
      93             :    Returns either a string or a float containing the current time in seconds and microseconds */
      94      313360 : PHP_FUNCTION(microtime)
      95             : {
      96      313360 :         _php_gettimeofday(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
      97      313360 : }
      98             : /* }}} */
      99             : 
     100             : /* {{{ proto array gettimeofday([bool get_as_float])
     101             :    Returns the current time as array */
     102          34 : PHP_FUNCTION(gettimeofday)
     103             : {
     104          34 :         _php_gettimeofday(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
     105          34 : }
     106             : #endif
     107             : /* }}} */
     108             : 
     109             : #ifdef HAVE_GETRUSAGE
     110             : /* {{{ proto array getrusage([int who])
     111             :    Returns an array of usage statistics */
     112          31 : PHP_FUNCTION(getrusage)
     113             : {
     114             :         struct rusage usg;
     115          31 :         zend_long pwho = 0;
     116          31 :         int who = RUSAGE_SELF;
     117             : 
     118          31 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &pwho) == FAILURE) {
     119           6 :                 return;
     120             :         }
     121             : 
     122          25 :         if (pwho == 1) {
     123           5 :                 who = RUSAGE_CHILDREN;
     124             :         }
     125             : 
     126          25 :         memset(&usg, 0, sizeof(struct rusage));
     127             : 
     128          25 :         if (getrusage(who, &usg) == -1) {
     129           0 :                 RETURN_FALSE;
     130             :         }
     131             : 
     132          25 :         array_init(return_value);
     133             : 
     134             : #define PHP_RUSAGE_PARA(a) \
     135             :                 add_assoc_long(return_value, #a, usg.a)
     136             : 
     137             : #ifdef PHP_WIN32 /* Windows only implements a limited amount of fields from the rusage struct */
     138             :         PHP_RUSAGE_PARA(ru_majflt);
     139             :         PHP_RUSAGE_PARA(ru_maxrss);
     140             : #elif !defined( _OSD_POSIX) && !defined(__BEOS__) /* BS2000 has only a few fields in the rusage struct*/
     141          25 :         PHP_RUSAGE_PARA(ru_oublock);
     142          25 :         PHP_RUSAGE_PARA(ru_inblock);
     143          25 :         PHP_RUSAGE_PARA(ru_msgsnd);
     144          25 :         PHP_RUSAGE_PARA(ru_msgrcv);
     145          25 :         PHP_RUSAGE_PARA(ru_maxrss);
     146          25 :         PHP_RUSAGE_PARA(ru_ixrss);
     147          25 :         PHP_RUSAGE_PARA(ru_idrss);
     148          25 :         PHP_RUSAGE_PARA(ru_minflt);
     149          25 :         PHP_RUSAGE_PARA(ru_majflt);
     150          25 :         PHP_RUSAGE_PARA(ru_nsignals);
     151          25 :         PHP_RUSAGE_PARA(ru_nvcsw);
     152          25 :         PHP_RUSAGE_PARA(ru_nivcsw);
     153          25 :         PHP_RUSAGE_PARA(ru_nswap);
     154             : #endif /*_OSD_POSIX*/
     155          25 :         PHP_RUSAGE_PARA(ru_utime.tv_usec);
     156          25 :         PHP_RUSAGE_PARA(ru_utime.tv_sec);
     157          25 :         PHP_RUSAGE_PARA(ru_stime.tv_usec);
     158          25 :         PHP_RUSAGE_PARA(ru_stime.tv_sec);
     159             : 
     160             : #undef PHP_RUSAGE_PARA
     161             : }
     162             : #endif /* HAVE_GETRUSAGE */
     163             : 
     164             : /* }}} */
     165             : 
     166             : /*
     167             :  * Local variables:
     168             :  * tab-width: 4
     169             :  * c-basic-offset: 4
     170             :  * End:
     171             :  * vim600: sw=4 ts=4 fdm=marker
     172             :  * vim<600: sw=4 ts=4
     173             :  */

Generated by: LCOV version 1.10

Generated at Sat, 27 Jun 2015 09:41:21 +0000 (7 days ago)

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