fault/fm-common/sources/fmTime.cpp
albailey 08130cd625 Fix zuul jobs broken due to pip upversion
python 2.7 zuul jobs such as py27 and pylint could fail
when trying to import bandit using the new pip
since bandit 1.7 was released Dec 12 and is python3 only.

The cpp file header was only changed in this review to
trigger the appropriate zuul jobs.

Partial-Bug: #1907678
Change-Id: Idb1e97d16773d36027d29f4eb100d8b453a8069f
Signed-off-by: albailey <Al.Bailey@windriver.com>
2020-12-18 08:41:07 -06:00

49 lines
943 B
C++

//
// Copyright (c) 2020 Wind River Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
#include "fmTime.h"
#include "fmLog.h"
#include <string.h>
#include <errno.h>
#define FM_USEC_PER_SEC 1000000
static FMTimeT GetUptimeMicro() {
uint64_t thetm = 0;
struct timespec tv;
if (clock_gettime(CLOCK_MONOTONIC_RAW,&tv)==0) {
thetm = tv.tv_nsec/1000;
thetm = ((uint64_t)tv.tv_sec) * FM_USEC_PER_SEC;
} else {
FM_ERROR_LOG("clock_gettime() failed: error: (%d), (%s)", errno, strerror(errno));
}
return thetm;
}
FMTimeT fmGetCurrentTime() {
struct timeval tv;
memset(&tv,0,sizeof(tv));
if (gettimeofday(&tv, NULL) != 0){
FM_ERROR_LOG("gettimeofday failed (errno:%d)",errno);
return 0;
} else {
return (((FMTimeT)tv.tv_sec) * FM_USEC_PER_SEC) +
((FMTimeT)tv.tv_usec);
}
}
FMTimeT fmGetCurrentHrt() {
return GetUptimeMicro();
}
FMTimeT CFmTimer::gethrtime(){
return fmGetCurrentHrt();
}