TensorRT  7.2.1.6
NVIDIA TensorRT
Looking for a C++ dev who knows TensorRT?
I'm looking for work. Hire me!
sample::Logger Class Reference

Class which manages logging of TensorRT tools and samples. More...

Inheritance diagram for sample::Logger:
Collaboration diagram for sample::Logger:

Classes

class  TestAtom
 Opaque handle that holds logging information for a particular test. More...
 

Public Types

enum  TestResult {
  TestResult::kRUNNING,
  TestResult::kPASSED,
  TestResult::kFAILED,
  TestResult::kWAIVED
}
 Represents the state of a given test. More...
 
enum  Severity : int32_t {
  Severity::kINTERNAL_ERROR = 0,
  Severity::kERROR = 1,
  Severity::kWARNING = 2,
  Severity::kINFO = 3,
  Severity::kVERBOSE = 4
}
 

Public Member Functions

 Logger (Severity severity=Severity::kWARNING)
 
nvinfer1::ILoggergetTRTLogger ()
 Forward-compatible method for retrieving the nvinfer::ILogger associated with this Logger. More...
 
void log (Severity severity, const char *msg) override
 Implementation of the nvinfer1::ILogger::log() virtual method. More...
 
void setReportableSeverity (Severity severity)
 Method for controlling the verbosity of logging output. More...
 
Severity getReportableSeverity () const
 

Static Public Member Functions

static TestAtom defineTest (const std::string &name, const std::string &cmdline)
 Define a test for logging. More...
 
static TestAtom defineTest (const std::string &name, int argc, char const *const *argv)
 A convenience overloaded version of defineTest() that accepts an array of command-line arguments as input. More...
 
static void reportTestStart (TestAtom &testAtom)
 Report that a test has started. More...
 
static void reportTestEnd (const TestAtom &testAtom, TestResult result)
 Report that a test has ended. More...
 
static int reportPass (const TestAtom &testAtom)
 
static int reportFail (const TestAtom &testAtom)
 
static int reportWaive (const TestAtom &testAtom)
 
static int reportTest (const TestAtom &testAtom, bool pass)
 

Static Private Member Functions

static const char * severityPrefix (Severity severity)
 returns an appropriate string for prefixing a log message with the given severity More...
 
static const char * testResultString (TestResult result)
 returns an appropriate string for prefixing a test result message with the given result More...
 
static std::ostream & severityOstream (Severity severity)
 returns an appropriate output stream (cout or cerr) to use with the given severity More...
 
static void reportTestResult (const TestAtom &testAtom, TestResult result)
 method that implements logging test results More...
 
static std::string genCmdlineString (int argc, char const *const *argv)
 generate a command line string from the given (argc, argv) values More...
 

Private Attributes

Severity mReportableSeverity
 

Detailed Description

Class which manages logging of TensorRT tools and samples.

This class provides a common interface for TensorRT tools and samples to log information to the console, and supports logging two types of messages:

  • Debugging messages with an associated severity (info, warning, error, or internal error/fatal)
  • Test pass/fail messages

The advantage of having all samples use this class for logging as opposed to emitting directly to stdout/stderr is that the logic for controlling the verbosity and formatting of sample output is centralized in one location.

In the future, this class could be extended to support dumping test results to a file in some standard format (for example, JUnit XML), and providing additional metadata (e.g. timing the duration of a test run).

TODO: For backwards compatibility with existing samples, this class inherits directly from the nvinfer1::ILogger interface, which is problematic since there isn't a clean separation between messages coming from the TensorRT library and messages coming from the sample.

In the future (once all samples are updated to use Logger::getTRTLogger() to access the ILogger) we can refactor the class to eliminate the inheritance and instead make the nvinfer1::ILogger implementation a member of the Logger object.

Member Enumeration Documentation

◆ TestResult

Represents the state of a given test.

Enumerator
kRUNNING 

The test is running.

kPASSED 

The test passed.

kFAILED 

The test failed.

kWAIVED 

The test was waived.

◆ Severity

enum nvinfer1::ILogger::Severity : int32_t
stronginherited

The severity corresponding to a log message.

Enumerator
kINTERNAL_ERROR 

Internal error has occurred. Execution is unrecoverable.

kERROR 

Application error has occurred.

kWARNING 

Application error has been discovered. TensorRT has recovered or fallen back to a default.

kINFO 

Informational messages with instructional information.

kVERBOSE 

Verbose messages with debugging information.

Constructor & Destructor Documentation

◆ Logger()

sample::Logger::Logger ( Severity  severity = Severity::kWARNING)
inline

Member Function Documentation

◆ getTRTLogger()

nvinfer1::ILogger& sample::Logger::getTRTLogger ( )
inline

Forward-compatible method for retrieving the nvinfer::ILogger associated with this Logger.

Returns
The nvinfer1::ILogger associated with this Logger

TODO Once all samples are updated to use this method to register the logger with TensorRT, we can eliminate the inheritance of Logger from ILogger

◆ log()

void sample::Logger::log ( Severity  severity,
const char *  msg 
)
inlineoverridevirtual

Implementation of the nvinfer1::ILogger::log() virtual method.

Note samples should not be calling this function directly; it will eventually go away once we eliminate the inheritance from nvinfer1::ILogger

Implements nvinfer1::ILogger.

Here is the caller graph for this function:

◆ setReportableSeverity()

void sample::Logger::setReportableSeverity ( Severity  severity)
inline

Method for controlling the verbosity of logging output.

Parameters
severityThe logger will only emit messages that have severity of this level or higher.
Here is the caller graph for this function:

◆ defineTest() [1/2]

static TestAtom sample::Logger::defineTest ( const std::string &  name,
const std::string &  cmdline 
)
inlinestatic

Define a test for logging.

Parameters
[in]nameThe name of the test. This should be a string starting with "TensorRT" and containing dot-separated strings containing the characters [A-Za-z0-9_]. For example, "TensorRT.sample_googlenet"
[in]cmdlineThe command line used to reproduce the test
Returns
a TestAtom that can be used in Logger::reportTest{Start,End}().
Here is the caller graph for this function:

◆ defineTest() [2/2]

static TestAtom sample::Logger::defineTest ( const std::string &  name,
int  argc,
char const *const *  argv 
)
inlinestatic

A convenience overloaded version of defineTest() that accepts an array of command-line arguments as input.

Parameters
[in]nameThe name of the test
[in]argcThe number of command-line arguments
[in]argvThe array of command-line arguments (given as C strings)
Returns
a TestAtom that can be used in Logger::reportTest{Start,End}().
Here is the call graph for this function:

◆ reportTestStart()

static void sample::Logger::reportTestStart ( TestAtom testAtom)
inlinestatic

Report that a test has started.

Precondition
reportTestStart() has not been called yet for the given testAtom
Parameters
[in]testAtomThe handle to the test that has started
Here is the call graph for this function:

◆ reportTestEnd()

static void sample::Logger::reportTestEnd ( const TestAtom testAtom,
TestResult  result 
)
inlinestatic

Report that a test has ended.

Precondition
reportTestStart() has been called for the given testAtom
Parameters
[in]testAtomThe handle to the test that has ended
[in]resultThe result of the test. Should be one of TestResult::kPASSED, TestResult::kFAILED, TestResult::kWAIVED
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reportPass()

static int sample::Logger::reportPass ( const TestAtom testAtom)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reportFail()

static int sample::Logger::reportFail ( const TestAtom testAtom)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reportWaive()

static int sample::Logger::reportWaive ( const TestAtom testAtom)
inlinestatic
Here is the call graph for this function:

◆ reportTest()

static int sample::Logger::reportTest ( const TestAtom testAtom,
bool  pass 
)
inlinestatic
Here is the call graph for this function:

◆ getReportableSeverity()

Severity sample::Logger::getReportableSeverity ( ) const
inline
Here is the caller graph for this function:

◆ severityPrefix()

static const char* sample::Logger::severityPrefix ( Severity  severity)
inlinestaticprivate

returns an appropriate string for prefixing a log message with the given severity

◆ testResultString()

static const char* sample::Logger::testResultString ( TestResult  result)
inlinestaticprivate

returns an appropriate string for prefixing a test result message with the given result

Here is the caller graph for this function:

◆ severityOstream()

static std::ostream& sample::Logger::severityOstream ( Severity  severity)
inlinestaticprivate

returns an appropriate output stream (cout or cerr) to use with the given severity

Here is the caller graph for this function:

◆ reportTestResult()

static void sample::Logger::reportTestResult ( const TestAtom testAtom,
TestResult  result 
)
inlinestaticprivate

method that implements logging test results

Here is the call graph for this function:
Here is the caller graph for this function:

◆ genCmdlineString()

static std::string sample::Logger::genCmdlineString ( int  argc,
char const *const *  argv 
)
inlinestaticprivate

generate a command line string from the given (argc, argv) values

Here is the caller graph for this function:

Member Data Documentation

◆ mReportableSeverity

Severity sample::Logger::mReportableSeverity
private

The documentation for this class was generated from the following file: