test_icl_core_logging.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #include <icl_core/BaseTypes.h>
25 #include <icl_core/os_lxrt.h>
26 #include <icl_core_config/Config.h>
29 #include <icl_core_thread/Thread.h>
30 
31 DECLARE_LOG_STREAM(Main);
32 DECLARE_LOG_STREAM(ThreadLog);
33 
35 REGISTER_LOG_STREAM(ThreadLog)
36 
37 using icl_core::logging::endl;
38 
39 class LoggingThread : public icl_core::thread::Thread
40 {
41 public:
43  size_t message_count,
44  uint32_t sleep_time_us)
45  : icl_core::thread::Thread("LoggingThread", priority),
46  m_message_count(message_count),
47  m_sleep_time_us(sleep_time_us)
48  { }
49 
50  virtual void run()
51  {
52 #ifdef _SYSTEM_LXRT_
53  PRINTF("test_icl_core_logging(LoggingThread): If you see this on the console then I am not hard real-time!\n");
54 #endif
55 
56  LOGGING_ERROR_C(ThreadLog, LoggingThread, "Thread Error" << endl);
57  LOGGING_WARNING_C(ThreadLog, LoggingThread, "Thread Warning" << endl);
58  LOGGING_INFO_C(ThreadLog, LoggingThread, "Thread Info" << endl);
59  LOGGING_DEBUG_C(ThreadLog, LoggingThread, "Thread Debug" << endl);
60  LOGGING_TRACE_C(ThreadLog, LoggingThread, "Thread Trace" << endl);
61 
62  for (size_t i = 0; i < m_message_count; ++i)
63  {
64  LOGGING_INFO_C(ThreadLog, LoggingThread, "Thread Loop " << i << endl);
65  if (m_sleep_time_us > 0)
66  {
67  icl_core::os::usleep(m_sleep_time_us);
68  }
69  }
70  }
71 
72 private:
75 };
76 
77 int main(int argc, char *argv[])
78 {
80 
81  icl_core::config::addParameter(icl_core::config::ConfigParameter("priority:", "p", "/TestLogging/ThreadPriority", "Priority of the logging thread."));
82  icl_core::config::addParameter(icl_core::config::ConfigParameter("message-count:", "c", "/TestLogging/MessageCount", "Number of messages to be logged."));
83  icl_core::config::addParameter(icl_core::config::ConfigParameter("sleep-time:", "s", "/TestLogging/SleepTimeUS", "Sleep time (us) between two log messages."));
84 
86 
87  icl_core::ThreadPriority priority = icl_core::config::getDefault<icl_core::ThreadPriority>("/TestLogging/ThreadPriority", 0);
88  size_t message_count = icl_core::config::getDefault<size_t>("/TestLogging/MessageCount", 10);
89  uint32_t sleep_time_us = icl_core::config::getDefault<uint32_t>("/TestLogging/SleepTimeUS", 1000);
90 
91  LOGGING_INFO(Main, "Creating logging thread." << endl);
92  LoggingThread *thread = new LoggingThread(priority, message_count, sleep_time_us);
93  LOGGING_INFO(Main, "Starting logging thread." << endl);
94  thread->start();
95 
96  {
97  LOGGING_SCOPED_TIMER_INFO(Main, "Main Loop");
98  for (size_t i = 0; i < message_count; ++i)
99  {
100  LOGGING_INFO(Main, "Main Loop " << i << endl);
101  if (sleep_time_us > 0)
102  {
103  icl_core::os::usleep(sleep_time_us);
104  }
105  }
106  }
107 
108  LOGGING_INFO(Main, "Waiting for logging thread to finish." << endl);
109  thread->join();
110  LOGGING_INFO(Main, "Logging thread finished." << endl);
111  delete thread;
112 
115 
116  return 0;
117 }
void lxrtShutdown()
Definition: os_lxrt.cpp:74
unsigned int uint32_t
Definition: msvc_stdint.h:93
#define LOGGING_INFO_C(streamname, classname, arg)
bool initialize(int &argc, char *argv[], bool remove_read_arguments)
void lxrtStartup()
Definition: os_lxrt.cpp:61
#define LOGGING_INFO(streamname, arg)
static LoggingManager & instance()
Base header file for the configuration framework.
Defines logging macros.
Contains a system independet PRINTF macro.
#define LOGGING_WARNING_C(streamname, classname, arg)
DECLARE_LOG_STREAM(Main)
int usleep(unsigned long useconds)
Definition: os_time.h:56
#define LOGGING_DEBUG_C(streamname, classname, arg)
ThreadStream & endl(ThreadStream &stream)
Definition: ThreadStream.h:249
LoggingThread(icl_core::ThreadPriority priority, size_t message_count, uint32_t sleep_time_us)
void addParameter(const ConfigParameter &parameter)
Definition: Config.h:541
Contains global LXRT functions.
REGISTER_LOG_STREAM(Performance)
int main(int argc, char *argv[])
#define LOGGING_SCOPED_TIMER_INFO(streamname, description)
Definition: ScopedTimer.h:155
Contains Interface base classes and base types.
Contains icl_core::thread::Thread.
#define PRINTF
int32_t ThreadPriority
Definition: os_thread.h:50
#define LOGGING_TRACE_C(streamname, classname, arg)
#define LOGGING_ERROR_C(streamname, classname, arg)


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58