2015-12-08 19:58:03 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
2015-12-08 22:34:20 +00:00
|
|
|
#include <memory>
|
2015-12-08 19:58:03 +00:00
|
|
|
#include "library/io_state_stream.h"
|
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
void register_trace_class(name const & n);
|
|
|
|
void register_trace_class_alias(name const & n, name const & alias);
|
|
|
|
bool is_trace_enabled();
|
|
|
|
bool is_trace_class_enabled(name const & n);
|
|
|
|
|
2015-12-08 22:34:20 +00:00
|
|
|
#define lean_is_trace_enabled(CName) (::lean::is_trace_enabled() && ::lean::is_trace_class_enabled(CName))
|
|
|
|
|
2015-12-08 19:58:03 +00:00
|
|
|
class scope_trace_env {
|
2015-12-11 19:03:16 +00:00
|
|
|
unsigned m_enable_sz;
|
|
|
|
unsigned m_disable_sz;
|
2015-12-08 19:58:03 +00:00
|
|
|
environment const * m_old_env;
|
|
|
|
io_state const * m_old_ios;
|
|
|
|
public:
|
|
|
|
scope_trace_env(environment const & env, io_state const & ios);
|
|
|
|
~scope_trace_env();
|
|
|
|
};
|
|
|
|
|
|
|
|
class scope_trace_inc_depth {
|
|
|
|
bool m_active{false};
|
|
|
|
public:
|
|
|
|
~scope_trace_inc_depth();
|
|
|
|
void activate();
|
|
|
|
};
|
|
|
|
|
2015-12-08 22:58:08 +00:00
|
|
|
#define LEAN_MERGE_(a, b) a##b
|
2015-12-08 22:34:20 +00:00
|
|
|
#define LEAN_LABEL_(a) LEAN_MERGE_(unique_name_, a)
|
|
|
|
#define LEAN_UNIQUE_NAME LEAN_LABEL_(__LINE__)
|
|
|
|
|
2015-12-09 03:37:06 +00:00
|
|
|
#define lean_trace_inc_depth(CName) \
|
|
|
|
scope_trace_inc_depth LEAN_UNIQUE_NAME; \
|
|
|
|
if (::lean::is_trace_enabled() && ::lean::is_trace_class_enabled(name(CName))) \
|
2015-12-08 22:34:20 +00:00
|
|
|
LEAN_UNIQUE_NAME.activate();
|
|
|
|
|
2015-12-08 20:59:30 +00:00
|
|
|
/* Temporarily set an option if it is not already set in the trace environment. */
|
|
|
|
class scope_trace_init_bool_option {
|
2015-12-08 22:34:20 +00:00
|
|
|
io_state const * m_old_ios{nullptr};
|
|
|
|
std::unique_ptr<io_state> m_tmp_ios;
|
2015-12-08 20:59:30 +00:00
|
|
|
public:
|
|
|
|
~scope_trace_init_bool_option();
|
2015-12-08 22:34:20 +00:00
|
|
|
void init(name const & opt, bool val);
|
2015-12-08 20:59:30 +00:00
|
|
|
};
|
|
|
|
|
2015-12-08 22:34:20 +00:00
|
|
|
#define lean_trace_init_bool(CName, Opt, Val) \
|
|
|
|
scope_trace_init_bool_option LEAN_UNIQUE_NAME; \
|
|
|
|
if (lean_is_trace_enabled(CName)) { \
|
|
|
|
LEAN_UNIQUE_NAME.init(Opt, Val); \
|
|
|
|
}
|
2015-12-08 19:58:03 +00:00
|
|
|
|
2015-12-09 03:37:06 +00:00
|
|
|
/* Helper object for temporarily silencing trace messages */
|
|
|
|
class scope_trace_silent {
|
|
|
|
io_state * m_old_ios{nullptr};
|
|
|
|
public:
|
|
|
|
scope_trace_silent(bool flag);
|
|
|
|
~scope_trace_silent();
|
|
|
|
};
|
|
|
|
|
2015-12-08 19:58:03 +00:00
|
|
|
struct tdepth {};
|
|
|
|
struct tclass { name m_cls; tclass(name const & c):m_cls(c) {} };
|
|
|
|
|
|
|
|
io_state_stream tout();
|
|
|
|
io_state_stream const & operator<<(io_state_stream const & ios, tdepth const &);
|
|
|
|
io_state_stream const & operator<<(io_state_stream const & ios, tclass const &);
|
|
|
|
|
2015-12-08 20:59:30 +00:00
|
|
|
#define lean_trace_plain(CName, CODE) { \
|
|
|
|
if (lean_is_trace_enabled(CName)) { \
|
2015-12-08 19:58:03 +00:00
|
|
|
CODE \
|
|
|
|
}}
|
|
|
|
|
|
|
|
#define lean_trace(CName, CODE) { \
|
|
|
|
if (lean_is_trace_enabled(CName)) { \
|
2015-12-08 20:59:30 +00:00
|
|
|
tout() << tclass(CName); CODE \
|
2015-12-08 19:58:03 +00:00
|
|
|
}}
|
|
|
|
|
2015-12-08 20:59:30 +00:00
|
|
|
#define lean_trace_d(CName, CODE) { \
|
|
|
|
if (lean_is_trace_enabled(CName)) { \
|
|
|
|
tout() << tdepth() << tclass(CName); CODE \
|
2015-12-08 19:58:03 +00:00
|
|
|
}}
|
|
|
|
|
|
|
|
void initialize_trace();
|
|
|
|
void finalize_trace();
|
|
|
|
}
|