| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include "atlas/library/config.h" |
| 14 |
#include "atlas/runtime/trace/Barriers.h" |
| 15 |
#include "atlas/runtime/trace/Logging.h" |
| 16 |
#include "atlas/runtime/trace/TraceT.h" |
| 17 |
|
| 18 |
//----------------------------------------------------------------------------------------------------------- |
| 19 |
|
| 20 |
/// Create scoped trace objects |
| 21 |
/// |
| 22 |
/// Example: |
| 23 |
/// |
| 24 |
/// void foo() { |
| 25 |
/// ATLAS_TRACE(); |
| 26 |
/// // trace "foo" starts |
| 27 |
/// |
| 28 |
/// /* interesting computations ... */ |
| 29 |
/// |
| 30 |
/// ATLAS_TRACE_SCOPE("bar") { |
| 31 |
/// // trace "bar" starts |
| 32 |
/// |
| 33 |
/// /* interesting computations ... */ |
| 34 |
/// |
| 35 |
/// // trace "bar" ends |
| 36 |
/// } |
| 37 |
/// |
| 38 |
/// // trace "foo" ends |
| 39 |
/// } |
| 40 |
/// |
| 41 |
/// Example 2: |
| 42 |
/// |
| 43 |
/// void foo() { |
| 44 |
/// ATLAS_TRACE("custom"); |
| 45 |
/// // trace "custom" starts |
| 46 |
/// |
| 47 |
/// /* interesting computations ... */ |
| 48 |
/// |
| 49 |
/// // trace "custom" ends |
| 50 |
/// } |
| 51 |
/// |
| 52 |
#define ATLAS_TRACE(...) |
| 53 |
#define ATLAS_TRACE_SCOPE(...) |
| 54 |
#define ATLAS_TRACE_BARRIERS(enabled) |
| 55 |
|
| 56 |
//----------------------------------------------------------------------------------------------------------- |
| 57 |
|
| 58 |
namespace atlas { |
| 59 |
|
| 60 |
namespace runtime { |
| 61 |
namespace trace { |
| 62 |
struct TraceTraits { |
| 63 |
#if ATLAS_HAVE_TRACE_BARRIERS |
| 64 |
using Barriers = ::atlas::runtime::trace::Barriers; |
| 65 |
#else |
| 66 |
using Barriers = ::atlas::runtime::trace::NoBarriers; |
| 67 |
#endif |
| 68 |
using Tracing = ::atlas::runtime::trace::Logging; |
| 69 |
}; |
| 70 |
|
| 71 |
} // namespace trace |
| 72 |
} // namespace runtime |
| 73 |
|
| 74 |
class Trace : public runtime::trace::TraceT<runtime::trace::TraceTraits> { |
| 75 |
using Base = runtime::trace::TraceT<runtime::trace::TraceTraits>; |
| 76 |
using Traits = runtime::trace::TraceTraits; |
| 77 |
|
| 78 |
public: |
| 79 |
using Base::Base; |
| 80 |
}; |
| 81 |
|
| 82 |
} // namespace atlas |
| 83 |
|
| 84 |
//----------------------------------------------------------------------------------------------------------- |
| 85 |
|
| 86 |
#if ATLAS_HAVE_TRACE |
| 87 |
|
| 88 |
#include "atlas/library/detail/BlackMagic.h" |
| 89 |
|
| 90 |
#undef ATLAS_TRACE |
| 91 |
#undef ATLAS_TRACE_SCOPE |
| 92 |
#undef ATLAS_TRACE_BARRIERS |
| 93 |
|
| 94 |
#define ATLAS_TRACE(...) __ATLAS_TYPE(::atlas::Trace, Here() __ATLAS_COMMA_ARGS(__VA_ARGS__)) |
| 95 |
#define ATLAS_TRACE_SCOPE(...) __ATLAS_TYPE_SCOPE(::atlas::Trace, Here() __ATLAS_COMMA_ARGS(__VA_ARGS__)) |
| 96 |
#define ATLAS_TRACE_BARRIERS(enabled) __ATLAS_TYPE(::atlas::Trace::Barriers, enabled) |
| 97 |
|
| 98 |
#endif |
| 99 |
|
| 100 |
//----------------------------------------------------------------------------------------------------------- |