Refactor logging, improve error handling workflow, clang-format. (#3385)
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
#include "util/deallocating_vector.hpp"
|
||||
#include "util/dynamic_graph.hpp"
|
||||
#include "util/integer_range.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/percent.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/timing_util.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
#include "util/xor_fast_hash.hpp"
|
||||
@@ -156,11 +156,10 @@ class GraphContractor
|
||||
#ifndef NDEBUG
|
||||
if (static_cast<unsigned int>(std::max(diter->weight, 1)) > 24 * 60 * 60 * 10)
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING)
|
||||
<< "Edge weight large -> "
|
||||
<< static_cast<unsigned int>(std::max(diter->weight, 1)) << " : "
|
||||
<< static_cast<unsigned int>(diter->source) << " -> "
|
||||
<< static_cast<unsigned int>(diter->target);
|
||||
util::Log(logWARNING) << "Edge weight large -> "
|
||||
<< static_cast<unsigned int>(std::max(diter->weight, 1))
|
||||
<< " : " << static_cast<unsigned int>(diter->source) << " -> "
|
||||
<< static_cast<unsigned int>(diter->target);
|
||||
}
|
||||
#endif
|
||||
edges.emplace_back(diter->source,
|
||||
@@ -245,15 +244,14 @@ class GraphContractor
|
||||
}
|
||||
}
|
||||
}
|
||||
util::SimpleLogger().Write() << "merged " << edges.size() - edge << " edges out of "
|
||||
<< edges.size();
|
||||
util::Log() << "merged " << edges.size() - edge << " edges out of " << edges.size();
|
||||
edges.resize(edge);
|
||||
contractor_graph = std::make_shared<ContractorGraph>(nodes, edges);
|
||||
edges.clear();
|
||||
edges.shrink_to_fit();
|
||||
|
||||
BOOST_ASSERT(0 == edges.capacity());
|
||||
util::SimpleLogger().Write() << "contractor finished initalization";
|
||||
util::Log() << "contractor finished initalization";
|
||||
}
|
||||
|
||||
void Run(double core_factor = 1.0)
|
||||
@@ -270,7 +268,6 @@ class GraphContractor
|
||||
const constexpr size_t DeleteGrainSize = 1;
|
||||
|
||||
const NodeID number_of_nodes = contractor_graph->GetNumberOfNodes();
|
||||
util::Percent p(number_of_nodes);
|
||||
|
||||
ThreadDataContainer thread_data_list(number_of_nodes);
|
||||
|
||||
@@ -292,9 +289,10 @@ class GraphContractor
|
||||
bool use_cached_node_priorities = !node_levels.empty();
|
||||
if (use_cached_node_priorities)
|
||||
{
|
||||
std::cout << "using cached node priorities ..." << std::flush;
|
||||
util::UnbufferedLog log;
|
||||
log << "using cached node priorities ...";
|
||||
node_priorities.swap(node_levels);
|
||||
std::cout << "ok" << std::endl;
|
||||
log << "ok";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -302,7 +300,8 @@ class GraphContractor
|
||||
node_priorities.resize(number_of_nodes);
|
||||
node_levels.resize(number_of_nodes);
|
||||
|
||||
std::cout << "initializing elimination PQ ..." << std::flush;
|
||||
util::UnbufferedLog log;
|
||||
log << "initializing elimination PQ ...";
|
||||
tbb::parallel_for(tbb::blocked_range<int>(0, number_of_nodes, PQGrainSize),
|
||||
[this, &node_priorities, &node_depth, &thread_data_list](
|
||||
const tbb::blocked_range<int> &range) {
|
||||
@@ -313,11 +312,14 @@ class GraphContractor
|
||||
this->EvaluateNodePriority(data, node_depth[x], x);
|
||||
}
|
||||
});
|
||||
std::cout << "ok" << std::endl;
|
||||
log << "ok";
|
||||
}
|
||||
BOOST_ASSERT(node_priorities.size() == number_of_nodes);
|
||||
|
||||
std::cout << "preprocessing " << number_of_nodes << " nodes ..." << std::flush;
|
||||
util::Log() << "preprocessing " << number_of_nodes << " nodes ...";
|
||||
|
||||
util::UnbufferedLog log;
|
||||
util::Percent p(log, number_of_nodes);
|
||||
|
||||
unsigned current_level = 0;
|
||||
bool flushed_contractor = false;
|
||||
@@ -331,7 +333,7 @@ class GraphContractor
|
||||
new_edge_set; // this one is not explicitely
|
||||
// cleared since it goes out of
|
||||
// scope anywa
|
||||
std::cout << " [flush " << number_of_contracted_nodes << " nodes] " << std::flush;
|
||||
log << " [flush " << number_of_contracted_nodes << " nodes] ";
|
||||
|
||||
// Delete old heap data to free memory that we need for the coming operations
|
||||
thread_data_list.data.clear();
|
||||
@@ -599,9 +601,8 @@ class GraphContractor
|
||||
is_core_node.clear();
|
||||
}
|
||||
|
||||
util::SimpleLogger().Write() << "[core] " << remaining_nodes.size() << " nodes "
|
||||
<< contractor_graph->GetNumberOfEdges() << " edges."
|
||||
<< std::endl;
|
||||
util::Log() << "[core] " << remaining_nodes.size() << " nodes "
|
||||
<< contractor_graph->GetNumberOfEdges() << " edges.";
|
||||
|
||||
thread_data_list.data.clear();
|
||||
}
|
||||
@@ -618,8 +619,9 @@ class GraphContractor
|
||||
|
||||
template <class Edge> inline void GetEdges(util::DeallocatingVector<Edge> &edges)
|
||||
{
|
||||
util::Percent p(contractor_graph->GetNumberOfNodes());
|
||||
util::SimpleLogger().Write() << "Getting edges of minimized graph";
|
||||
util::UnbufferedLog log;
|
||||
log << "Getting edges of minimized graph ";
|
||||
util::Percent p(log, contractor_graph->GetNumberOfNodes());
|
||||
const NodeID number_of_nodes = contractor_graph->GetNumberOfNodes();
|
||||
if (contractor_graph->GetNumberOfNodes())
|
||||
{
|
||||
|
||||
@@ -12,11 +12,13 @@
|
||||
#include "util/guidance/turn_lanes.hpp"
|
||||
|
||||
#include "engine/geospatial_query.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "util/exception_utils.hpp"
|
||||
#include "util/guidance/turn_bearing.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/packed_vector.hpp"
|
||||
#include "util/range_table.hpp"
|
||||
#include "util/rectangle.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/static_graph.hpp"
|
||||
#include "util/static_rtree.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
@@ -116,7 +118,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
|
||||
{
|
||||
m_check_sum =
|
||||
*data_layout.GetBlockPtr<unsigned>(memory_block, storage::DataLayout::HSGR_CHECKSUM);
|
||||
util::SimpleLogger().Write() << "set checksum: " << m_check_sum;
|
||||
util::Log() << "set checksum: " << m_check_sum;
|
||||
}
|
||||
|
||||
void InitializeProfilePropertiesPointer(storage::DataLayout &data_layout, char *memory_block)
|
||||
@@ -144,9 +146,9 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
|
||||
file_index_path = boost::filesystem::path(file_index_ptr);
|
||||
if (!boost::filesystem::exists(file_index_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logDEBUG) << "Leaf file name " << file_index_path.string();
|
||||
util::Log(logDEBUG) << "Leaf file name " << file_index_path.string();
|
||||
throw util::exception("Could not load " + file_index_path.string() +
|
||||
"Is any data loaded into shared memory?");
|
||||
"Is any data loaded into shared memory?" + SOURCE_REF);
|
||||
}
|
||||
|
||||
auto tree_ptr =
|
||||
|
||||
@@ -56,8 +56,7 @@ class SharedMemoryDataFacade : public ContiguousInternalMemoryDataFacadeBase
|
||||
|
||||
if (current_timestamp->timestamp == shared_timestamp)
|
||||
{
|
||||
util::SimpleLogger().Write(logDEBUG) << "Retaining data with shared timestamp "
|
||||
<< shared_timestamp;
|
||||
util::Log(logDEBUG) << "Retaining data with shared timestamp " << shared_timestamp;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -74,8 +73,7 @@ class SharedMemoryDataFacade : public ContiguousInternalMemoryDataFacadeBase
|
||||
: shared_barriers(shared_barriers_), layout_region(layout_region_),
|
||||
data_region(data_region_), shared_timestamp(shared_timestamp_)
|
||||
{
|
||||
util::SimpleLogger().Write(logDEBUG) << "Loading new data with shared timestamp "
|
||||
<< shared_timestamp;
|
||||
util::Log(logDEBUG) << "Loading new data with shared timestamp " << shared_timestamp;
|
||||
|
||||
BOOST_ASSERT(storage::SharedMemory::RegionExists(layout_region));
|
||||
m_layout_memory = storage::makeSharedMemory(layout_region);
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "engine/plugins/trip.hpp"
|
||||
#include "engine/plugins/viaroute.hpp"
|
||||
#include "engine/status.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "util/exception_utils.hpp"
|
||||
#include "util/json_container.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -235,10 +235,10 @@ class AlternativeRouting final
|
||||
}
|
||||
}
|
||||
|
||||
// util::SimpleLogger().Write(logDEBUG) << "fwd_search_space size: " <<
|
||||
// util::Log(logDEBUG) << "fwd_search_space size: " <<
|
||||
// forward_search_space.size() << ", marked " << approximated_forward_sharing.size() << "
|
||||
// nodes";
|
||||
// util::SimpleLogger().Write(logDEBUG) << "rev_search_space size: " <<
|
||||
// util::Log(logDEBUG) << "rev_search_space size: " <<
|
||||
// reverse_search_space.size() << ", marked " << approximated_reverse_sharing.size() << "
|
||||
// nodes";
|
||||
|
||||
@@ -601,7 +601,7 @@ class AlternativeRouting final
|
||||
// //compute forward sharing
|
||||
// while( (packed_alternate_path[aindex] == packed_shortest_path[aindex]) &&
|
||||
// (packed_alternate_path[aindex+1] == packed_shortest_path[aindex+1]) ) {
|
||||
// // util::SimpleLogger().Write() << "retrieving edge (" <<
|
||||
// // util::Log() << "retrieving edge (" <<
|
||||
// packed_alternate_path[aindex] << "," << packed_alternate_path[aindex+1] << ")";
|
||||
// EdgeID edgeID = facade->FindEdgeInEitherDirection(packed_alternate_path[aindex],
|
||||
// packed_alternate_path[aindex+1]);
|
||||
@@ -640,7 +640,7 @@ class AlternativeRouting final
|
||||
const NodeID node = forward_heap.DeleteMin();
|
||||
const int weight = forward_heap.GetKey(node);
|
||||
// const NodeID parentnode = forward_heap.GetData(node).parent;
|
||||
// util::SimpleLogger().Write() << (is_forward_directed ? "[fwd] " : "[rev] ") << "settled
|
||||
// util::Log() << (is_forward_directed ? "[fwd] " : "[rev] ") << "settled
|
||||
// edge ("
|
||||
// << parentnode << "," << node << "), dist: " << weight;
|
||||
|
||||
@@ -665,11 +665,11 @@ class AlternativeRouting final
|
||||
{
|
||||
*middle_node = node;
|
||||
*upper_bound_to_shortest_path_weight = new_weight;
|
||||
// util::SimpleLogger().Write() << "accepted middle_node " << *middle_node
|
||||
// util::Log() << "accepted middle_node " << *middle_node
|
||||
// << " at
|
||||
// weight " << new_weight;
|
||||
// } else {
|
||||
// util::SimpleLogger().Write() << "discarded middle_node " << *middle_node
|
||||
// util::Log() << "discarded middle_node " << *middle_node
|
||||
// << "
|
||||
// at weight " << new_weight;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define TRIP_BRUTE_FORCE_HPP
|
||||
|
||||
#include "util/dist_table_wrapper.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include "osrm/json_container.hpp"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define TRIP_NEAREST_NEIGHBOUR_HPP
|
||||
|
||||
#include "util/dist_table_wrapper.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include "osrm/json_container.hpp"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include "util/json_container.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
namespace osrm
|
||||
|
||||
@@ -66,13 +66,14 @@ class RasterGrid
|
||||
}
|
||||
catch (std::exception const &ex)
|
||||
{
|
||||
throw util::exception(
|
||||
std::string("Failed to read from raster source with exception: ") + ex.what());
|
||||
throw util::exception("Failed to read from raster source " + filepath.string() + ": " +
|
||||
ex.what() + SOURCE_REF);
|
||||
}
|
||||
|
||||
if (!r || itr != end)
|
||||
{
|
||||
throw util::exception("Failed to parse raster source correctly.");
|
||||
throw util::exception("Failed to parse raster source: " + filepath.string() +
|
||||
SOURCE_REF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include "util/integer_range.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/std_hash.hpp"
|
||||
#include "util/timing_util.hpp"
|
||||
|
||||
@@ -146,8 +146,8 @@ template <typename GraphT> class TarjanSCC
|
||||
|
||||
if (size_of_current_component > 1000)
|
||||
{
|
||||
util::SimpleLogger().Write() << "large component [" << component_index
|
||||
<< "]=" << size_of_current_component;
|
||||
util::Log() << "large component [" << component_index
|
||||
<< "]=" << size_of_current_component;
|
||||
}
|
||||
|
||||
++component_index;
|
||||
@@ -158,7 +158,7 @@ template <typename GraphT> class TarjanSCC
|
||||
}
|
||||
|
||||
TIMER_STOP(SCC_RUN);
|
||||
util::SimpleLogger().Write() << "SCC run took: " << TIMER_MSEC(SCC_RUN) / 1000. << "s";
|
||||
util::Log() << "SCC run took: " << TIMER_MSEC(SCC_RUN) / 1000. << "s";
|
||||
|
||||
size_one_counter = std::count_if(component_size_vector.begin(),
|
||||
component_size_vector.end(),
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "server/service_handler.hpp"
|
||||
|
||||
#include "util/integer_range.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
@@ -36,8 +36,7 @@ class Server
|
||||
static std::shared_ptr<Server>
|
||||
CreateServer(std::string &ip_address, int ip_port, unsigned requested_num_threads)
|
||||
{
|
||||
util::SimpleLogger().Write() << "http 1.1 compression handled by zlib version "
|
||||
<< zlibVersion();
|
||||
util::Log() << "http 1.1 compression handled by zlib version " << zlibVersion();
|
||||
const unsigned hardware_threads = std::max(1u, std::thread::hardware_concurrency());
|
||||
const unsigned real_num_threads = std::min(hardware_threads, requested_num_threads);
|
||||
return std::make_shared<Server>(ip_address, ip_port, real_num_threads);
|
||||
@@ -62,7 +61,7 @@ class Server
|
||||
acceptor.bind(endpoint);
|
||||
acceptor.listen();
|
||||
|
||||
util::SimpleLogger().Write() << "Listening on: " << acceptor.local_endpoint();
|
||||
util::Log() << "Listening on: " << acceptor.local_endpoint();
|
||||
|
||||
acceptor.async_accept(
|
||||
new_connection->socket(),
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
#define OSRM_STORAGE_IO_HPP_
|
||||
|
||||
#include "util/exception.hpp"
|
||||
#include "util/exception_utils.hpp"
|
||||
#include "util/fingerprint.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/iostreams/seek.hpp>
|
||||
@@ -55,7 +56,7 @@ class FileReader
|
||||
|
||||
if (flag == VerifyFingerprint && !ReadAndCheckFingerprint())
|
||||
{
|
||||
throw util::exception("Fingerprint mismatch in " + filepath.string());
|
||||
throw util::exception("Fingerprint mismatch in " + filepath_.string() + SOURCE_REF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,9 +78,9 @@ class FileReader
|
||||
if (result.eof())
|
||||
{
|
||||
throw util::exception("Error reading from " + filepath.string() +
|
||||
": Unexpected end of file");
|
||||
": Unexpected end of file " + SOURCE_REF);
|
||||
}
|
||||
throw util::exception("Error reading from " + filepath.string());
|
||||
throw util::exception("Error reading from " + filepath.string() + " " + SOURCE_REF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "storage/io.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "util/fingerprint.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/static_graph.hpp"
|
||||
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
@@ -44,8 +44,8 @@ inline HSGRHeader readHSGRHeader(io::FileReader &input_file)
|
||||
const auto fingerprint_loaded = input_file.ReadOne<util::FingerPrint>();
|
||||
if (!fingerprint_loaded.TestGraphUtil(fingerprint_valid))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << ".hsgr was prepared with different build.\n"
|
||||
"Reprocess to get rid of this warning.";
|
||||
util::Log(logWARNING) << ".hsgr was prepared with different build.\n"
|
||||
"Reprocess to get rid of this warning.";
|
||||
}
|
||||
|
||||
HSGRHeader header;
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
#define SHARED_DATA_TYPE_HPP
|
||||
|
||||
#include "util/exception.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/exception_utils.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
@@ -175,13 +176,13 @@ struct DataLayout
|
||||
bool end_canary_alive = std::equal(CANARY, CANARY + sizeof(CANARY), end_canary_ptr);
|
||||
if (!start_canary_alive)
|
||||
{
|
||||
throw util::exception(std::string("Start canary of block corrupted. (") +
|
||||
block_id_to_name[bid] + ")");
|
||||
throw util::exception("Start canary of block corrupted. (" +
|
||||
std::string(block_id_to_name[bid]) + ")" + SOURCE_REF);
|
||||
}
|
||||
if (!end_canary_alive)
|
||||
{
|
||||
throw util::exception(std::string("End canary of block corrupted. (") +
|
||||
block_id_to_name[bid] + ")");
|
||||
throw util::exception("End canary of block corrupted. (" +
|
||||
std::string(block_id_to_name[bid]) + ")" + SOURCE_REF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
#define SHARED_MEMORY_HPP
|
||||
|
||||
#include "util/exception.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/exception_utils.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
@@ -62,8 +63,7 @@ class SharedMemory
|
||||
{
|
||||
shm = boost::interprocess::xsi_shared_memory(boost::interprocess::open_only, key);
|
||||
|
||||
util::SimpleLogger().Write(logDEBUG) << "opening " << shm.get_shmid() << " from id "
|
||||
<< id;
|
||||
util::Log(logDEBUG) << "opening " << shm.get_shmid() << " from id " << id;
|
||||
|
||||
region = boost::interprocess::mapped_region(shm, access);
|
||||
}
|
||||
@@ -72,14 +72,14 @@ class SharedMemory
|
||||
{
|
||||
shm = boost::interprocess::xsi_shared_memory(
|
||||
boost::interprocess::open_or_create, key, size);
|
||||
util::SimpleLogger().Write(logDEBUG) << "opening/creating " << shm.get_shmid()
|
||||
<< " from id " << id << " with size " << size;
|
||||
util::Log(logDEBUG) << "opening/creating " << shm.get_shmid() << " from id " << id
|
||||
<< " with size " << size;
|
||||
#ifdef __linux__
|
||||
if (-1 == shmctl(shm.get_shmid(), SHM_LOCK, nullptr))
|
||||
{
|
||||
if (ENOMEM == errno)
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << "could not lock shared memory to RAM";
|
||||
util::Log(logWARNING) << "could not lock shared memory to RAM";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -133,7 +133,7 @@ class SharedMemory
|
||||
static bool Remove(const boost::interprocess::xsi_key &key)
|
||||
{
|
||||
boost::interprocess::xsi_shared_memory xsi(boost::interprocess::open_only, key);
|
||||
util::SimpleLogger().Write(logDEBUG) << "deallocating prev memory " << xsi.get_shmid();
|
||||
util::Log(logDEBUG) << "deallocating prev memory " << xsi.get_shmid();
|
||||
return boost::interprocess::xsi_shared_memory::remove(xsi.get_shmid());
|
||||
}
|
||||
|
||||
@@ -173,8 +173,7 @@ class SharedMemory
|
||||
shm.truncate(size);
|
||||
region = boost::interprocess::mapped_region(shm, access);
|
||||
|
||||
util::SimpleLogger().Write(logDEBUG) << "writeable memory allocated " << size
|
||||
<< " bytes";
|
||||
util::Log(logDEBUG) << "writeable memory allocated " << size << " bytes";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +220,7 @@ class SharedMemory
|
||||
|
||||
static bool Remove(char *key)
|
||||
{
|
||||
util::SimpleLogger().Write(logDEBUG) << "deallocating prev memory for key " << key;
|
||||
util::Log(logDEBUG) << "deallocating prev memory for key " << key;
|
||||
return boost::interprocess::shared_memory_object::remove(key);
|
||||
}
|
||||
|
||||
@@ -242,7 +241,7 @@ makeSharedMemory(const IdentifierT &id, const uint64_t size = 0, bool read_write
|
||||
{
|
||||
if (0 == size)
|
||||
{
|
||||
throw util::exception("lock file does not exist, exiting");
|
||||
throw util::exception("lock file does not exist, exiting" + SOURCE_REF);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -253,9 +252,9 @@ makeSharedMemory(const IdentifierT &id, const uint64_t size = 0, bool read_write
|
||||
}
|
||||
catch (const boost::interprocess::interprocess_exception &e)
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << "caught exception: " << e.what() << ", code "
|
||||
<< e.get_error_code();
|
||||
throw util::exception(e.what());
|
||||
util::Log(logERROR) << "Error while attempting to allocate shared memory: " << e.what()
|
||||
<< ", code " << e.get_error_code();
|
||||
throw util::exception(e.what() + SOURCE_REF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef SOURCE_MACROS_HPP
|
||||
#define SOURCE_MACROS_HPP
|
||||
#include <cstring>
|
||||
|
||||
// Helper macros, don't use these ones
|
||||
// STRIP the OSRM_PROJECT_DIR from the front of a filename. Expected to come
|
||||
// from CMake's CURRENT_SOURCE_DIR, which doesn't have a trailing /, hence the +1
|
||||
#define _PROJECT_RELATIVE_PATH(x) std::string(x).substr(strlen(OSRM_PROJECT_DIR) + 1)
|
||||
// Return the path of a file, relative to the OSRM_PROJECT_DIR
|
||||
#define _OSRM_SOURCE_FILE _PROJECT_RELATIVE_PATH(__FILE__)
|
||||
|
||||
// This is the macro to use
|
||||
#define SOURCE_REF std::string(" (at ") + _OSRM_SOURCE_FILE + ":" + std::to_string(__LINE__) + ")"
|
||||
|
||||
#endif // SOURCE_MACROS_HPP
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "util/exception.hpp"
|
||||
#include "util/exception_utils.hpp"
|
||||
|
||||
#include <boost/uuid/name_generator.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
@@ -57,7 +58,7 @@ bool FingerPrint::TestGraphUtil(const FingerPrint &other) const
|
||||
{
|
||||
if (!IsMagicNumberOK(other))
|
||||
{
|
||||
throw exception("hsgr input file misses magic number. Check or reprocess the file");
|
||||
throw exception(std::string("hsgr input file misses magic number. Check or reprocess the file") + SOURCE_REF);
|
||||
}
|
||||
return std::equal(md5_graph, md5_graph + 32, other.md5_graph);
|
||||
}
|
||||
@@ -66,7 +67,7 @@ bool FingerPrint::TestContractor(const FingerPrint &other) const
|
||||
{
|
||||
if (!IsMagicNumberOK(other))
|
||||
{
|
||||
throw exception("osrm input file misses magic number. Check or reprocess the file");
|
||||
throw exception(std::string("osrm input file misses magic number. Check or reprocess the file") + SOURCE_REF);
|
||||
}
|
||||
return std::equal(md5_prepare, md5_prepare + 32, other.md5_prepare);
|
||||
}
|
||||
@@ -75,7 +76,7 @@ bool FingerPrint::TestRTree(const FingerPrint &other) const
|
||||
{
|
||||
if (!IsMagicNumberOK(other))
|
||||
{
|
||||
throw exception("r-tree input file misses magic number. Check or reprocess the file");
|
||||
throw exception(std::string("r-tree input file misses magic number. Check or reprocess the file") + SOURCE_REF);
|
||||
}
|
||||
return std::equal(md5_tree, md5_tree + 32, other.md5_tree);
|
||||
}
|
||||
@@ -84,7 +85,7 @@ bool FingerPrint::TestQueryObjects(const FingerPrint &other) const
|
||||
{
|
||||
if (!IsMagicNumberOK(other))
|
||||
{
|
||||
throw exception("missing magic number. Check or reprocess the file");
|
||||
throw exception(std::string("missing magic number. Check or reprocess the file") + SOURCE_REF);
|
||||
}
|
||||
return std::equal(md5_objects, md5_objects + 32, other.md5_objects);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "util/json_container.hpp"
|
||||
#include "util/json_renderer.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
@@ -92,7 +92,7 @@ class GeojsonLogger
|
||||
// out on log output. Such a sad life
|
||||
if (ofs.is_open())
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING)
|
||||
util::Log(logWARNING)
|
||||
<< "Overwriting " << logfile
|
||||
<< ". Is this desired behaviour? If this message occurs more than once rethink the "
|
||||
"location of your Logger Guard.";
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "storage/io.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "util/fingerprint.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
@@ -60,7 +60,7 @@ NodeID loadNodesFromFile(storage::io::FileReader &file_reader,
|
||||
std::vector<extractor::QueryNode> &node_array)
|
||||
{
|
||||
NodeID number_of_nodes = file_reader.ReadElementCount32();
|
||||
SimpleLogger().Write() << "Importing number_of_nodes new = " << number_of_nodes << " nodes ";
|
||||
Log() << "Importing number_of_nodes new = " << number_of_nodes << " nodes ";
|
||||
|
||||
node_array.resize(number_of_nodes);
|
||||
|
||||
@@ -99,14 +99,14 @@ inline NodeID loadEdgesFromFile(storage::io::FileReader &file_reader,
|
||||
BOOST_ASSERT(sizeof(EdgeID) == sizeof(number_of_edges));
|
||||
|
||||
edge_list.resize(number_of_edges);
|
||||
SimpleLogger().Write() << " and " << number_of_edges << " edges ";
|
||||
Log() << " and " << number_of_edges << " edges ";
|
||||
|
||||
file_reader.ReadInto(edge_list.data(), number_of_edges);
|
||||
|
||||
BOOST_ASSERT(edge_list.size() > 0);
|
||||
|
||||
#ifndef NDEBUG
|
||||
SimpleLogger().Write() << "Validating loaded edges...";
|
||||
Log() << "Validating loaded edges...";
|
||||
tbb::parallel_sort(
|
||||
edge_list.begin(),
|
||||
edge_list.end(),
|
||||
@@ -129,7 +129,7 @@ inline NodeID loadEdgesFromFile(storage::io::FileReader &file_reader,
|
||||
}
|
||||
#endif
|
||||
|
||||
SimpleLogger().Write() << "Graph loaded ok and has " << edge_list.size() << " edges";
|
||||
Log() << "Graph loaded ok and has " << edge_list.size() << " edges";
|
||||
|
||||
return number_of_edges;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include "util/attributes.hpp"
|
||||
#include "util/guidance/bearing_class.hpp"
|
||||
#include "util/guidance/entry_class.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/name_table.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
+6
-6
@@ -1,7 +1,7 @@
|
||||
#ifndef OSRM_INCLUDE_UTIL_IO_HPP_
|
||||
#define OSRM_INCLUDE_UTIL_IO_HPP_
|
||||
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
@@ -125,9 +125,10 @@ void deserializeAdjacencyArray(const std::string &filename,
|
||||
|
||||
// offsets have to match up with the size of the data
|
||||
if (offsets.empty() || (offsets.back() != boost::numeric_cast<std::uint32_t>(data.size())))
|
||||
throw util::exception("Error in " + filename + (offsets.empty()
|
||||
? "Offsets are empty"
|
||||
: "Offset and data size do not match"));
|
||||
throw util::exception(
|
||||
"Error in " + filename +
|
||||
(offsets.empty() ? "Offsets are empty" : "Offset and data size do not match") +
|
||||
SOURCE_REF);
|
||||
}
|
||||
|
||||
inline bool serializeFlags(const boost::filesystem::path &path, const std::vector<bool> &flags)
|
||||
@@ -153,8 +154,7 @@ inline bool serializeFlags(const boost::filesystem::path &path, const std::vecto
|
||||
++chunk_count;
|
||||
flag_stream.write(reinterpret_cast<const char *>(&chunk), sizeof(chunk));
|
||||
}
|
||||
SimpleLogger().Write() << "Wrote " << number_of_bits << " bits in " << chunk_count
|
||||
<< " chunks (Flags).";
|
||||
Log() << "Wrote " << number_of_bits << " bits in " << chunk_count << " chunks (Flags).";
|
||||
return static_cast<bool>(flag_stream);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#ifndef LOG_HPP
|
||||
#define LOG_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
||||
enum LogLevel
|
||||
{
|
||||
logINFO,
|
||||
logWARNING,
|
||||
logERROR,
|
||||
logDEBUG
|
||||
};
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
class LogPolicy
|
||||
{
|
||||
public:
|
||||
void Unmute();
|
||||
|
||||
void Mute();
|
||||
|
||||
bool IsMute() const;
|
||||
|
||||
static LogPolicy &GetInstance();
|
||||
|
||||
LogPolicy(const LogPolicy &) = delete;
|
||||
LogPolicy &operator=(const LogPolicy &) = delete;
|
||||
|
||||
private:
|
||||
LogPolicy() : m_is_mute(true) {}
|
||||
std::atomic<bool> m_is_mute;
|
||||
};
|
||||
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
Log(LogLevel level_ = logINFO);
|
||||
Log(LogLevel level_, std::ostream &ostream);
|
||||
|
||||
virtual ~Log();
|
||||
std::mutex &get_mutex();
|
||||
|
||||
template <typename T> inline std::ostream &operator<<(const T &data) { return stream << data; }
|
||||
|
||||
protected:
|
||||
LogLevel level;
|
||||
std::ostringstream buffer;
|
||||
std::ostream &stream;
|
||||
};
|
||||
|
||||
/**
|
||||
* Modified logger - this one doesn't buffer - it writes directly to stdout,
|
||||
* and the final newline is only printed when the object is destructed.
|
||||
* Useful for logging situations where you don't want to newline right away
|
||||
*/
|
||||
class UnbufferedLog : public Log
|
||||
{
|
||||
public:
|
||||
UnbufferedLog(LogLevel level_ = logINFO);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* LOG_HPP */
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "util/isatty.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
@@ -13,8 +14,13 @@ namespace util
|
||||
|
||||
class Percent
|
||||
{
|
||||
Log &log;
|
||||
|
||||
public:
|
||||
explicit Percent(unsigned max_value, unsigned step = 5) { Reinit(max_value, step); }
|
||||
explicit Percent(Log &log_, unsigned max_value, unsigned step = 5) : log{log_}
|
||||
{
|
||||
Reinit(max_value, step);
|
||||
}
|
||||
|
||||
// Reinitializes
|
||||
void Reinit(unsigned max_value, unsigned step = 5)
|
||||
@@ -36,7 +42,7 @@ class Percent
|
||||
PrintPercent(current_value / static_cast<double>(m_max_value) * 100.);
|
||||
}
|
||||
if (current_value + 1 == m_max_value)
|
||||
std::cout << " 100%" << std::endl;
|
||||
log << " 100%";
|
||||
}
|
||||
|
||||
void PrintIncrement()
|
||||
@@ -67,19 +73,17 @@ class Percent
|
||||
m_last_percent += m_step;
|
||||
if (m_last_percent % 10 == 0)
|
||||
{
|
||||
std::cout << " " << m_last_percent << "% ";
|
||||
log << " " << m_last_percent << "% ";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << ".";
|
||||
log << ".";
|
||||
}
|
||||
|
||||
// When not on a TTY, print newlines after each progress indicator so
|
||||
// so that progress is visible to line-buffered logging systems
|
||||
if (!IsStdoutATTY())
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout.flush();
|
||||
log << "" << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifndef SIMPLE_LOGGER_HPP
|
||||
#define SIMPLE_LOGGER_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
||||
enum LogLevel
|
||||
{
|
||||
logINFO,
|
||||
logWARNING,
|
||||
logDEBUG
|
||||
};
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
class LogPolicy
|
||||
{
|
||||
public:
|
||||
void Unmute();
|
||||
|
||||
void Mute();
|
||||
|
||||
bool IsMute() const;
|
||||
|
||||
static LogPolicy &GetInstance();
|
||||
|
||||
LogPolicy(const LogPolicy &) = delete;
|
||||
LogPolicy &operator=(const LogPolicy &) = delete;
|
||||
|
||||
private:
|
||||
LogPolicy() : m_is_mute(true) {}
|
||||
std::atomic<bool> m_is_mute;
|
||||
};
|
||||
|
||||
class SimpleLogger
|
||||
{
|
||||
public:
|
||||
SimpleLogger();
|
||||
|
||||
virtual ~SimpleLogger();
|
||||
std::mutex &get_mutex();
|
||||
std::ostringstream &Write(LogLevel l = logINFO) noexcept;
|
||||
|
||||
private:
|
||||
std::ostringstream os;
|
||||
LogLevel level;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SIMPLE_LOGGER_HPP */
|
||||
@@ -378,7 +378,8 @@ class StaticRTree
|
||||
catch (const std::exception &exc)
|
||||
{
|
||||
throw exception(boost::str(boost::format("Leaf file %1% mapping failed: %2%") %
|
||||
leaf_file % exc.what()));
|
||||
leaf_file % exc.what()) +
|
||||
SOURCE_REF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user