blob: 44778689dbc8556922cf7a4e9ef466bc676542bd [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#include <errno.h>
brians343bc112013-02-10 01:53:46 +00002#include <fcntl.h>
3#include <inttypes.h>
Austin Schuhf2a50ba2016-12-24 16:16:26 -08004#include <pwd.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <sys/types.h>
9#include <time.h>
10#include <unistd.h>
11#include <chrono>
12#include <string>
brians343bc112013-02-10 01:53:46 +000013
John Park33858a32018-09-28 23:05:48 -070014#include "aos/logging/implementations.h"
15#include "aos/logging/logging.h"
16#include "aos/time/time.h"
John Park398c74a2018-10-20 21:17:39 -070017#include "aos/init.h"
18#include "aos/ipc_lib/queue.h"
brians343bc112013-02-10 01:53:46 +000019
Brian Silvermanf665d692013-02-17 22:11:39 -080020namespace aos {
21namespace logging {
Brian Silverman14fd0fb2014-01-14 21:42:01 -080022namespace linux_code {
Brian Silvermanf665d692013-02-17 22:11:39 -080023namespace {
brians343bc112013-02-10 01:53:46 +000024
Austin Schuhf2a50ba2016-12-24 16:16:26 -080025namespace chrono = ::std::chrono;
26
Brian Silvermanab6615c2013-03-05 20:29:29 -080027int LogStreamerMain() {
Brian Silvermanf665d692013-02-17 22:11:39 -080028 InitNRT();
brians343bc112013-02-10 01:53:46 +000029
Brian Silvermancb5da1f2015-12-05 22:19:58 -050030 RawQueue *queue = GetLoggingQueue();
31
Austin Schuhf2a50ba2016-12-24 16:16:26 -080032 const monotonic_clock::time_point now = monotonic_clock::now();
33 chrono::seconds sec =
34 chrono::duration_cast<chrono::seconds>(now.time_since_epoch());
35 chrono::nanoseconds nsec =
36 chrono::duration_cast<chrono::nanoseconds>(now.time_since_epoch() - sec);
Brian Silverman8efe23e2013-07-07 23:31:37 -070037 printf("starting at %" PRId32 "s%" PRId32 "ns-----------------------------\n",
Austin Schuhf2a50ba2016-12-24 16:16:26 -080038 static_cast<int32_t>(sec.count()), static_cast<int32_t>(nsec.count()));
brians343bc112013-02-10 01:53:46 +000039
brians343bc112013-02-10 01:53:46 +000040 while (true) {
Brian Silverman18c2c362016-01-02 14:18:32 -080041 const LogMessage *const msg = static_cast<const LogMessage *>(
42 queue->ReadMessage(RawQueue::kNonBlock));
43 if (msg == NULL) {
Austin Schuhf2a50ba2016-12-24 16:16:26 -080044 ::std::this_thread::sleep_for(::std::chrono::milliseconds(100));
Brian Silverman18c2c362016-01-02 14:18:32 -080045 } else {
46 internal::PrintMessage(stdout, *msg);
brians343bc112013-02-10 01:53:46 +000047
Brian Silverman18c2c362016-01-02 14:18:32 -080048 queue->FreeMessage(msg);
49 }
brians343bc112013-02-10 01:53:46 +000050 }
51
Brian Silvermanf665d692013-02-17 22:11:39 -080052 Cleanup();
53 return 0;
54}
55
56} // namespace
Brian Silverman14fd0fb2014-01-14 21:42:01 -080057} // namespace linux_code
Brian Silvermanf665d692013-02-17 22:11:39 -080058} // namespace logging
59} // namespace aos
60
61int main() {
Brian Silverman14fd0fb2014-01-14 21:42:01 -080062 return ::aos::logging::linux_code::LogStreamerMain();
brians343bc112013-02-10 01:53:46 +000063}