Loader: add basic logging abilities
- Enabled with env var LOADER_ENABLE_LOGGING=1 Change-Id: Ibdbb1b55ffddb7dc9c63e52fc9db3013409376a4
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <libelf.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
@@ -224,6 +225,38 @@ private:
|
||||
VariableSymbol& operator=(const VariableSymbol &vs);
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Logger. //
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
class Logger final {
|
||||
public:
|
||||
Logger(std::ostream &Stream = std::cerr) : OutStream(Stream) {}
|
||||
|
||||
template <typename T>
|
||||
Logger &operator<<(const T &Data) {
|
||||
if (!IsLoggingEnabled())
|
||||
return *this;
|
||||
OutStream << Data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
Logger(const Logger &L);
|
||||
Logger& operator=(const Logger &L);
|
||||
|
||||
bool IsLoggingEnabled() const {
|
||||
const char *enable_logging = getenv("LOADER_ENABLE_LOGGING");
|
||||
if (!enable_logging)
|
||||
return false;
|
||||
if (std::string(enable_logging) == "0")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::ostream &OutStream;
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Executable. //
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -501,6 +534,7 @@ private:
|
||||
amd::hsa::common::ReaderWriterLock rw_lock_;
|
||||
hsa_profile_t profile_;
|
||||
Context *context_;
|
||||
Logger logger_;
|
||||
const size_t id_;
|
||||
hsa_default_float_rounding_mode_t default_float_rounding_mode_;
|
||||
hsa_executable_state_t state_;
|
||||
|
||||
Reference in New Issue
Block a user