Replace deprecated ftime() with gettimeofday()
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
parent
795bdd2440
commit
a13287b4ff
@ -8,7 +8,7 @@
|
|||||||
#include "argp.h"
|
#include "argp.h"
|
||||||
#include "cas_lib.h"
|
#include "cas_lib.h"
|
||||||
#include "cas_lib_utils.h"
|
#include "cas_lib_utils.h"
|
||||||
#include <sys/timeb.h>
|
#include <sys/time.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#define PADDING " "
|
#define PADDING " "
|
||||||
@ -472,6 +472,11 @@ void log_command(int argc, const char **argv, int result, long long int timespan
|
|||||||
free(command);
|
free(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline long long int timeval_to_msec(struct timeval t)
|
||||||
|
{
|
||||||
|
return 1000 * t.tv_sec + t.tv_usec / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* run command. Additionally log its execution and report any errors if
|
* run command. Additionally log its execution and report any errors if
|
||||||
* they've happened
|
* they've happened
|
||||||
@ -480,15 +485,12 @@ int run_command(cli_command *commands, int cmd, int argc, const char **argv)
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
const char *syslog_path = "/var/log/messages";
|
const char *syslog_path = "/var/log/messages";
|
||||||
/* time buffer and stat buffer after running command */
|
struct timeval t0, t1;
|
||||||
struct timeb t0;
|
|
||||||
FILE *messages_f;
|
FILE *messages_f;
|
||||||
/* time buffer and stat buffer after running command */
|
|
||||||
struct timeb t1;
|
|
||||||
long long int timespan;
|
long long int timespan;
|
||||||
|
|
||||||
/* collect time */
|
/* collect time */
|
||||||
ftime(&t0);
|
gettimeofday(&t0, NULL);
|
||||||
/* collect stat buffer for syslog */
|
/* collect stat buffer for syslog */
|
||||||
messages_f = fopen(syslog_path, "r");
|
messages_f = fopen(syslog_path, "r");
|
||||||
if (messages_f) {
|
if (messages_f) {
|
||||||
@ -507,8 +509,8 @@ int run_command(cli_command *commands, int cmd, int argc, const char **argv)
|
|||||||
|
|
||||||
/* execute CAS command */
|
/* execute CAS command */
|
||||||
result = commands[cmd].handle();
|
result = commands[cmd].handle();
|
||||||
ftime(&t1);
|
gettimeofday(&t1, NULL);
|
||||||
timespan = (1000 * (t1.time - t0.time) + t1.millitm - t0.millitm);
|
timespan = timeval_to_msec(t1) - timeval_to_msec(t0);
|
||||||
|
|
||||||
if (commands[cmd].short_name != 'V') {
|
if (commands[cmd].short_name != 'V') {
|
||||||
log_command(argc, argv, result, timespan);
|
log_command(argc, argv, result, timespan);
|
||||||
|
Loading…
Reference in New Issue
Block a user