| 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/runtime/trace/CallStack.h" |
| 14 |
#include "atlas/runtime/trace/CodeLocation.h" |
| 15 |
#include "atlas/runtime/trace/Logging.h" |
| 16 |
|
| 17 |
//----------------------------------------------------------------------------------------------------------- |
| 18 |
|
| 19 |
namespace atlas { |
| 20 |
namespace runtime { |
| 21 |
namespace trace { |
| 22 |
|
| 23 |
class CurrentCallStack { |
| 24 |
private: |
| 25 |
CurrentCallStack() {} |
| 26 |
CallStack stack_; |
| 27 |
|
| 28 |
public: |
| 29 |
CurrentCallStack(CurrentCallStack const&) = delete; |
| 30 |
CurrentCallStack& operator=(CurrentCallStack const&) = delete; |
| 31 |
static CurrentCallStack& instance() { |
| 32 |
static CurrentCallStack state; |
| 33 |
return state; |
| 34 |
} |
| 35 |
operator CallStack() const { return stack_; } |
| 36 |
CallStack& push(const CodeLocation& loc, const std::string& id) { |
| 37 |
if (Control::enabled()) |
| 38 |
stack_.push(loc, id); |
| 39 |
return stack_; |
| 40 |
} |
| 41 |
void pop() { |
| 42 |
if (Control::enabled()) |
| 43 |
stack_.pop(); |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
} // namespace trace |
| 48 |
} // namespace runtime |
| 49 |
} // namespace atlas |