chen.wang1 | 9fec184 | 2023-06-15 06:52:30 +0000 | [diff] [blame^] | 1 | #include <time.h> |
| 2 | #include <stdarg.h> |
| 3 | #include <string.h> |
| 4 | #include <stdbool.h> |
| 5 | #include "meson_drm_log.h" |
| 6 | #include <sys/time.h> |
| 7 | |
| 8 | static int g_activeLevel= 1; |
| 9 | |
| 10 | long long getMonotonicTimeMicros( void ) |
| 11 | { |
| 12 | int rc; |
| 13 | struct timespec tm; |
| 14 | long long timeMicro; |
| 15 | static bool reportedError= false; |
| 16 | if ( !reportedError ) |
| 17 | { |
| 18 | rc= clock_gettime( CLOCK_MONOTONIC, &tm ); |
| 19 | } |
| 20 | if ( reportedError || rc ) |
| 21 | { |
| 22 | struct timeval tv; |
| 23 | if ( !reportedError ) |
| 24 | { |
| 25 | reportedError= true; |
| 26 | ERROR("clock_gettime failed rc %d - using timeofday", rc); |
| 27 | } |
| 28 | gettimeofday(&tv,0); |
| 29 | timeMicro= tv.tv_sec*1000000LL+tv.tv_usec; |
| 30 | } |
| 31 | else |
| 32 | { |
| 33 | timeMicro= tm.tv_sec*1000000LL+(tm.tv_nsec/1000LL); |
| 34 | } |
| 35 | return timeMicro; |
| 36 | } |
| 37 | |
| 38 | void mesonDrmLog( int level, const char *fmt, ... ) |
| 39 | { |
| 40 | const char *env= getenv( "LIBMESON_GL_DEBUG" ); |
| 41 | if ( env ) |
| 42 | { |
| 43 | int level= atoi( env ); |
| 44 | g_activeLevel= level; |
| 45 | } |
| 46 | if ( level <= g_activeLevel ) |
| 47 | { |
| 48 | va_list argptr; |
| 49 | fprintf( stderr, "%lld: ", getMonotonicTimeMicros()); |
| 50 | va_start( argptr, fmt ); |
| 51 | vfprintf( stderr, fmt, argptr ); |
| 52 | va_end( argptr ); |
| 53 | } |
| 54 | } |