libcamera: Switch to the std::chrono API
Replace the clock_gettime()-based API with durations expressed as integers with the std::chrono API. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
+4
-16
@@ -11,7 +11,6 @@
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <string.h>
|
||||
@@ -78,17 +77,6 @@ static int log_severity_to_syslog(LogSeverity severity)
|
||||
}
|
||||
}
|
||||
|
||||
static std::string log_timespec_to_string(const struct timespec ×tamp)
|
||||
{
|
||||
std::ostringstream ossTimestamp;
|
||||
ossTimestamp.fill('0');
|
||||
ossTimestamp << "[" << timestamp.tv_sec / (60 * 60) << ":"
|
||||
<< std::setw(2) << (timestamp.tv_sec / 60) % 60 << ":"
|
||||
<< std::setw(2) << timestamp.tv_sec % 60 << "."
|
||||
<< std::setw(9) << timestamp.tv_nsec << "]";
|
||||
return ossTimestamp.str();
|
||||
}
|
||||
|
||||
static const char *log_severity_name(LogSeverity severity)
|
||||
{
|
||||
static const char *const names[] = {
|
||||
@@ -216,10 +204,10 @@ void LogOutput::writeSyslog(const LogMessage &msg)
|
||||
|
||||
void LogOutput::writeStream(const LogMessage &msg)
|
||||
{
|
||||
std::string str = std::string(log_timespec_to_string(msg.timestamp()) +
|
||||
log_severity_name(msg.severity()) + " " +
|
||||
std::string str = "[" + utils::time_point_to_string(msg.timestamp()) +
|
||||
"]" + log_severity_name(msg.severity()) + " " +
|
||||
msg.category().name() + " " + msg.fileInfo() + " " +
|
||||
msg.msg());
|
||||
msg.msg();
|
||||
stream_->write(str.c_str(), str.size());
|
||||
stream_->flush();
|
||||
}
|
||||
@@ -777,7 +765,7 @@ LogMessage::LogMessage(LogMessage &&other)
|
||||
void LogMessage::init(const char *fileName, unsigned int line)
|
||||
{
|
||||
/* Log the timestamp, severity and file information. */
|
||||
clock_gettime(CLOCK_MONOTONIC, ×tamp_);
|
||||
timestamp_ = utils::clock::now();
|
||||
|
||||
std::ostringstream ossFileInfo;
|
||||
ossFileInfo << utils::basename(fileName) << ":" << line;
|
||||
|
||||
Reference in New Issue
Block a user