Skip to content

Commit 673c177

Browse files
mhalkronlieb
authored andcommitted
[offload][ompTest] Added dedicated logging
This is a first iteration on dedicated logging for ompTest. Added logger class Added rudimentary support for log-levels (with colored output) * Can be turned ON via EnVar 'OMPTEST_LOG_COLORED' Change-Id: I3426c45e5f19c1102ee7278f0732ccc85b9209e9
1 parent ad7def2 commit 673c177

19 files changed

+409
-75
lines changed

offload/plugins-nextgen/common/OMPT/OmptTracing.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ OMPT_API_ROUTINE ompt_set_result_t ompt_set_trace_ompt(ompt_device_t *Device,
124124

125125
int DeviceId = getDeviceId(Device);
126126
if (DeviceId < 0) {
127-
REPORT("Failed to set trace events for Device=%p (Unknown device)\n",
128-
Device);
127+
REPORT("Failed to set trace events for Device=%p (Unknown device) "
128+
"[Enable=%d, EventTy=%d]\n",
129+
Device, Enable, EventTy);
129130
return ompt_set_never;
130131
}
131132

offload/test/ompTest/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set(OMPTEST_HEADERS
1717
./include/AssertMacros.h
1818
./include/InternalEvent.h
1919
./include/InternalEventCommon.h
20+
./include/Logging.h
2021
./include/OmptAliases.h
2122
./include/OmptAsserter.h
2223
./include/OmptAssertEvent.h
@@ -31,6 +32,7 @@ add_library(omptest
3132
${OMPTEST_HEADERS}
3233
./src/InternalEvent.cpp
3334
./src/InternalEventOperators.cpp
35+
./src/Logging.cpp
3436
./src/OmptAsserter.cpp
3537
./src/OmptAssertEvent.cpp
3638
./src/OmptCallbackHandler.cpp

offload/test/ompTest/include/AssertMacros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_ASSERTMACROS_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_ASSERTMACROS_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_ASSERTMACROS_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_ASSERTMACROS_H
33

44
#define OMPTEST_EXCLUDED_EVENT omptest::ObserveState::never
55
#define OMPTEST_REQUIRED_EVENT omptest::ObserveState::always

offload/test/ompTest/include/InternalEvent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_INTERNALEVENT_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_INTERNALEVENT_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_INTERNALEVENT_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_INTERNALEVENT_H
33

44
#include "InternalEventCommon.h"
55

offload/test/ompTest/include/InternalEventCommon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_INTERNALEVENTCOMMON_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_INTERNALEVENTCOMMON_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_INTERNALEVENTCOMMON_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_INTERNALEVENTCOMMON_H
33

44
#include "omp-tools.h"
55

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//===--- ompTest/include/Logging.h - ompTest logging class ------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_LOGGING_H
9+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_LOGGING_H
10+
11+
#include "OmptAssertEvent.h"
12+
13+
#include <iostream>
14+
#include <map>
15+
#include <set>
16+
#include <sstream>
17+
#include <string>
18+
19+
namespace omptest {
20+
namespace logging {
21+
22+
enum class Level : uint32_t {
23+
// Levels (Note: DEBUG may already be reserved)
24+
DIAGNOSTIC = 10,
25+
INFO = 20,
26+
WARNING = 30,
27+
ERROR = 40,
28+
CRITICAL = 50,
29+
30+
// Types used for formatting options
31+
Default,
32+
ExpectedEvent,
33+
ObservedEvent,
34+
OffendingEvent
35+
};
36+
37+
enum class FormatOption : uint32_t {
38+
// General options
39+
// Note: BOLD is actually "BRIGHT" -- But it will be perceived as 'bold' font
40+
// It is implicitly switching colors to the 'Light' variant
41+
// Thus, it has -NO EFFECT- when already using a Light* color
42+
NONE = 0,
43+
BOLD = 1,
44+
DIM = 2,
45+
UNDERLINED = 4,
46+
BLINK = 5,
47+
INVERTED = 7,
48+
HIDDEN = 8,
49+
// Foreground colors
50+
COLOR_Default = 39,
51+
COLOR_Black = 30,
52+
COLOR_Red = 31,
53+
COLOR_Green = 32,
54+
COLOR_Yellow = 33,
55+
COLOR_Blue = 34,
56+
COLOR_Magenta = 35,
57+
COLOR_Cyan = 36,
58+
COLOR_LightGray = 37,
59+
COLOR_DarkGray = 90,
60+
COLOR_LightRed = 91,
61+
COLOR_LightGreen = 92,
62+
COLOR_LightYellow = 93,
63+
COLOR_LightBlue = 94,
64+
COLOR_LightMagenta = 95,
65+
COLOR_LightCyan = 96,
66+
COLOR_White = 97,
67+
// Background colors
68+
COLOR_BG_Default = 49,
69+
COLOR_BG_Black = 40,
70+
COLOR_BG_Red = 41,
71+
COLOR_BG_Green = 42,
72+
COLOR_BG_Yellow = 43,
73+
COLOR_BG_Blue = 44,
74+
COLOR_BG_Magenta = 45,
75+
COLOR_BG_Cyan = 46,
76+
COLOR_BG_LightGray = 47,
77+
COLOR_BG_DarkGray = 100,
78+
COLOR_BG_LightRed = 101,
79+
COLOR_BG_LightGreen = 102,
80+
COLOR_BG_LightYellow = 103,
81+
COLOR_BG_LightBlue = 104,
82+
COLOR_BG_LightMagenta = 105,
83+
COLOR_BG_LightCyan = 106,
84+
COLOR_BG_White = 107
85+
};
86+
87+
/// Returns a string representation of the given logging level.
88+
const char *to_string(Level LogLevel);
89+
90+
/// Returns the format options as escaped sequence, for the given logging level
91+
std::string getFormatSequence(Level LogLevel = Level::Default);
92+
93+
/// Format the given message with the provided option(s) and return it.
94+
/// Here formatting is only concerning control sequences using <Esc> character
95+
/// which can be obtained using '\e' (on console), '\033' or '\x1B'.
96+
std::string format(const std::string &Message, FormatOption Option);
97+
std::string format(const std::string &Message, std::set<FormatOption> Options);
98+
99+
class Logger {
100+
public:
101+
~Logger();
102+
103+
/// Retrieve the singleton logger (and initialize, if not done already)
104+
static Logger &get(Level LogLevel = Level::WARNING,
105+
std::ostream &OutStream = std::cerr,
106+
bool FormatOutput = true);
107+
108+
/// Log the given message to the output.
109+
void log(Level LogLevel, const std::string &Message) const;
110+
111+
/// Log a single event mismatch.
112+
void eventMismatch(const omptest::OmptAssertEvent &OffendingEvent,
113+
const std::string &Message,
114+
Level LogLevel = Level::ERROR) const;
115+
116+
/// Log an event-pair mismatch.
117+
void eventMismatch(const omptest::OmptAssertEvent &ExpectedEvent,
118+
const omptest::OmptAssertEvent &ObservedEvent,
119+
const std::string &Message,
120+
Level LogLevel = Level::ERROR) const;
121+
122+
/// Set if output is being formatted.
123+
void setFormatOutput(bool Enabled);
124+
125+
/// Return the current (minimum) Logging Level.
126+
Level getLoggingLevel() const;
127+
128+
/// Set the (minimum) Logging Level.
129+
void setLoggingLevel(Level LogLevel);
130+
131+
private:
132+
Logger(Level LogLevel = Level::WARNING, std::ostream &OutStream = std::cerr,
133+
bool FormatOutput = true);
134+
135+
/// The minimum logging level that is considered by the logger instance.
136+
Level LoggingLevel;
137+
138+
/// The output stream used by the logger instance.
139+
std::ostream &OutStream;
140+
141+
/// Determine if log messages are formatted using control sequences.
142+
bool FormatOutput;
143+
};
144+
145+
} // namespace logging
146+
} // namespace omptest
147+
148+
// Pointer to global logger
149+
extern omptest::logging::Logger *Log;
150+
151+
#endif

offload/test/ompTest/include/OmptAliases.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTALIASES_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTALIASES_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTALIASES_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTALIASES_H
33

44
#include <omp-tools.h>
55

offload/test/ompTest/include/OmptAssertEvent.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTASSERTEVENT_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTASSERTEVENT_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTASSERTEVENT_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTASSERTEVENT_H
33

44
#include "InternalEvent.h"
55
#include "omp-tools.h"
@@ -13,6 +13,8 @@ namespace omptest{
1313

1414
enum class ObserveState { generated, always, never };
1515

16+
const char *to_string(ObserveState State);
17+
1618
struct OmptAssertEvent {
1719

1820
static OmptAssertEvent AssertionSyncPoint(const std::string &Name,

offload/test/ompTest/include/OmptAsserter.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTASSERTER_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTASSERTER_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTASSERTER_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTASSERTER_H
33

44
#include "OmptAssertEvent.h"
55

@@ -83,14 +83,6 @@ class OmptAsserter : public OmptListener {
8383
/// the notification.
8484
virtual void notifyImpl(omptest::OmptAssertEvent &&AE) = 0;
8585

86-
/// Report an error for a single event.
87-
void reportError(const omptest::OmptAssertEvent &OffendingEvent,
88-
const std::string &Message);
89-
90-
void reportError(const omptest::OmptAssertEvent &AwaitedEvent,
91-
const omptest::OmptAssertEvent &OffendingEvent,
92-
const std::string &Message);
93-
9486
/// Get the number of currently remaining events, with: ObserveState::always.
9587
virtual size_t getRemainingEventCount() = 0;
9688

offload/test/ompTest/include/OmptCallbackHandler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTCALLBACKHANDLER_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTCALLBACKHANDLER_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTCALLBACKHANDLER_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTCALLBACKHANDLER_H
33

44
#include "OmptAssertEvent.h"
55
#include "OmptAsserter.h"

offload/test/ompTest/include/OmptTester.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTTESTER_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTTESTER_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTTESTER_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTTESTER_H
33

44
#include "AssertMacros.h"
5+
#include "Logging.h"
56
#include "OmptAliases.h"
67
#include "OmptAssertEvent.h"
78
#include "OmptAsserter.h"

offload/test/ompTest/include/OmptTesterGlobals.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTTESTERGLOBALS_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTTESTERGLOBALS_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTTESTERGLOBALS_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTTESTERGLOBALS_H
33

44
#include <omp-tools.h>
55

offload/test/ompTest/include/OmptTesterGoogleTest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTTESTERGOOGLETEST_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTTESTERGOOGLETEST_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTTESTERGOOGLETEST_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTTESTERGOOGLETEST_H
33

44
#include "AssertMacros.h"
55
#include "OmptAliases.h"

offload/test/ompTest/include/OmptTesterStandalone.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTTESTERSTANDALONE_H
2-
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_OMPTTESTERSTANDALONE_H
1+
#ifndef OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTTESTERSTANDALONE_H
2+
#define OFFLOAD_TEST_OMPTEST_INCLUDE_OMPTTESTERSTANDALONE_H
33

44
#include "OmptAssertEvent.h"
55
#include "OmptAsserter.h"

0 commit comments

Comments
 (0)