Refactor logging, improve error handling workflow, clang-format. (#3385)

This commit is contained in:
Daniel Patterson
2016-12-06 12:30:46 -08:00
committed by GitHub
parent 6f4c6e84ae
commit 468d8c0031
62 changed files with 1778 additions and 1607 deletions
+55 -51
View File
@@ -2,9 +2,10 @@
#include "util/coordinate_calculation.hpp"
#include "util/dynamic_graph.hpp"
#include "util/exception.hpp"
#include "util/exception_utils.hpp"
#include "util/fingerprint.hpp"
#include "util/graph_loader.hpp"
#include "util/simple_logger.hpp"
#include "util/log.hpp"
#include "util/static_graph.hpp"
#include "util/typedefs.hpp"
@@ -102,7 +103,7 @@ int main(int argc, char *argv[])
// enable logging
if (argc < 2)
{
osrm::util::SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0] << " <osrm>";
osrm::util::Log(logWARNING) << "usage:\n" << argv[0] << " <osrm>";
return EXIT_FAILURE;
}
@@ -115,14 +116,12 @@ int main(int argc, char *argv[])
graph_edge_list.clear();
graph_edge_list.shrink_to_fit();
osrm::util::SimpleLogger().Write() << "Starting SCC graph traversal";
osrm::util::Log() << "Starting SCC graph traversal";
auto tarjan = std::make_unique<osrm::extractor::TarjanSCC<osrm::tools::TarjanGraph>>(graph);
tarjan->Run();
osrm::util::SimpleLogger().Write() << "identified: " << tarjan->GetNumberOfComponents()
<< " many components";
osrm::util::SimpleLogger().Write() << "identified " << tarjan->GetSizeOneCount()
<< " size 1 SCCs";
osrm::util::Log() << "identified: " << tarjan->GetNumberOfComponents() << " many components";
osrm::util::Log() << "identified " << tarjan->GetSizeOneCount() << " size 1 SCCs";
// output
TIMER_START(SCC_RUN_SETUP);
@@ -138,13 +137,13 @@ int main(int argc, char *argv[])
auto *po_driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(psz_driver_name);
if (nullptr == po_driver)
{
throw osrm::util::exception("ESRI Shapefile driver not available");
throw osrm::util::exception("ESRI Shapefile driver not available" + SOURCE_REF);
}
auto *po_datasource = po_driver->CreateDataSource("component.shp", nullptr);
if (nullptr == po_datasource)
{
throw osrm::util::exception("Creation of output file failed");
throw osrm::util::exception("Creation of output file failed" + SOURCE_REF);
}
auto *po_srs = new OGRSpatialReference();
@@ -154,55 +153,62 @@ int main(int argc, char *argv[])
if (nullptr == po_layer)
{
throw osrm::util::exception("Layer creation failed.");
throw osrm::util::exception("Layer creation failed." + SOURCE_REF);
}
TIMER_STOP(SCC_RUN_SETUP);
osrm::util::SimpleLogger().Write() << "shapefile setup took "
<< TIMER_MSEC(SCC_RUN_SETUP) / 1000. << "s";
osrm::util::Log() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP) / 1000. << "s";
uint64_t total_network_length = 0;
osrm::util::Percent percentage(graph->GetNumberOfNodes());
TIMER_START(SCC_OUTPUT);
for (const NodeID source : osrm::util::irange(0u, graph->GetNumberOfNodes()))
uint64_t total_network_length = 0;
{
percentage.PrintIncrement();
for (const auto current_edge : graph->GetAdjacentEdgeRange(source))
osrm::util::UnbufferedLog log;
log << "Constructing geometry ";
osrm::util::Percent percentage(log, graph->GetNumberOfNodes());
for (const NodeID source : osrm::util::irange(0u, graph->GetNumberOfNodes()))
{
const auto target = graph->GetTarget(current_edge);
if (source < target || SPECIAL_EDGEID == graph->FindEdge(target, source))
percentage.PrintIncrement();
for (const auto current_edge : graph->GetAdjacentEdgeRange(source))
{
total_network_length +=
100 * osrm::util::coordinate_calculation::greatCircleDistance(
coordinate_list[source], coordinate_list[target]);
const auto target = graph->GetTarget(current_edge);
BOOST_ASSERT(current_edge != SPECIAL_EDGEID);
BOOST_ASSERT(source != SPECIAL_NODEID);
BOOST_ASSERT(target != SPECIAL_NODEID);
const unsigned size_of_containing_component =
std::min(tarjan->GetComponentSize(tarjan->GetComponentID(source)),
tarjan->GetComponentSize(tarjan->GetComponentID(target)));
// edges that end on bollard nodes may actually be in two distinct components
if (size_of_containing_component < 1000)
if (source < target || SPECIAL_EDGEID == graph->FindEdge(target, source))
{
OGRLineString line_string;
line_string.addPoint(
static_cast<double>(osrm::util::toFloating(coordinate_list[source].lon)),
static_cast<double>(osrm::util::toFloating(coordinate_list[source].lat)));
line_string.addPoint(
static_cast<double>(osrm::util::toFloating(coordinate_list[target].lon)),
static_cast<double>(osrm::util::toFloating(coordinate_list[target].lat)));
total_network_length +=
100 * osrm::util::coordinate_calculation::greatCircleDistance(
coordinate_list[source], coordinate_list[target]);
OGRFeature *po_feature = OGRFeature::CreateFeature(po_layer->GetLayerDefn());
BOOST_ASSERT(current_edge != SPECIAL_EDGEID);
BOOST_ASSERT(source != SPECIAL_NODEID);
BOOST_ASSERT(target != SPECIAL_NODEID);
po_feature->SetGeometry(&line_string);
if (OGRERR_NONE != po_layer->CreateFeature(po_feature))
const unsigned size_of_containing_component =
std::min(tarjan->GetComponentSize(tarjan->GetComponentID(source)),
tarjan->GetComponentSize(tarjan->GetComponentID(target)));
// edges that end on bollard nodes may actually be in two distinct components
if (size_of_containing_component < 1000)
{
throw osrm::util::exception("Failed to create feature in shapefile.");
OGRLineString line_string;
line_string.addPoint(static_cast<double>(osrm::util::toFloating(
coordinate_list[source].lon)),
static_cast<double>(osrm::util::toFloating(
coordinate_list[source].lat)));
line_string.addPoint(static_cast<double>(osrm::util::toFloating(
coordinate_list[target].lon)),
static_cast<double>(osrm::util::toFloating(
coordinate_list[target].lat)));
OGRFeature *po_feature =
OGRFeature::CreateFeature(po_layer->GetLayerDefn());
po_feature->SetGeometry(&line_string);
if (OGRERR_NONE != po_layer->CreateFeature(po_feature))
{
throw osrm::util::exception("Failed to create feature in shapefile." +
SOURCE_REF);
}
OGRFeature::DestroyFeature(po_feature);
}
OGRFeature::DestroyFeature(po_feature);
}
}
}
@@ -210,13 +216,11 @@ int main(int argc, char *argv[])
OGRSpatialReference::DestroySpatialReference(po_srs);
OGRDataSource::DestroyDataSource(po_datasource);
TIMER_STOP(SCC_OUTPUT);
osrm::util::SimpleLogger().Write()
<< "generating output took: " << TIMER_MSEC(SCC_OUTPUT) / 1000. << "s";
osrm::util::Log() << "generating output took: " << TIMER_MSEC(SCC_OUTPUT) / 1000. << "s";
osrm::util::SimpleLogger().Write()
<< "total network distance: " << static_cast<uint64_t>(total_network_length / 100 / 1000.)
<< " km";
osrm::util::Log() << "total network distance: "
<< static_cast<uint64_t>(total_network_length / 100 / 1000.) << " km";
osrm::util::SimpleLogger().Write() << "finished component analysis";
osrm::util::Log() << "finished component analysis";
return EXIT_SUCCESS;
}
+16 -17
View File
@@ -1,6 +1,7 @@
#include "contractor/contractor.hpp"
#include "contractor/contractor_config.hpp"
#include "util/simple_logger.hpp"
#include "util/exception.hpp"
#include "util/log.hpp"
#include "util/version.hpp"
#include <boost/filesystem.hpp>
@@ -92,19 +93,19 @@ return_code parseArguments(int argc, char *argv[], contractor::ContractorConfig
}
catch (const boost::program_options::error &e)
{
util::SimpleLogger().Write(logWARNING) << "[error] " << e.what();
util::Log(logERROR) << e.what();
return return_code::fail;
}
if (option_variables.count("version"))
{
util::SimpleLogger().Write() << OSRM_VERSION;
std::cout << OSRM_VERSION << std::endl;
return return_code::exit;
}
if (option_variables.count("help"))
{
util::SimpleLogger().Write() << visible_options;
std::cout << visible_options;
return return_code::exit;
}
@@ -112,7 +113,7 @@ return_code parseArguments(int argc, char *argv[], contractor::ContractorConfig
if (!option_variables.count("input"))
{
util::SimpleLogger().Write() << visible_options;
std::cout << visible_options;
return return_code::fail;
}
@@ -121,6 +122,7 @@ return_code parseArguments(int argc, char *argv[], contractor::ContractorConfig
int main(int argc, char *argv[]) try
{
util::LogPolicy::GetInstance().Unmute();
contractor::ContractorConfig contractor_config;
@@ -140,7 +142,7 @@ int main(int argc, char *argv[]) try
if (1 > contractor_config.requested_num_threads)
{
util::SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
util::Log(logERROR) << "Number of threads must be 1 or larger";
return EXIT_FAILURE;
}
@@ -148,21 +150,19 @@ int main(int argc, char *argv[]) try
if (recommended_num_threads != contractor_config.requested_num_threads)
{
util::SimpleLogger().Write(logWARNING)
<< "The recommended number of threads is " << recommended_num_threads
<< "! This setting may have performance side-effects.";
util::Log(logWARNING) << "The recommended number of threads is " << recommended_num_threads
<< "! This setting may have performance side-effects.";
}
if (!boost::filesystem::is_regular_file(contractor_config.osrm_input_path))
{
util::SimpleLogger().Write(logWARNING)
<< "Input file " << contractor_config.osrm_input_path.string() << " not found!";
util::Log(logERROR) << "Input file " << contractor_config.osrm_input_path.string()
<< " not found!";
return EXIT_FAILURE;
}
util::SimpleLogger().Write() << "Input file: "
<< contractor_config.osrm_input_path.filename().string();
util::SimpleLogger().Write() << "Threads: " << contractor_config.requested_num_threads;
util::Log() << "Input file: " << contractor_config.osrm_input_path.filename().string();
util::Log() << "Threads: " << contractor_config.requested_num_threads;
tbb::task_scheduler_init init(contractor_config.requested_num_threads);
@@ -170,8 +170,7 @@ int main(int argc, char *argv[]) try
}
catch (const std::bad_alloc &e)
{
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
util::SimpleLogger().Write(logWARNING)
<< "Please provide more memory or consider using a larger swapfile";
util::Log(logERROR) << "[exception] " << e.what();
util::Log(logERROR) << "Please provide more memory or consider using a larger swapfile";
return EXIT_FAILURE;
}
+13 -14
View File
@@ -1,7 +1,7 @@
#include "extractor/extractor.hpp"
#include "extractor/extractor_config.hpp"
#include "extractor/scripting_environment_lua.hpp"
#include "util/simple_logger.hpp"
#include "util/log.hpp"
#include "util/version.hpp"
#include <tbb/task_scheduler_init.h>
@@ -84,19 +84,19 @@ return_code parseArguments(int argc, char *argv[], extractor::ExtractorConfig &e
}
catch (const boost::program_options::error &e)
{
util::SimpleLogger().Write(logWARNING) << "[error] " << e.what();
util::Log(logERROR) << e.what();
return return_code::fail;
}
if (option_variables.count("version"))
{
util::SimpleLogger().Write() << OSRM_VERSION;
std::cout << OSRM_VERSION << std::endl;
return return_code::exit;
}
if (option_variables.count("help"))
{
util::SimpleLogger().Write() << visible_options;
std::cout << visible_options;
return return_code::exit;
}
@@ -104,7 +104,7 @@ return_code parseArguments(int argc, char *argv[], extractor::ExtractorConfig &e
if (!option_variables.count("input"))
{
util::SimpleLogger().Write() << visible_options;
std::cout << visible_options;
return return_code::exit;
}
@@ -132,21 +132,21 @@ int main(int argc, char *argv[]) try
if (1 > extractor_config.requested_num_threads)
{
util::SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
util::Log(logERROR) << "Number of threads must be 1 or larger";
return EXIT_FAILURE;
}
if (!boost::filesystem::is_regular_file(extractor_config.input_path))
{
util::SimpleLogger().Write(logWARNING)
<< "Input file " << extractor_config.input_path.string() << " not found!";
util::Log(logERROR) << "Input file " << extractor_config.input_path.string()
<< " not found!";
return EXIT_FAILURE;
}
if (!boost::filesystem::is_regular_file(extractor_config.profile_path))
{
util::SimpleLogger().Write(logWARNING)
<< "Profile " << extractor_config.profile_path.string() << " not found!";
util::Log(logERROR) << "Profile " << extractor_config.profile_path.string()
<< " not found!";
return EXIT_FAILURE;
}
@@ -157,8 +157,7 @@ int main(int argc, char *argv[]) try
}
catch (const std::bad_alloc &e)
{
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
util::SimpleLogger().Write(logWARNING)
<< "Please provide more memory or consider using a larger swapfile";
util::Log(logERROR) << "[exception] " << e.what();
util::Log(logERROR) << "Please provide more memory or consider using a larger swapfile";
return EXIT_FAILURE;
}
}
+51 -53
View File
@@ -1,5 +1,6 @@
#include "util/exception.hpp"
#include "util/simple_logger.hpp"
#include "util/exception_utils.hpp"
#include "util/log.hpp"
#include "util/timing_util.hpp"
#include <boost/filesystem.hpp>
@@ -53,24 +54,24 @@ int main(int argc, char *argv[])
{
#ifdef __FreeBSD__
osrm::util::SimpleLogger().Write() << "Not supported on FreeBSD";
osrm::util::Log() << "Not supported on FreeBSD";
return 0;
#endif
#ifdef _WIN32
osrm::util::SimpleLogger().Write() << "Not supported on Windows";
osrm::util::Log() << "Not supported on Windows";
return 0;
#else
osrm::util::LogPolicy::GetInstance().Unmute();
if (1 == argc)
{
osrm::util::SimpleLogger().Write(logWARNING) << "usage: " << argv[0] << " /path/on/device";
osrm::util::Log(logWARNING) << "usage: " << argv[0] << " /path/on/device";
return -1;
}
test_path = boost::filesystem::path(argv[1]);
test_path /= "osrm.tst";
osrm::util::SimpleLogger().Write(logDEBUG) << "temporary file: " << test_path.string();
osrm::util::Log(logDEBUG) << "temporary file: " << test_path.string();
// create files for testing
if (2 == argc)
@@ -78,7 +79,8 @@ int main(int argc, char *argv[])
// create file to test
if (boost::filesystem::exists(test_path))
{
throw osrm::util::exception("Data file already exists");
throw osrm::util::exception("Data file already exists: " + test_path.string() +
SOURCE_REF);
}
int *random_array = new int[osrm::tools::NUMBER_OF_ELEMENTS];
@@ -97,34 +99,33 @@ int main(int argc, char *argv[])
open(test_path.string().c_str(), O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, S_IRWXU);
if (-1 == file_desc)
{
throw osrm::util::exception("Could not open random data file");
throw osrm::util::exception("Could not open random data file" + test_path.string() +
SOURCE_REF);
}
TIMER_START(write_1gb);
int ret =
write(file_desc, random_array, osrm::tools::NUMBER_OF_ELEMENTS * sizeof(unsigned));
if (0 > ret)
{
throw osrm::util::exception("could not write random data file");
throw osrm::util::exception("could not write random data file" + test_path.string() +
SOURCE_REF);
}
TIMER_STOP(write_1gb);
close(file_desc);
#endif
delete[] random_array;
osrm::util::SimpleLogger().Write(logDEBUG) << "writing raw 1GB took "
<< TIMER_SEC(write_1gb) << "s";
osrm::util::SimpleLogger().Write() << "raw write performance: " << std::setprecision(5)
<< std::fixed << 1024 * 1024 / TIMER_SEC(write_1gb)
<< "MB/sec";
osrm::util::Log(logDEBUG) << "writing raw 1GB took " << TIMER_SEC(write_1gb) << "s";
osrm::util::Log() << "raw write performance: " << std::setprecision(5) << std::fixed
<< 1024 * 1024 / TIMER_SEC(write_1gb) << "MB/sec";
osrm::util::SimpleLogger().Write(logDEBUG)
<< "finished creation of random data. Flush disk cache now!";
osrm::util::Log(logDEBUG) << "finished creation of random data. Flush disk cache now!";
}
else
{
// Run Non-Cached I/O benchmarks
if (!boost::filesystem::exists(test_path))
{
throw osrm::util::exception("data file does not exist");
throw osrm::util::exception("data file does not exist" + SOURCE_REF);
}
// volatiles do not get optimized
@@ -143,7 +144,7 @@ int main(int argc, char *argv[])
int file_desc = open(test_path.string().c_str(), O_RDONLY | O_DIRECT | O_SYNC);
if (-1 == file_desc)
{
osrm::util::SimpleLogger().Write(logDEBUG) << "opened, error: " << strerror(errno);
osrm::util::Log(logDEBUG) << "opened, error: " << strerror(errno);
return -1;
}
char *raw_array = (char *)memalign(512, osrm::tools::NUMBER_OF_ELEMENTS * sizeof(unsigned));
@@ -156,22 +157,19 @@ int main(int argc, char *argv[])
#endif
#ifdef __linux__
int ret = read(file_desc, raw_array, osrm::tools::NUMBER_OF_ELEMENTS * sizeof(unsigned));
osrm::util::SimpleLogger().Write(logDEBUG) << "read " << ret
<< " bytes, error: " << strerror(errno);
osrm::util::Log(logDEBUG) << "read " << ret << " bytes, error: " << strerror(errno);
close(file_desc);
file_desc = open(test_path.string().c_str(), O_RDONLY | O_DIRECT | O_SYNC);
osrm::util::SimpleLogger().Write(logDEBUG) << "opened, error: " << strerror(errno);
osrm::util::Log(logDEBUG) << "opened, error: " << strerror(errno);
#endif
TIMER_STOP(read_1gb);
osrm::util::SimpleLogger().Write(logDEBUG) << "reading raw 1GB took " << TIMER_SEC(read_1gb)
<< "s";
osrm::util::SimpleLogger().Write() << "raw read performance: " << std::setprecision(5)
<< std::fixed << 1024 * 1024 / TIMER_SEC(read_1gb)
<< "MB/sec";
osrm::util::Log(logDEBUG) << "reading raw 1GB took " << TIMER_SEC(read_1gb) << "s";
osrm::util::Log() << "raw read performance: " << std::setprecision(5) << std::fixed
<< 1024 * 1024 / TIMER_SEC(read_1gb) << "MB/sec";
std::vector<double> timing_results_raw_random;
osrm::util::SimpleLogger().Write(logDEBUG) << "running 1000 random I/Os of 4KB";
osrm::util::Log(logDEBUG) << "running 1000 random I/Os of 4KB";
#ifdef __APPLE__
fseek(fd, 0, SEEK_SET);
@@ -206,21 +204,21 @@ int main(int argc, char *argv[])
TIMER_STOP(random_access);
if (((off_t)-1) == ret1)
{
osrm::util::SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
osrm::util::SimpleLogger().Write(logWARNING) << "seek error " << strerror(errno);
throw osrm::util::exception("seek error");
osrm::util::Log(logWARNING) << "offset: " << current_offset;
osrm::util::Log(logWARNING) << "seek error " << strerror(errno);
throw osrm::util::exception("seek error" + SOURCE_REF);
}
if (-1 == ret2)
{
osrm::util::SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
osrm::util::SimpleLogger().Write(logWARNING) << "read error " << strerror(errno);
throw osrm::util::exception("read error");
osrm::util::Log(logWARNING) << "offset: " << current_offset;
osrm::util::Log(logWARNING) << "read error " << strerror(errno);
throw osrm::util::exception("read error" + SOURCE_REF);
}
timing_results_raw_random.push_back(TIMER_SEC(random_access));
}
// Do statistics
osrm::util::SimpleLogger().Write(logDEBUG) << "running raw random I/O statistics";
osrm::util::Log(logDEBUG) << "running raw random I/O statistics";
std::ofstream random_csv("random.csv", std::ios::trunc);
for (unsigned i = 0; i < timing_results_raw_random.size(); ++i)
{
@@ -228,12 +226,12 @@ int main(int argc, char *argv[])
}
osrm::tools::runStatistics(timing_results_raw_random, stats);
osrm::util::SimpleLogger().Write() << "raw random I/O: " << std::setprecision(5)
<< std::fixed << "min: " << stats.min << "ms, "
<< "mean: " << stats.mean << "ms, "
<< "med: " << stats.med << "ms, "
<< "max: " << stats.max << "ms, "
<< "dev: " << stats.dev << "ms";
osrm::util::Log() << "raw random I/O: " << std::setprecision(5) << std::fixed
<< "min: " << stats.min << "ms, "
<< "mean: " << stats.mean << "ms, "
<< "med: " << stats.med << "ms, "
<< "max: " << stats.max << "ms, "
<< "dev: " << stats.dev << "ms";
std::vector<double> timing_results_raw_seq;
#ifdef __APPLE__
@@ -266,15 +264,15 @@ int main(int argc, char *argv[])
TIMER_STOP(read_every_100);
if (((off_t)-1) == ret1)
{
osrm::util::SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
osrm::util::SimpleLogger().Write(logWARNING) << "seek error " << strerror(errno);
throw osrm::util::exception("seek error");
osrm::util::Log(logWARNING) << "offset: " << current_offset;
osrm::util::Log(logWARNING) << "seek error " << strerror(errno);
throw osrm::util::exception("seek error" + SOURCE_REF);
}
if (-1 == ret2)
{
osrm::util::SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
osrm::util::SimpleLogger().Write(logWARNING) << "read error " << strerror(errno);
throw osrm::util::exception("read error");
osrm::util::Log(logWARNING) << "offset: " << current_offset;
osrm::util::Log(logWARNING) << "read error " << strerror(errno);
throw osrm::util::exception("read error" + SOURCE_REF);
}
timing_results_raw_seq.push_back(TIMER_SEC(read_every_100));
}
@@ -288,7 +286,7 @@ int main(int argc, char *argv[])
close(file_desc);
#endif
// Do statistics
osrm::util::SimpleLogger().Write(logDEBUG) << "running sequential I/O statistics";
osrm::util::Log(logDEBUG) << "running sequential I/O statistics";
// print simple statistics: min, max, median, variance
std::ofstream seq_csv("sequential.csv", std::ios::trunc);
for (unsigned i = 0; i < timing_results_raw_seq.size(); ++i)
@@ -296,17 +294,17 @@ int main(int argc, char *argv[])
seq_csv << i << ", " << timing_results_raw_seq[i] << std::endl;
}
osrm::tools::runStatistics(timing_results_raw_seq, stats);
osrm::util::SimpleLogger().Write() << "raw sequential I/O: " << std::setprecision(5)
<< std::fixed << "min: " << stats.min << "ms, "
<< "mean: " << stats.mean << "ms, "
<< "med: " << stats.med << "ms, "
<< "max: " << stats.max << "ms, "
<< "dev: " << stats.dev << "ms";
osrm::util::Log() << "raw sequential I/O: " << std::setprecision(5) << std::fixed
<< "min: " << stats.min << "ms, "
<< "mean: " << stats.mean << "ms, "
<< "med: " << stats.med << "ms, "
<< "max: " << stats.max << "ms, "
<< "dev: " << stats.dev << "ms";
if (boost::filesystem::exists(test_path))
{
boost::filesystem::remove(test_path);
osrm::util::SimpleLogger().Write(logDEBUG) << "removing temporary files";
osrm::util::Log(logDEBUG) << "removing temporary files";
}
}
return EXIT_SUCCESS;
+37 -49
View File
@@ -1,5 +1,5 @@
#include "server/server.hpp"
#include "util/simple_logger.hpp"
#include "util/log.hpp"
#include "util/version.hpp"
#include "osrm/engine_config.hpp"
@@ -136,19 +136,19 @@ inline unsigned generateServerProgramOptions(const int argc,
}
catch (const boost::program_options::error &e)
{
util::SimpleLogger().Write(logWARNING) << "[error] " << e.what();
util::Log(logERROR) << e.what();
return INIT_FAILED;
}
if (option_variables.count("version"))
{
util::SimpleLogger().Write() << OSRM_VERSION;
std::cout << OSRM_VERSION << std::endl;
return INIT_OK_DO_NOT_START_ENGINE;
}
if (option_variables.count("help"))
{
util::SimpleLogger().Write() << visible_options;
std::cout << visible_options;
return INIT_OK_DO_NOT_START_ENGINE;
}
@@ -164,11 +164,10 @@ inline unsigned generateServerProgramOptions(const int argc,
}
else if (use_shared_memory && option_variables.count("base"))
{
util::SimpleLogger().Write(logWARNING)
<< "Shared memory settings conflict with path settings.";
util::Log(logWARNING) << "Shared memory settings conflict with path settings.";
}
util::SimpleLogger().Write() << visible_options;
std::cout << visible_options;
return INIT_OK_DO_NOT_START_ENGINE;
}
@@ -211,69 +210,59 @@ int main(int argc, const char *argv[]) try
{
if (base_path.empty() != config.use_shared_memory)
{
util::SimpleLogger().Write(logWARNING) << "Path settings and shared memory conflicts.";
util::Log(logWARNING) << "Path settings and shared memory conflicts.";
}
else
{
if (!boost::filesystem::is_regular_file(config.storage_config.ram_index_path))
{
util::SimpleLogger().Write(logWARNING) << config.storage_config.ram_index_path
<< " is not found";
util::Log(logWARNING) << config.storage_config.ram_index_path << " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.file_index_path))
{
util::SimpleLogger().Write(logWARNING) << config.storage_config.file_index_path
<< " is not found";
util::Log(logWARNING) << config.storage_config.file_index_path << " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.hsgr_data_path))
{
util::SimpleLogger().Write(logWARNING) << config.storage_config.hsgr_data_path
<< " is not found";
util::Log(logWARNING) << config.storage_config.hsgr_data_path << " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.nodes_data_path))
{
util::SimpleLogger().Write(logWARNING) << config.storage_config.nodes_data_path
<< " is not found";
util::Log(logWARNING) << config.storage_config.nodes_data_path << " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.edges_data_path))
{
util::SimpleLogger().Write(logWARNING) << config.storage_config.edges_data_path
<< " is not found";
util::Log(logWARNING) << config.storage_config.edges_data_path << " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.core_data_path))
{
util::SimpleLogger().Write(logWARNING) << config.storage_config.core_data_path
<< " is not found";
util::Log(logWARNING) << config.storage_config.core_data_path << " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.geometries_path))
{
util::SimpleLogger().Write(logWARNING) << config.storage_config.geometries_path
<< " is not found";
util::Log(logWARNING) << config.storage_config.geometries_path << " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.timestamp_path))
{
util::SimpleLogger().Write(logWARNING) << config.storage_config.timestamp_path
<< " is not found";
util::Log(logWARNING) << config.storage_config.timestamp_path << " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.datasource_names_path))
{
util::SimpleLogger().Write(logWARNING)
<< config.storage_config.datasource_names_path << " is not found";
util::Log(logWARNING) << config.storage_config.datasource_names_path
<< " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.datasource_indexes_path))
{
util::SimpleLogger().Write(logWARNING)
<< config.storage_config.datasource_indexes_path << " is not found";
util::Log(logWARNING) << config.storage_config.datasource_indexes_path
<< " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.names_data_path))
{
util::SimpleLogger().Write(logWARNING) << config.storage_config.names_data_path
<< " is not found";
util::Log(logWARNING) << config.storage_config.names_data_path << " is not found";
}
if (!boost::filesystem::is_regular_file(config.storage_config.properties_path))
{
util::SimpleLogger().Write(logWARNING) << config.storage_config.properties_path
<< " is not found";
util::Log(logWARNING) << config.storage_config.properties_path << " is not found";
}
}
return EXIT_FAILURE;
@@ -287,7 +276,7 @@ int main(int argc, const char *argv[]) try
if (should_lock && -1 == mlockall(MCL_CURRENT | MCL_FUTURE))
{
could_lock = false;
util::SimpleLogger().Write(logWARNING) << "memory could not be locked to RAM";
util::Log(logWARNING) << "memory could not be locked to RAM";
}
}
~MemoryLocker()
@@ -298,16 +287,16 @@ int main(int argc, const char *argv[]) try
bool should_lock = false, could_lock = true;
} memory_locker(config.use_shared_memory);
#endif
util::SimpleLogger().Write() << "starting up engines, " << OSRM_VERSION;
util::Log() << "starting up engines, " << OSRM_VERSION;
if (config.use_shared_memory)
{
util::SimpleLogger().Write() << "Loading from shared memory";
util::Log() << "Loading from shared memory";
}
util::SimpleLogger().Write() << "Threads: " << requested_thread_num;
util::SimpleLogger().Write() << "IP address: " << ip_address;
util::SimpleLogger().Write() << "IP port: " << ip_port;
util::Log() << "Threads: " << requested_thread_num;
util::Log() << "IP address: " << ip_address;
util::Log() << "IP port: " << ip_port;
#ifndef _WIN32
int sig = 0;
@@ -324,7 +313,7 @@ int main(int argc, const char *argv[]) try
if (trial_run)
{
util::SimpleLogger().Write() << "trial run, quitting after successful initialization";
util::Log() << "trial run, quitting after successful initialization";
}
else
{
@@ -343,7 +332,7 @@ int main(int argc, const char *argv[]) try
sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &wait_mask, nullptr);
util::SimpleLogger().Write() << "running and waiting for requests";
util::Log() << "running and waiting for requests";
if (std::getenv("SIGNAL_PARENT_WHEN_READY"))
{
kill(getppid(), SIGUSR1);
@@ -353,12 +342,12 @@ int main(int argc, const char *argv[]) try
// Set console control handler to allow server to be stopped.
console_ctrl_function = std::bind(&server::Server::Stop, routing_server);
SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
util::SimpleLogger().Write() << "running and waiting for requests";
util::Log() << "running and waiting for requests";
routing_server->Run();
#endif
util::SimpleLogger().Write() << "initiating shutdown";
util::Log() << "initiating shutdown";
routing_server->Stop();
util::SimpleLogger().Write() << "stopping threads";
util::Log() << "stopping threads";
auto status = future.wait_for(std::chrono::seconds(2));
@@ -368,19 +357,18 @@ int main(int argc, const char *argv[]) try
}
else
{
util::SimpleLogger().Write(logWARNING) << "Didn't exit within 2 seconds. Hard abort!";
util::Log(logWARNING) << "Didn't exit within 2 seconds. Hard abort!";
server_task.reset(); // just kill it
}
}
util::SimpleLogger().Write() << "freeing objects";
util::Log() << "freeing objects";
routing_server.reset();
util::SimpleLogger().Write() << "shutdown completed";
util::Log() << "shutdown completed";
}
catch (const std::bad_alloc &e)
{
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
util::SimpleLogger().Write(logWARNING)
<< "Please provide more memory or consider using a larger swapfile";
util::Log(logWARNING) << "[exception] " << e.what();
util::Log(logWARNING) << "Please provide more memory or consider using a larger swapfile";
return EXIT_FAILURE;
}
+11 -12
View File
@@ -2,7 +2,7 @@
#include "storage/shared_datatype.hpp"
#include "storage/shared_memory.hpp"
#include "util/simple_logger.hpp"
#include "util/log.hpp"
namespace osrm
{
@@ -36,14 +36,14 @@ void deleteRegion(const SharedDataType region)
}
}();
util::SimpleLogger().Write(logWARNING) << "could not delete shared memory region " << name;
util::Log(logWARNING) << "could not delete shared memory region " << name;
}
}
// find all existing shmem regions and remove them.
void springclean()
{
util::SimpleLogger().Write() << "spring-cleaning all shared memory regions";
util::Log() << "spring-cleaning all shared memory regions";
deleteRegion(DATA_1);
deleteRegion(LAYOUT_1);
deleteRegion(DATA_2);
@@ -56,19 +56,18 @@ void springclean()
int main()
{
osrm::util::LogPolicy::GetInstance().Unmute();
osrm::util::SimpleLogger().Write() << "Releasing all locks";
osrm::util::SimpleLogger().Write() << "ATTENTION! BE CAREFUL!";
osrm::util::SimpleLogger().Write() << "----------------------";
osrm::util::SimpleLogger().Write() << "This tool may put osrm-routed into an undefined state!";
osrm::util::SimpleLogger().Write()
<< "Type 'Y' to acknowledge that you know what your are doing.";
osrm::util::SimpleLogger().Write() << "\n\nDo you want to purge all shared memory allocated "
<< "by osrm-datastore? [type 'Y' to confirm]";
osrm::util::Log() << "Releasing all locks";
osrm::util::Log() << "ATTENTION! BE CAREFUL!";
osrm::util::Log() << "----------------------";
osrm::util::Log() << "This tool may put osrm-routed into an undefined state!";
osrm::util::Log() << "Type 'Y' to acknowledge that you know what your are doing.";
osrm::util::Log() << "\n\nDo you want to purge all shared memory allocated "
<< "by osrm-datastore? [type 'Y' to confirm]";
const auto letter = getchar();
if (letter != 'Y')
{
osrm::util::SimpleLogger().Write() << "aborted.";
osrm::util::Log() << "aborted.";
return EXIT_SUCCESS;
}
osrm::tools::springclean();
+12 -13
View File
@@ -1,6 +1,6 @@
#include "storage/storage.hpp"
#include "util/exception.hpp"
#include "util/simple_logger.hpp"
#include "util/log.hpp"
#include "util/typedefs.hpp"
#include "util/version.hpp"
@@ -49,7 +49,7 @@ bool generateDataStoreOptions(const int argc,
// print help options if no infile is specified
if (argc < 2)
{
util::SimpleLogger().Write() << visible_options;
util::Log() << visible_options;
return false;
}
@@ -66,19 +66,19 @@ bool generateDataStoreOptions(const int argc,
}
catch (const boost::program_options::error &e)
{
util::SimpleLogger().Write(logWARNING) << "[error] " << e.what();
util::Log(logERROR) << e.what();
return false;
}
if (option_variables.count("version"))
{
util::SimpleLogger().Write() << OSRM_VERSION;
util::Log() << OSRM_VERSION;
return false;
}
if (option_variables.count("help"))
{
util::SimpleLogger().Write() << visible_options;
util::Log() << visible_options;
return false;
}
@@ -100,7 +100,7 @@ int main(const int argc, const char *argv[]) try
storage::StorageConfig config(base_path);
if (!config.IsValid())
{
util::SimpleLogger().Write(logWARNING) << "Config contains invalid file paths. Exiting!";
util::Log(logERROR) << "Config contains invalid file paths. Exiting!";
return EXIT_FAILURE;
}
storage::Storage storage(std::move(config));
@@ -115,8 +115,8 @@ int main(const int argc, const char *argv[]) try
{
if (retry_counter > 0)
{
util::SimpleLogger().Write(logWARNING) << "Try number " << (retry_counter + 1)
<< " to load the dataset.";
util::Log(logWARNING) << "Try number " << (retry_counter + 1)
<< " to load the dataset.";
}
code = storage.Run(max_wait);
retry_counter++;
@@ -131,9 +131,8 @@ int main(const int argc, const char *argv[]) try
}
catch (const std::bad_alloc &e)
{
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
util::SimpleLogger().Write(logWARNING)
<< "Please provide more memory or disable locking the virtual "
"address space (note: this makes OSRM swap, i.e. slow)";
util::Log(logERROR) << "[exception] " << e.what();
util::Log(logERROR) << "Please provide more memory or disable locking the virtual "
"address space (note: this makes OSRM swap, i.e. slow)";
return EXIT_FAILURE;
}
}
+2 -2
View File
@@ -1,12 +1,12 @@
#include "storage/shared_barriers.hpp"
#include "util/simple_logger.hpp"
#include "util/log.hpp"
#include <iostream>
int main()
{
osrm::util::LogPolicy::GetInstance().Unmute();
osrm::util::SimpleLogger().Write() << "Releasing all locks";
osrm::util::Log() << "Releasing all locks";
osrm::storage::SharedBarriers::resetCurrentRegions();
osrm::storage::SharedBarriers::resetRegions1();