log_read.h revision 0175b0747a1f55329109e84c9a1322dcb95e2848
1/* 2 * Copyright (C) 2013-2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef _LIBS_LOG_LOG_READ_H 18#define _LIBS_LOG_LOG_READ_H 19 20#include <time.h> 21 22#define NS_PER_SEC 1000000000ULL 23#ifdef __cplusplus 24struct log_time : public timespec { 25public: 26 log_time(const timespec &T) 27 { 28 tv_sec = T.tv_sec; 29 tv_nsec = T.tv_nsec; 30 } 31 log_time() 32 { 33 } 34 log_time(clockid_t id) 35 { 36 clock_gettime(id, (timespec *) this); 37 } 38 log_time(const char *T) 39 { 40 const uint8_t *c = (const uint8_t *) T; 41 tv_sec = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24); 42 tv_nsec = c[4] | (c[5] << 8) | (c[6] << 16) | (c[7] << 24); 43 } 44 bool operator== (const timespec &T) const 45 { 46 return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec); 47 } 48 bool operator!= (const timespec &T) const 49 { 50 return !(*this == T); 51 } 52 bool operator< (const timespec &T) const 53 { 54 return (tv_sec < T.tv_sec) 55 || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec)); 56 } 57 bool operator>= (const timespec &T) const 58 { 59 return !(*this < T); 60 } 61 bool operator> (const timespec &T) const 62 { 63 return (tv_sec > T.tv_sec) 64 || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec)); 65 } 66 bool operator<= (const timespec &T) const 67 { 68 return !(*this > T); 69 } 70 uint64_t nsec() const 71 { 72 return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec; 73 } 74}; 75#else 76typedef struct timespec log_time; 77#endif 78 79#endif /* define _LIBS_LOG_LOG_READ_H */ 80