LCOV - code coverage report
Current view: top level - src/ftimings - time.c (source / functions) Hit Total Coverage
Test: coverage_50ab7a7628bba174fc62cee3ab72b26e81f87fe5.info Lines: 8 10 80.0 %
Date: 2018-01-10 09:29:53 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* Copyright 2014 Lorenz Hüdepohl
       2             :  *
       3             :  * This file is part of ftimings.
       4             :  *
       5             :  * ftimings is free software: you can redistribute it and/or modify
       6             :  * it under the terms of the GNU Lesser General Public License as published by
       7             :  * the Free Software Foundation, either version 3 of the License, or
       8             :  * (at your option) any later version.
       9             :  *
      10             :  * ftimings is distributed in the hope that it will be useful,
      11             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :  * GNU Lesser General Public License for more details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with ftimings.  If not, see <http://www.gnu.org/licenses/>.
      17             :  */
      18             : 
      19             : #include <sys/time.h>
      20             : #include <stdio.h>
      21             : #include <unistd.h>
      22             : #include <stdint.h>
      23             : #include <stddef.h>
      24             : #include <stdlib.h>
      25             : 
      26             : #ifdef HAVE_CONFIG_H
      27             : #include "config-f90.h"
      28             : #endif
      29             : 
      30             : /* Return number of microseconds since 1.1.1970, in a 64 bit integer.
      31             :  * (with 2^64 us ~ 6 * 10^5 years, this should be sufficiently overflow safe)
      32             :  */
      33   943796304 : int64_t ftimings_microseconds_since_epoch(void) {
      34             :         struct timeval tv;
      35   943796304 :         if (gettimeofday(&tv, NULL) != 0) {
      36           0 :                 perror("gettimeofday");
      37           0 :                 exit(1);
      38             :         }
      39   943796304 :         return (int64_t) (tv.tv_sec) * ((int64_t) 1000000) + (int64_t)(tv.tv_usec);
      40             : }
      41             : 
      42             : #ifndef WITH_MPI
      43             : int64_t t0 = 0;
      44        9360 : void __attribute__((constructor)) init_time(void) {
      45        9360 :         t0 = ftimings_microseconds_since_epoch();
      46        9360 : }
      47             : 
      48     3210912 : double seconds(void) {
      49     3210912 :     return (ftimings_microseconds_since_epoch() - t0) / 1e6;
      50             : }
      51             : #endif

Generated by: LCOV version 1.12