Unify logging facilities. (#3982)
* Unify logging facilities. * Enhance `ConsoleLogger` to handle different verbosity. * Override macros from `dmlc`. * Don't use specialized gamma when building with GPU. * Remove verbosity cache in monitor. * Test monitor. * Deprecate `silent`. * Fix doc and messages. * Fix python test. * Fix silent tests.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
#include <thrust/device_vector.h>
|
||||
#include <xgboost/base.h>
|
||||
#include "../../../src/common/device_helpers.cuh"
|
||||
#include "../../../src/common/timer.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
struct Shard { int id; };
|
||||
|
||||
32
tests/cpp/common/test_monitor.cc
Normal file
32
tests/cpp/common/test_monitor.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <xgboost/logging.h>
|
||||
#include <string>
|
||||
#include "../../../src/common/timer.h"
|
||||
|
||||
namespace xgboost {
|
||||
namespace common {
|
||||
TEST(Monitor, Basic) {
|
||||
auto run_monitor =
|
||||
[]() {
|
||||
Monitor monitor_;
|
||||
monitor_.Init("Monitor test");
|
||||
monitor_.Start("basic");
|
||||
monitor_.Stop("basic");
|
||||
};
|
||||
|
||||
std::map<std::string, std::string> args = {std::make_pair("verbosity", "3")};
|
||||
ConsoleLogger::Configure(args.cbegin(), args.cend());
|
||||
testing::internal::CaptureStderr();
|
||||
run_monitor();
|
||||
std::string output = testing::internal::GetCapturedStderr();
|
||||
ASSERT_NE(output.find("Monitor"), std::string::npos);
|
||||
|
||||
args = {std::make_pair("verbosity", "2")};
|
||||
ConsoleLogger::Configure(args.cbegin(), args.cend());
|
||||
testing::internal::CaptureStderr();
|
||||
run_monitor();
|
||||
output = testing::internal::GetCapturedStderr();
|
||||
ASSERT_EQ(output.find("Monitor"), std::string::npos);
|
||||
}
|
||||
} // namespace common
|
||||
} // namespace xgboost
|
||||
47
tests/cpp/test_logging.cc
Normal file
47
tests/cpp/test_logging.cc
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <map>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <xgboost/logging.h>
|
||||
|
||||
namespace xgboost {
|
||||
|
||||
TEST(Logging, Basic) {
|
||||
std::map<std::string, std::string> args {};
|
||||
args["verbosity"] = "0"; // silent
|
||||
ConsoleLogger::Configure(args.cbegin(), args.cend());
|
||||
testing::internal::CaptureStderr();
|
||||
std::string output = testing::internal::GetCapturedStderr();
|
||||
ASSERT_EQ(output.length(), 0);
|
||||
|
||||
args["verbosity"] = "3"; // debug
|
||||
ConsoleLogger::Configure(args.cbegin(), args.cend());
|
||||
|
||||
testing::internal::CaptureStderr();
|
||||
LOG(WARNING) << "Test Log Warning.";
|
||||
output = testing::internal::GetCapturedStderr();
|
||||
ASSERT_NE(output.find("WARNING"), std::string::npos);
|
||||
|
||||
testing::internal::CaptureStderr();
|
||||
LOG(INFO) << "Test Log Info";
|
||||
output = testing::internal::GetCapturedStderr();
|
||||
ASSERT_NE(output.find("Test Log Info"), std::string::npos);
|
||||
|
||||
testing::internal::CaptureStderr();
|
||||
LOG(DEBUG) << "Test Log Debug.";
|
||||
output = testing::internal::GetCapturedStderr();
|
||||
ASSERT_NE(output.find("DEBUG"), std::string::npos);
|
||||
|
||||
args["silent"] = "True";
|
||||
ConsoleLogger::Configure(args.cbegin(), args.cend());
|
||||
testing::internal::CaptureStderr();
|
||||
LOG(INFO) << "Test Log Info";
|
||||
output = testing::internal::GetCapturedStderr();
|
||||
ASSERT_EQ(output.length(), 0);
|
||||
|
||||
testing::internal::CaptureStderr();
|
||||
LOG(CONSOLE) << "Test Log Console";
|
||||
output = testing::internal::GetCapturedStderr();
|
||||
ASSERT_NE(output.find("Test Log Console"), std::string::npos);
|
||||
}
|
||||
|
||||
} // namespace xgboost
|
||||
@@ -252,7 +252,7 @@ TEST(GpuHist, EvaluateSplits) {
|
||||
|
||||
// Copy cut matrix to device.
|
||||
DeviceShard<GradientPairPrecise>::DeviceHistCutMatrix cut;
|
||||
shard->ba.Allocate(0, true,
|
||||
shard->ba.Allocate(0,
|
||||
&(shard->cut_.feature_segments), cmat.row_ptr.size(),
|
||||
&(shard->cut_.min_fvalue), cmat.min_val.size(),
|
||||
&(shard->cut_.gidx_fvalue_map), 24,
|
||||
@@ -315,7 +315,6 @@ TEST(GpuHist, ApplySplit) {
|
||||
int constexpr n_cols = 8;
|
||||
|
||||
TrainParam param;
|
||||
param.silent = true;
|
||||
|
||||
// Initialize shard
|
||||
for (size_t i = 0; i < n_cols; ++i) {
|
||||
@@ -330,7 +329,7 @@ TEST(GpuHist, ApplySplit) {
|
||||
shard->node_sum_gradients.resize(3);
|
||||
|
||||
shard->ridx_segments[0] = Segment(0, n_rows);
|
||||
shard->ba.Allocate(0, true, &(shard->ridx), n_rows,
|
||||
shard->ba.Allocate(0, &(shard->ridx), n_rows,
|
||||
&(shard->position), n_rows);
|
||||
shard->row_stride = n_cols;
|
||||
thrust::sequence(shard->ridx.CurrentDVec().tbegin(),
|
||||
@@ -367,8 +366,7 @@ TEST(GpuHist, ApplySplit) {
|
||||
size_t compressed_size_bytes =
|
||||
common::CompressedBufferWriter::CalculateBufferSize(
|
||||
row_stride * n_rows, num_symbols);
|
||||
shard->ba.Allocate(0, param.silent,
|
||||
&(shard->gidx_buffer), compressed_size_bytes);
|
||||
shard->ba.Allocate(0, &(shard->gidx_buffer), compressed_size_bytes);
|
||||
|
||||
common::CompressedBufferWriter wr(num_symbols);
|
||||
std::vector<int> h_gidx (n_rows * row_stride);
|
||||
|
||||
Reference in New Issue
Block a user