Mir

Merge lp:~vanvugt/mir/logtime into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Approved by: kevin gunn
Approved revision: no longer in the source branch.
Merged at revision: 1288
Proposed branch: lp:~vanvugt/mir/logtime
Merge into: lp:mir
Diff against target: 34 lines (+17/-2)
1 file modified
src/shared/logging/dumb_console_logger.cpp (+17/-2)
To merge this branch: bzr merge lp:~vanvugt/mir/logtime
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Kevin DuBois (community) Approve
Alexandros Frantzis (community) Approve
Alan Griffiths Needs Information
Andreas Pokorny (community) Approve
Review via email: mp+198675@code.launchpad.net

Commit message

Logging: Add timestamps to log messages and change the prefix format to be
more like that of kernel/Xorg logs:
[seconds.microseconds] (severity) component: your message goes here

Importantly, the timestamps are consistent system-wide so you can compare
them between different processes, concatenate logs from different processes,
and sort the result into meaningful output.

To post a comment you must log in.
Revision history for this message
Andreas Pokorny (andreas-pokorny) :
review: Approve
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

The display of the timestamp can be written more idiomatically and more safely (since we avoid the manual conversion) as:

auto secs = duration_cast<duration<double>>(system_clock::now().time_since_epoch());
auto old_flags = out.flags();
out << std::fixed << secs.count() << std::endl;
out.setf(old_flags);

review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

I am intentionally avoiding floating point at every stage due to its lack of precision. Maintaining integers all the way through provides a guarantee that the digits right of the decimal point are accurate. Floating point does not.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

As per the standard, single precision floating point are guaranteed to have a precision of at least 6 decimal digits, and double precision numbers a precision of least 10 decimal digits (in practice, i.e., when using IEEE 754 representation, the precision is actually larger). Double should be more than enough for our purposes. Plus we are just converting to double, not doing any arithmetic with it which could lead to the accumulation of precision errors. Anyway, I am not really fussed over the current approach, so abstaining.

review: Abstain
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

According to IEEE754, even a double will not fit enough decimal digits to accurately represent system_clock time in microseconds. A double can represent 15.95 decimal digits. But the system_clock in microseconds is at least 16 digits.

[http://en.wikipedia.org/wiki/IEEE_floating_point]

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I'm not against changing the output format. But isn't this just replicating what glog already provides?

review: Needs Information
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

this would be easier to test if it used the_time_source() instead of accessing the system clock directly.

And it lacks tests. ;:

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> According to IEEE754, even a double will not fit enough decimal digits to accurately represent system_clock time in > microseconds. A double can represent 15.95 decimal digits. But the system_clock in microseconds is at least 16
> digits.

OK, convinced. It would be useful to have some tests like Alan suggests, but not a blocker.

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

the_time_source() uses std::chrono::high_resolution_clock, which I believe is unsafe to use in this case because there's possibly less guarantee of it having the same epoch between different processes. I did consider that already.

I don't think it's appropriate to write tests for trivial debugging code like this. Although one potential case for tests here would be to verify the format does not change when we have tooling which depends on it...

Revision history for this message
Kevin DuBois (kdub) wrote :

i don't know if breaking before every << improves readability, but otherwise good

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

> I'm not against changing the output format. But isn't this just replicating
> what glog already provides?

I don't know what glog provides. If it did the formatting for us then great. But I do know that DumbConsoleLogger has no dependencies on glog. You'd have to redesign classes to utilize glog in this case, no?

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Modified to use CLOCK_REALTIME, so we can accurately calculate the latency between kernel input events and server.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/shared/logging/dumb_console_logger.cpp'
2--- src/shared/logging/dumb_console_logger.cpp 2013-06-03 08:14:01 +0000
3+++ src/shared/logging/dumb_console_logger.cpp 2013-12-16 09:58:03 +0000
4@@ -19,6 +19,8 @@
5 #include "mir/logging/dumb_console_logger.h"
6
7 #include <iostream>
8+#include <ctime>
9+#include <cstdio>
10
11 namespace ml = mir::logging;
12
13@@ -38,6 +40,19 @@
14
15 std::ostream& out = severity < Logger::informational ? std::cerr : std::cout;
16
17- out << "[" << lut[severity] << ", " << component << "] "
18- << message << "\n";
19+ struct timespec ts;
20+ clock_gettime(CLOCK_REALTIME, &ts);
21+ char now[32];
22+ snprintf(now, sizeof(now), "%ld.%06ld",
23+ (long)ts.tv_sec, ts.tv_nsec / 1000);
24+
25+ out << "["
26+ << now
27+ << "] ("
28+ << lut[severity]
29+ << ") "
30+ << component
31+ << ": "
32+ << message
33+ << "\n";
34 }

Subscribers

People subscribed via source and target branches