Changes for beast logging

This commit is contained in:
Vinnie Falco
2016-05-18 16:07:52 -04:00
parent fa0ef25ffb
commit 3de738429f
14 changed files with 145 additions and 57 deletions

View File

@@ -240,6 +240,8 @@
</ClInclude>
<ClInclude Include="..\..\src\beast\extras\beast\unit_test\detail\const_container.hpp">
</ClInclude>
<ClInclude Include="..\..\src\beast\extras\beast\unit_test\dstream.hpp">
</ClInclude>
<ClInclude Include="..\..\src\beast\extras\beast\unit_test\global_suites.hpp">
</ClInclude>
<ClInclude Include="..\..\src\beast\extras\beast\unit_test\match.hpp">
@@ -1895,6 +1897,8 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\beast\utility\tagged_integer.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\beast\utility\temp_dir.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\beast\utility\test\beast_Journal_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>

View File

@@ -543,6 +543,9 @@
<ClInclude Include="..\..\src\beast\extras\beast\unit_test\detail\const_container.hpp">
<Filter>extras\beast\unit_test\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\src\beast\extras\beast\unit_test\dstream.hpp">
<Filter>extras\beast\unit_test</Filter>
</ClInclude>
<ClInclude Include="..\..\src\beast\extras\beast\unit_test\global_suites.hpp">
<Filter>extras\beast\unit_test</Filter>
</ClInclude>
@@ -2460,6 +2463,9 @@
<ClInclude Include="..\..\src\ripple\beast\utility\tagged_integer.h">
<Filter>ripple\beast\utility</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\beast\utility\temp_dir.h">
<Filter>ripple\beast\utility</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\beast\utility\test\beast_Journal_test.cpp">
<Filter>ripple\beast\utility\test</Filter>
</ClCompile>

View File

@@ -40,7 +40,7 @@
#include <ripple/beast/core/Time.h>
#include <ripple/beast/unit_test.h>
#include <ripple/beast/utility/Debug.h>
#include <beast/unit_test/debug_ostream.hpp>
#include <beast/unit_test/dstream.hpp>
#include <google/protobuf/stubs/common.h>
#include <boost/program_options.hpp>
#include <cstdlib>
@@ -201,8 +201,8 @@ static int runUnitTests(
std::string const& argument)
{
using namespace beast::unit_test;
beast::debug_ostream stream;
reporter r (stream);
beast::unit_test::dstream dlog;
reporter r(dlog);
r.arg(argument);
bool const failed (r.run_each_if (
global_suites(), match_auto (pattern)));

View File

@@ -18,7 +18,7 @@
//==============================================================================
#include <ripple/beast/nudb/test/common.h>
#include <beast/core/detail/temp_dir.hpp>
#include <ripple/beast/utility/temp_dir.h>
#include <ripple/beast/xor_shift_engine.h>
#include <ripple/beast/unit_test.h>
#include <cmath>
@@ -96,9 +96,9 @@ public:
N = 100000
};
testcase (abort_on_fail);
testcase (beast::unit_test::abort_on_fail);
beast::detail::temp_dir tempDir;
beast::temp_dir tempDir;
do_test (N, tempDir.path());
}
};

View File

@@ -20,7 +20,7 @@
#include <ripple/beast/nudb/test/common.h>
#include <ripple/beast/xor_shift_engine.h>
#include <ripple/beast/unit_test.h>
#include <beast/core/detail/temp_dir.hpp>
#include <ripple/beast/utility/temp_dir.h>
#include <cmath>
#include <cstring>
#include <memory>
@@ -117,7 +117,7 @@ public:
{
testcase << count << " inserts";
beast::detail::temp_dir tempDir;
beast::temp_dir tempDir;
auto const path = tempDir.path();
for (std::size_t n = 1;;++n)

View File

@@ -18,7 +18,7 @@
//==============================================================================
#include <ripple/beast/nudb/test/common.h>
#include <beast/core/detail/temp_dir.hpp>
#include <ripple/beast/utility/temp_dir.h>
#include <ripple/beast/xor_shift_engine.h>
#include <ripple/beast/unit_test.h>
#include <cmath>
@@ -43,8 +43,8 @@ public:
do_test (std::size_t N,
std::size_t block_size, float load_factor)
{
testcase (abort_on_fail);
beast::detail::temp_dir tempDir;
testcase (beast::unit_test::abort_on_fail);
beast::temp_dir tempDir;
auto const dp = tempDir.file ("nudb.dat");
auto const kp = tempDir.file ("nudb.key");

View File

@@ -242,7 +242,7 @@ public:
void
run() override
{
testcase(abort_on_fail) << "verify " << arg();
testcase(beast::unit_test::abort_on_fail) << "verify " << arg();
if (arg().empty())
return fail("missing unit test argument");
do_verify(arg());
@@ -270,7 +270,7 @@ public:
void
run() override
{
testcase(abort_on_fail) << "verify_fast " << arg();
testcase(beast::unit_test::abort_on_fail) << "verify_fast " << arg();
if (arg().empty())
return fail("missing unit test argument");
do_verify(arg());

View File

@@ -209,47 +209,43 @@ num (T t)
return s2;
}
template <class Log>
inline
void
print (Log log,
print(std::ostream& log,
beast::nudb::verify_info const& info)
{
log << "avg_fetch: " << std::fixed << std::setprecision(3) <<
info.avg_fetch;
log << "waste: " << std::fixed << std::setprecision(3) <<
info.waste * 100 << "%";
log << "overhead: " << std::fixed << std::setprecision(1) <<
info.overhead * 100 << "%";
log << "actual_load: " << std::fixed << std::setprecision(0) <<
info.actual_load * 100 << "%";
log << "version: " << num(info.version);
log << "uid: " << std::showbase << std::hex << info.uid;
log << "appnum: " << info.appnum;
log << "key_size: " << num(info.key_size);
log << "salt: " << std::showbase << std::hex << info.salt;
log << "pepper: " << std::showbase << std::hex << info.pepper;
log << "block_size: " << num(info.block_size);
log << "bucket_size: " << num(info.bucket_size);
log << "load_factor: " << std::fixed << std::setprecision(0) <<
info.load_factor * 100 << "%";
log << "capacity: " << num(info.capacity);
log << "buckets: " << num(info.buckets);
log << "key_count: " << num(info.key_count);
log << "value_count: " << num(info.value_count);
log << "value_bytes: " << num(info.value_bytes);
log << "spill_count: " << num(info.spill_count);
log << "spill_count_tot: " << num(info.spill_count_tot);
log << "spill_bytes: " << num(info.spill_bytes);
log << "spill_bytes_tot: " << num(info.spill_bytes_tot);
log << "key_file_size: " << num(info.key_file_size);
log << "dat_file_size: " << num(info.dat_file_size);
log <<
"avg_fetch: " << std::fixed << std::setprecision(3) << info.avg_fetch << '\n' <<
"waste: " << std::fixed << std::setprecision(3) << info.waste * 100 << "%\n" <<
"overhead: " << std::fixed << std::setprecision(1) << info.overhead * 100 << "%\n" <<
"actual_load: " << std::fixed << std::setprecision(0) << info.actual_load * 100 << "%\n" <<
"version: " << num(info.version) << '\n' <<
"uid: " << std::showbase << std::hex << info.uid << '\n' <<
"appnum: " << info.appnum << '\n' <<
"key_size: " << num(info.key_size) << '\n' <<
"salt: " << std::showbase << std::hex << info.salt << '\n' <<
"pepper: " << std::showbase << std::hex << info.pepper << '\n' <<
"block_size: " << num(info.block_size) << '\n' <<
"bucket_size: " << num(info.bucket_size) << '\n' <<
"load_factor: " << std::fixed << std::setprecision(0) << info.load_factor * 100 << "%\n" <<
"capacity: " << num(info.capacity) << '\n' <<
"buckets: " << num(info.buckets) << '\n' <<
"key_count: " << num(info.key_count) << '\n' <<
"value_count: " << num(info.value_count) << '\n' <<
"value_bytes: " << num(info.value_bytes) << '\n' <<
"spill_count: " << num(info.spill_count) << '\n' <<
"spill_count_tot: " << num(info.spill_count_tot) << '\n' <<
"spill_bytes: " << num(info.spill_bytes) << '\n' <<
"spill_bytes_tot: " << num(info.spill_bytes_tot) << '\n' <<
"key_file_size: " << num(info.key_file_size) << '\n' <<
"dat_file_size: " << num(info.dat_file_size) << std::endl;
std::string s;
for (int i = 0; i < info.hist.size(); ++i)
s += (i==0) ?
std::to_string(info.hist[i]) :
(", " + std::to_string(info.hist[i]));
log << "hist: " << s;
log << "hist: " << s << std::endl;
}
} // test

View File

@@ -21,7 +21,6 @@
#define BEAST_UNIT_TEST_H_INCLUDED
#include <beast/unit_test/amount.hpp>
#include <beast/unit_test/print.hpp>
#include <beast/unit_test/global_suites.hpp>
#include <beast/unit_test/match.hpp>
#include <beast/unit_test/recorder.hpp>

View File

@@ -0,0 +1,83 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_UTILITY_TEMP_DIR_H_INCLUDED
#define BEAST_UTILITY_TEMP_DIR_H_INCLUDED
#include <boost/filesystem.hpp>
#include <string>
namespace beast {
/** RAII temporary directory.
The directory and all its contents are deleted when
the instance of `temp_dir` is destroyed.
*/
class temp_dir
{
boost::filesystem::path path_;
public:
#if ! GENERATING_DOCS
temp_dir(const temp_dir&) = delete;
temp_dir& operator=(const temp_dir&) = delete;
#endif
/// Construct a temporary directory.
temp_dir()
{
auto const dir =
boost::filesystem::temp_directory_path();
do
{
path_ =
dir / boost::filesystem::unique_path();
}
while(boost::filesystem::exists(path_));
boost::filesystem::create_directory (path_);
}
/// Destroy a temporary directory.
~temp_dir()
{
boost::filesystem::remove_all (path_);
}
/// Get the native path for the temporary directory
std::string
path() const
{
return path_.string();
}
/** Get the native path for the a file.
The file does not need to exist.
*/
std::string
file(std::string const& name) const
{
return (path_ / name).string();
}
};
} // beast
#endif

View File

@@ -21,7 +21,7 @@
#include <ripple/nodestore/tests/Base.test.h>
#include <ripple/nodestore/DummyScheduler.h>
#include <ripple/nodestore/Manager.h>
#include <beast/core/detail/temp_dir.hpp>
#include <ripple/beast/utility/temp_dir.h>
#include <algorithm>
namespace ripple {
@@ -42,7 +42,7 @@ public:
testcase ("Backend type=" + type);
Section params;
beast::detail::temp_dir tempDir;
beast::temp_dir tempDir;
params.set ("type", type);
params.set ("path", tempDir.path());

View File

@@ -21,7 +21,7 @@
#include <ripple/nodestore/tests/Base.test.h>
#include <ripple/nodestore/DummyScheduler.h>
#include <ripple/nodestore/Manager.h>
#include <beast/core/detail/temp_dir.hpp>
#include <ripple/beast/utility/temp_dir.h>
#include <algorithm>
namespace ripple {
@@ -35,7 +35,7 @@ public:
{
DummyScheduler scheduler;
beast::detail::temp_dir node_db;
beast::temp_dir node_db;
Section srcParams;
srcParams.set ("type", srcBackendType);
srcParams.set ("path", node_db.path());
@@ -61,7 +61,7 @@ public:
"test", scheduler, j, 2, srcParams);
// Set up the destination database
beast::detail::temp_dir dest_db;
beast::temp_dir dest_db;
Section destParams;
destParams.set ("type", destBackendType);
destParams.set ("path", dest_db.path());
@@ -98,7 +98,7 @@ public:
testcase (s);
beast::detail::temp_dir node_db;
beast::temp_dir node_db;
Section nodeParams;
nodeParams.set ("type", type);
nodeParams.set ("path", node_db.path());

View File

@@ -23,7 +23,7 @@
#include <ripple/nodestore/Manager.h>
#include <ripple/basics/BasicConfig.h>
#include <ripple/unity/rocksdb.h>
#include <beast/core/detail/temp_dir.hpp>
#include <ripple/beast/utility/temp_dir.h>
#include <ripple/beast/xor_shift_engine.h>
#include <ripple/beast/unit_test.h>
#include <beast/unit_test/thread.hpp>
@@ -679,7 +679,7 @@ public:
params.threads = threads;
for (auto i = default_repeat; i--;)
{
beast::detail::temp_dir tempDir;
beast::temp_dir tempDir;
Section config = parse(config_string);
config.set ("path", tempDir.path());
std::stringstream ss;
@@ -697,7 +697,7 @@ public:
void
run() override
{
testcase ("Timing", suite::abort_on_fail);
testcase ("Timing", beast::unit_test::abort_on_fail);
/* Parameters:

View File

@@ -301,7 +301,7 @@ public:
void
run() override
{
testcase(abort_on_fail) << arg();
testcase(beast::unit_test::abort_on_fail) << arg();
using namespace beast::nudb;
using namespace beast::nudb::detail;
@@ -573,7 +573,7 @@ public:
void
run() override
{
testcase(abort_on_fail) << arg();
testcase(beast::unit_test::abort_on_fail) << arg();
using namespace beast::nudb;
using namespace beast::nudb::detail;