diff --git a/build/libaegisub/libaegisub.vcxproj b/build/libaegisub/libaegisub.vcxproj
index 030f4b70e..d688c5161 100644
--- a/build/libaegisub/libaegisub.vcxproj
+++ b/build/libaegisub/libaegisub.vcxproj
@@ -80,7 +80,6 @@
-
diff --git a/build/libaegisub/libaegisub.vcxproj.filters b/build/libaegisub/libaegisub.vcxproj.filters
index a9e8cb417..9608b93dd 100644
--- a/build/libaegisub/libaegisub.vcxproj.filters
+++ b/build/libaegisub/libaegisub.vcxproj.filters
@@ -152,9 +152,6 @@
Header Files
-
- Header Files
-
ASS
@@ -334,4 +331,4 @@
Header Files
-
\ No newline at end of file
+
diff --git a/libaegisub/common/log.cpp b/libaegisub/common/log.cpp
index 70817f33b..685d07a5e 100644
--- a/libaegisub/common/log.cpp
+++ b/libaegisub/common/log.cpp
@@ -17,16 +17,15 @@
#include "libaegisub/cajun/elements.h"
#include "libaegisub/cajun/writer.h"
#include "libaegisub/dispatch.h"
-#include "libaegisub/time.h"
#include "libaegisub/util.h"
#include
#include
#include
#include
+#include
-namespace agi {
- namespace log {
+namespace agi { namespace log {
/// Global log sink.
LogSink *log;
@@ -75,12 +74,13 @@ decltype(LogSink::messages) LogSink::GetMessages() const {
Message::Message(const char *section, Severity severity, const char *file, const char *func, int line)
: msg(buffer, sizeof buffer)
{
+ using namespace std::chrono;
sm.section = section;
sm.severity = severity;
sm.file = file;
sm.func = func;
sm.line = line;
- sm.tv = util::time_log();
+ sm.time = duration_cast(steady_clock::now().time_since_epoch()).count();
}
Message::~Message() {
@@ -91,17 +91,12 @@ Message::~Message() {
JsonEmitter::JsonEmitter(fs::path const& directory)
: fp(new boost::filesystem::ofstream(unique_path(directory/util::strftime("%Y-%m-%d-%H-%M-%S-%%%%%%%%.json"))))
{
- WriteTime("open");
-}
-
-JsonEmitter::~JsonEmitter() {
- WriteTime("close");
}
void JsonEmitter::log(SinkMessage *sm) {
json::Object entry;
- entry["sec"] = (int64_t)sm->tv.tv_sec;
- entry["usec"] = (int64_t)sm->tv.tv_usec;
+ entry["sec"] = sm->time / 1000000000;
+ entry["usec"] = sm->time % 1000000000;
entry["severity"] = sm->severity;
entry["section"] = sm->section;
entry["file"] = sm->file;
@@ -112,14 +107,4 @@ void JsonEmitter::log(SinkMessage *sm) {
fp->flush();
}
-void JsonEmitter::WriteTime(const char *key) {
- auto time = util::time_log();
- json::Object obj;
- json::Array &timeval = obj[key];
- timeval.push_back((int64_t)time.tv_sec);
- timeval.push_back((int64_t)time.tv_usec);
- json::Writer::Write(obj, *fp);
-}
-
- } // namespace log
-} // namespace agi
+} }
diff --git a/libaegisub/include/libaegisub/log.h b/libaegisub/include/libaegisub/log.h
index 21b7eb026..343d6461c 100644
--- a/libaegisub/include/libaegisub/log.h
+++ b/libaegisub/include/libaegisub/log.h
@@ -12,16 +12,11 @@
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-/// @file log.h
-/// @brief Logging
-/// @ingroup libaegisub
-
#include
-#include
#include
#include
-#include
+#include
#include
#include
@@ -39,18 +34,18 @@
#define LOG_D_IF(cond, section) if (cond) LOG_SINK(section, agi::log::Debug)
namespace agi {
- namespace dispatch { class Queue; }
+namespace dispatch { class Queue; }
+namespace log {
- namespace log {
class LogSink;
/// Severity levels
enum Severity {
- Exception, ///< Used when exceptions are thrown
- Assert, ///< Fatal and non-fatal assert logging
- Warning, ///< Warnings
- Info, ///< Information only
- Debug ///< Enabled by default when compiled in debug mode.
+ Exception, ///< Used when exceptions are thrown
+ Assert, ///< Fatal and non-fatal assert logging
+ Warning, ///< Warnings
+ Info, ///< Information only
+ Debug ///< Enabled by default when compiled in debug mode.
};
/// Short Severity ID
@@ -62,13 +57,13 @@ extern LogSink *log;
/// Container to hold a single message
struct SinkMessage {
- std::string message; ///< Formatted message
- agi_timeval tv; ///< Time at execution
- const char *section; ///< Section info eg "video/open" "video/seek" etc
- const char *file; ///< Source file
- const char *func; ///< Function name
- Severity severity; ///< Severity
- int line; ///< Source line
+ std::string message; ///< Formatted message
+ int64_t time; ///< Time at execution in nanoseconds since epoch
+ const char *section; ///< Section info eg "video/open" "video/seek" etc
+ const char *file; ///< Source file
+ const char *func; ///< Function name
+ Severity severity; ///< Severity
+ int line; ///< Source line
};
class Emitter;
@@ -115,14 +110,10 @@ public:
class JsonEmitter final : public Emitter {
std::unique_ptr fp;
- void WriteTime(const char *key);
-
public:
/// Constructor
/// @param directory Directory to write the log file in
JsonEmitter(fs::path const& directory);
- /// Destructor
- ~JsonEmitter();
void log(SinkMessage *) override;
};
diff --git a/libaegisub/include/libaegisub/time.h b/libaegisub/include/libaegisub/time.h
deleted file mode 100644
index 0152c8f81..000000000
--- a/libaegisub/include/libaegisub/time.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2013, Thomas Goyne
-//
-// Permission to use, copy, modify, and distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-//
-// Aegisub Project http://www.aegisub.org/
-
-#pragma once
-
-#ifdef HAVE_SYS_TIME_H
-# include
-#else
-# include
-#endif
-
-#ifdef _WIN32
-// timeval on windows is defined by winsock, which is a bit much to drag in for
-// a pair of longs
-struct agi_timeval {
- long tv_sec;
- long tv_usec;
-};
-#else
-typedef timeval agi_timeval;
-#endif
diff --git a/libaegisub/include/libaegisub/util.h b/libaegisub/include/libaegisub/util.h
index 972e57334..baeb1ab2e 100644
--- a/libaegisub/include/libaegisub/util.h
+++ b/libaegisub/include/libaegisub/util.h
@@ -12,8 +12,6 @@
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-#include
-
#include
#include
#include
@@ -25,9 +23,6 @@ namespace agi {
/// Clamp `b` to the range [`a`,`c`]
template inline T mid(T a, T b, T c) { return std::max(a, std::min(b, c)); }
- /// Get time suitable for logging mechanisms.
- agi_timeval time_log();
-
bool try_parse(std::string const& str, double *out);
bool try_parse(std::string const& str, int *out);
diff --git a/libaegisub/unix/log.cpp b/libaegisub/unix/log.cpp
index 0e137804b..cdbf7857f 100644
--- a/libaegisub/unix/log.cpp
+++ b/libaegisub/unix/log.cpp
@@ -12,30 +12,31 @@
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#include "libaegisub/log.h"
+
#include
#include
-
#include
-#include "libaegisub/log.h"
-
namespace agi { namespace log {
void EmitSTDOUT::log(SinkMessage *sm) {
+ time_t time = sm->time / 1000000000;
tm tmtime;
- localtime_r(&sm->tv.tv_sec, &tmtime);
+ localtime_r(&time, &tmtime);
printf("%c %02d:%02d:%02d %-6ld <%-25s> [%s:%s:%d] %.*s\n",
Severity_ID[sm->severity],
tmtime.tm_hour,
tmtime.tm_min,
tmtime.tm_sec,
- (long)sm->tv.tv_usec,
+ (long)(sm->time % 1000000000),
sm->section,
sm->file,
sm->func,
sm->line,
(int)sm->message.size(),
sm->message.c_str());
+
if (!isatty(fileno(stdout)))
fflush(stdout);
}
diff --git a/libaegisub/unix/util.cpp b/libaegisub/unix/util.cpp
index 6fbc010a0..4cf672119 100644
--- a/libaegisub/unix/util.cpp
+++ b/libaegisub/unix/util.cpp
@@ -23,13 +23,6 @@
#endif
namespace agi { namespace util {
-
-timeval time_log() {
- timeval tv;
- gettimeofday(&tv, nullptr);
- return tv;
-}
-
void SetThreadName(const char *) { }
void sleep_for(int ms) {
diff --git a/libaegisub/windows/util_win.cpp b/libaegisub/windows/util_win.cpp
index 65be3c6e6..7e91c0421 100644
--- a/libaegisub/windows/util_win.cpp
+++ b/libaegisub/windows/util_win.cpp
@@ -12,10 +12,6 @@
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-/// @file util.cpp
-/// @brief Windows utility methods.
-/// @ingroup libaegisub windows
-
#include "libaegisub/util.h"
#include "libaegisub/charset_conv_win.h"
@@ -43,39 +39,6 @@ std::string ErrorString(int error) {
return str;
}
-/// @brief Get seconds and microseconds.
-/// @param tv[out] agi_timeval struct
-/// This code is from http://www.suacommunity.com/dictionary/gettimeofday-entry.php
-agi_timeval time_log() {
-#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
- // Define a structure to receive the current Windows filetime
- FILETIME ft;
-
- // Initialize the present time to 0 and the timezone to UTC
- unsigned __int64 tmpres = 0;
-
- GetSystemTimeAsFileTime(&ft);
-
- // The GetSystemTimeAsFileTime returns the number of 100 nanosecond
- // intervals since Jan 1, 1601 in a structure. Copy the high bits to
- // the 64 bit tmpres, shift it left by 32 then or in the low 32 bits.
- tmpres |= ft.dwHighDateTime;
- tmpres <<= 32;
- tmpres |= ft.dwLowDateTime;
-
- // Convert to microseconds by dividing by 10
- tmpres /= 10;
-
- // The Unix epoch starts on Jan 1 1970. Need to subtract the difference
- // in seconds from Jan 1 1601.
- tmpres -= DELTA_EPOCH_IN_MICROSECS;
-
- // Finally change microseconds to seconds and place in the seconds value.
- // The modulus picks up the microseconds.
- agi_timeval tv = { (long)(tmpres / 1000000UL), (long)(tmpres % 1000000UL) };
- return tv;
-}
-
#define MS_VC_EXCEPTION 0x406d1388
/// Parameters for setting the thread name
diff --git a/src/dialog_log.cpp b/src/dialog_log.cpp
index b66e10569..4e404afad 100644
--- a/src/dialog_log.cpp
+++ b/src/dialog_log.cpp
@@ -53,15 +53,16 @@ public:
}
void log(agi::log::SinkMessage *sm) override {
+ time_t time = sm->time / 1000000000;
#ifndef _WIN32
tm tmtime;
- localtime_r(&sm->tv.tv_sec, &tmtime);
+ localtime_r(&time, &tmtime);
auto log = wxString::Format("%c %02d:%02d:%02d %-6ld <%-25s> [%s:%s:%d] %s\n",
agi::log::Severity_ID[sm->severity],
(int)tmtime.tm_hour,
(int)tmtime.tm_min,
(int)tmtime.tm_sec,
- (long)sm->tv.tv_usec,
+ (long)(sm->time % 1000000000),
sm->section,
sm->file,
sm->func,
@@ -70,7 +71,7 @@ public:
#else
auto log = wxString::Format("%c %-6ld <%-25s> [%s:%s:%d] %s\n",
agi::log::Severity_ID[sm->severity],
- sm->tv.tv_usec,
+ (long)(sm->time % 1000000000),
sm->section,
sm->file,
sm->func,