COSA
An Object-Oriented Platform for Arduino Programming
Trace.hh File Reference
#include "Cosa/Types.h"
#include "Cosa/IOStream.hh"
Include dependency graph for Trace.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Trace
 

Macros

#define LOG_EMERG   0 /* System is unusable */
 
#define LOG_ALERT   1 /* Action must be taken immediately */
 
#define LOG_CRIT   2 /* Critical conditions */
 
#define LOG_ERR   3 /* Error conditions */
 
#define LOG_WARNING   4 /* Warning conditions */
 
#define LOG_NOTICE   5 /* Normal but significant condition */
 
#define LOG_INFO   6 /* Informational */
 
#define LOG_DEBUG   7 /* Debug-level messages */
 
#define LOG_MASK(prio)   (1 << (prio))
 
#define LOG_UPTO(prio)   (LOG_MASK((prio) + 1) - 1)
 
#define FATAL(msg)
 
#define ASSERT(expr)
 
#define TRACE_P(str)   trace.print(PSTR(str))
 
#define TRACE(expr)
 
#define TRACE_LOG(msg, ...)
 
#define IS_LOG_PRIO(prio)   (trace_log_mask & LOG_MASK(prio))
 
#define EMERG(msg, ...)   if (IS_LOG_PRIO(LOG_EMERG)) TRACE_LOG("emerg:" msg, __VA_ARGS__)
 
#define ALERT(msg, ...)   if (IS_LOG_PRIO(LOG_ALERT)) TRACE_LOG("alert:" msg, __VA_ARGS__)
 
#define CRIT(msg, ...)   if (IS_LOG_PRIO(LOG_CRIT)) TRACE_LOG("crit:" msg, __VA_ARGS__)
 
#define ERR(msg, ...)   if (IS_LOG_PRIO(LOG_ERR)) TRACE_LOG("err:" msg, __VA_ARGS__)
 
#define WARNING(msg, ...)   if (IS_LOG_PRIO(LOG_WARNING)) TRACE_LOG("warning:" msg, __VA_ARGS__)
 
#define NOTICE(msg, ...)   if (IS_LOG_PRIO(LOG_NOTICE)) TRACE_LOG("notice:" msg, __VA_ARGS__)
 
#define INFO(msg, ...)   if (IS_LOG_PRIO(LOG_INFO)) TRACE_LOG("info:" msg, __VA_ARGS__)
 
#define DEBUG(msg, ...)   if (IS_LOG_PRIO(LOG_DEBUG)) TRACE_LOG("debug:" msg, __VA_ARGS__)
 
#define MEASURE(msg, cnt)
 
#define measure(msg, cnt)
 

Variables

uint8_t trace_log_mask
 
Trace trace
 

Detailed Description

Version
1.0

License

Copyright (C) 2012-2015, Mikael Patel

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

This file is part of the Arduino Che Cosa project.

Definition in file Trace.hh.

Macro Definition Documentation

#define ALERT (   msg,
  ... 
)    if (IS_LOG_PRIO(LOG_ALERT)) TRACE_LOG("alert:" msg, __VA_ARGS__)

Definition at line 174 of file Trace.hh.

#define ASSERT (   expr)
Value:
do { \
if (UNLIKELY(!(expr))) FATAL("assert:" #expr); \
} while (0)
#define FATAL(msg)
Definition: Trace.hh:115
#define UNLIKELY(x)
Definition: Types.h:153

Support macro to check that an expression is valid. The expression is used as a string and evaluated. If false a message is printed to the trace device and the program will terminate.

Parameters
[in]exprexpression to validate.

Definition at line 127 of file Trace.hh.

#define CRIT (   msg,
  ... 
)    if (IS_LOG_PRIO(LOG_CRIT)) TRACE_LOG("crit:" msg, __VA_ARGS__)

Definition at line 176 of file Trace.hh.

#define DEBUG (   msg,
  ... 
)    if (IS_LOG_PRIO(LOG_DEBUG)) TRACE_LOG("debug:" msg, __VA_ARGS__)

Definition at line 186 of file Trace.hh.

#define EMERG (   msg,
  ... 
)    if (IS_LOG_PRIO(LOG_EMERG)) TRACE_LOG("emerg:" msg, __VA_ARGS__)

Definition at line 172 of file Trace.hh.

#define ERR (   msg,
  ... 
)    if (IS_LOG_PRIO(LOG_ERR)) TRACE_LOG("err:" msg, __VA_ARGS__)

Definition at line 178 of file Trace.hh.

#define FATAL (   msg)
Value:
trace.fatal(__FILE__, \
__LINE__, \
__PSTR(msg))
void fatal(const char *file, int line, str_P expr)
Definition: Trace.cpp:39
Trace trace
Definition: Trace.cpp:23
#define __PSTR(s)
Definition: Types.h:203

Prints given message with current file name and line number to trace device and the program will terminate. The message string is stored in program memory.

Parameters
[in]msgmessage string to print.

Definition at line 115 of file Trace.hh.

#define INFO (   msg,
  ... 
)    if (IS_LOG_PRIO(LOG_INFO)) TRACE_LOG("info:" msg, __VA_ARGS__)

Definition at line 184 of file Trace.hh.

#define IS_LOG_PRIO (   prio)    (trace_log_mask & LOG_MASK(prio))

Definition at line 171 of file Trace.hh.

#define LOG_ALERT   1 /* Action must be taken immediately */

Definition at line 91 of file Trace.hh.

#define LOG_CRIT   2 /* Critical conditions */

Definition at line 92 of file Trace.hh.

#define LOG_DEBUG   7 /* Debug-level messages */

Definition at line 97 of file Trace.hh.

#define LOG_EMERG   0 /* System is unusable */

Log priorities.

Definition at line 90 of file Trace.hh.

#define LOG_ERR   3 /* Error conditions */

Definition at line 93 of file Trace.hh.

#define LOG_INFO   6 /* Informational */

Definition at line 96 of file Trace.hh.

#define LOG_MASK (   prio)    (1 << (prio))

Macros to generate mask for the trace log priorities (LOG_EMERG.. LOG_DEBUG) setting of trace_log_mask. LOG_MASK(prio) bit mask corresponding to the given priority. LOG_UPTO(prio) bit mask for all priorities including the given.

Definition at line 105 of file Trace.hh.

#define LOG_NOTICE   5 /* Normal but significant condition */

Definition at line 95 of file Trace.hh.

#define LOG_UPTO (   prio)    (LOG_MASK((prio) + 1) - 1)

Definition at line 106 of file Trace.hh.

#define LOG_WARNING   4 /* Warning conditions */

Definition at line 94 of file Trace.hh.

#define MEASURE (   msg,
  cnt 
)
Value:
for (uint32_t __stop, __start = RTT::micros(), __i = 1; \
__i != 0; \
__i--, \
__stop = RTT::micros(), \
trace.measure = (__stop - __start) / cnt, \
trace << __LINE__ << ':' << __PRETTY_FUNCTION__, \
trace << PSTR(":measure:") << PSTR(msg) << trace.measure, \
trace << PSTR(" us") << endl, \
for (uint16_t __j = cnt; __j != 0; __j--)
Trace trace
Definition: Trace.cpp:23
#define PSTR(s)
Definition: Types.h:202
static uint32_t micros()
Definition: RTT.cpp:103
void flush()
Definition: IOStream.hh:504
uint32_t measure
Definition: Trace.hh:80
IOStream & endl(IOStream &outs)
Definition: IOStream.hh:817

Syntactic sugar for measuring execution time for a block. Used in the form:

1 MEASURE("time to execute block", 1) {
2  ...
3  // Block of code to measure
4  ...
5  ...
6 }
Parameters
[in]msgmeasurement prefix string.
[in]cntnumber of block calls (max UINT16_MAX).

Definition at line 241 of file Trace.hh.

#define measure (   msg,
  cnt 
)
Value:
for (uint32_t __stop, __start = RTT::millis(), __i = 1; \
__i != 0; \
__i--, \
__stop = RTT::millis(), \
trace.measure = (__stop - __start) / cnt, \
trace << __LINE__ << ':' << __PRETTY_FUNCTION__, \
trace << PSTR(":measure:") << PSTR(msg) << trace.measure, \
trace << PSTR(" ms") << endl, \
for (uint16_t __j = cnt; __j != 0; __j--)
Trace trace
Definition: Trace.cpp:23
#define PSTR(s)
Definition: Types.h:202
void flush()
Definition: IOStream.hh:504
uint32_t measure
Definition: Trace.hh:80
static uint32_t millis()
Definition: RTT.cpp:121
IOStream & endl(IOStream &outs)
Definition: IOStream.hh:817

Definition at line 253 of file Trace.hh.

#define NOTICE (   msg,
  ... 
)    if (IS_LOG_PRIO(LOG_NOTICE)) TRACE_LOG("notice:" msg, __VA_ARGS__)

Definition at line 182 of file Trace.hh.

#define TRACE (   expr)
Value:
do { \
trace.printf(__PSTR("%d:%s:trace:" #expr " = "), \
__LINE__, \
__PRETTY_FUNCTION__); \
trace.print(expr); \
} while (0)
void println()
Definition: IOStream.hh:467
void print(int value, Base base=dec)
Definition: IOStream.cpp:46
Trace trace
Definition: Trace.cpp:23
void printf(str_P format,...)
Definition: IOStream.hh:487
#define __PSTR(s)
Definition: Types.h:203

Support macro for trace of an expression. The expression is used as a string and evaluated.

Parameters
[in]exprexpression.

Definition at line 151 of file Trace.hh.

#define TRACE_LOG (   msg,
  ... 
)
Value:
trace.printf(__PSTR("%d:%s:" msg "\r\n"), \
__LINE__, \
__PRETTY_FUNCTION__, \
__VA_ARGS__)
Trace trace
Definition: Trace.cpp:23
void printf(str_P format,...)
Definition: IOStream.hh:487
#define __PSTR(s)
Definition: Types.h:203

Support macro for trace of a log message with line number and function name prefix.

Parameters
[in]msglog message.

Definition at line 166 of file Trace.hh.

#define TRACE_P (   str)    trace.print(PSTR(str))

Support macro for trace of a string in program memory.

Parameters
[in]strstring literal

Definition at line 136 of file Trace.hh.

#define WARNING (   msg,
  ... 
)    if (IS_LOG_PRIO(LOG_WARNING)) TRACE_LOG("warning:" msg, __VA_ARGS__)

Definition at line 180 of file Trace.hh.

Variable Documentation

Trace trace

The Trace class singleton.

Definition at line 23 of file Trace.cpp.

uint8_t trace_log_mask

Definition at line 25 of file Trace.cpp.