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
+53 -59
View File
@@ -11,11 +11,13 @@
#include "extractor/raster_source.hpp"
#include "storage/io.hpp"
#include "storage/io.hpp"
#include "util/exception.hpp"
#include "util/exception_utils.hpp"
#include "util/graph_loader.hpp"
#include "util/io.hpp"
#include "util/log.hpp"
#include "util/name_table.hpp"
#include "util/range_table.hpp"
#include "util/simple_logger.hpp"
#include "util/timing_util.hpp"
#include "extractor/compressed_edge_container.hpp"
@@ -119,12 +121,12 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
tbb::task_scheduler_init init(number_of_threads);
{
util::SimpleLogger().Write() << "Input file: " << config.input_path.filename().string();
util::Log() << "Input file: " << config.input_path.filename().string();
if (!config.profile_path.empty())
{
util::SimpleLogger().Write() << "Profile: " << config.profile_path.filename().string();
util::Log() << "Profile: " << config.profile_path.filename().string();
}
util::SimpleLogger().Write() << "Threads: " << number_of_threads;
util::Log() << "Threads: " << number_of_threads;
ExtractionContainers extraction_containers;
auto extractor_callbacks = std::make_unique<ExtractorCallbacks>(extraction_containers);
@@ -137,7 +139,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
unsigned number_of_ways = 0;
unsigned number_of_relations = 0;
util::SimpleLogger().Write() << "Parsing in progress..";
util::Log() << "Parsing in progress..";
TIMER_START(parsing);
// setup raster sources
@@ -148,7 +150,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
{
generator = "unknown tool";
}
util::SimpleLogger().Write() << "input file generated by " << generator;
util::Log() << "input file generated by " << generator;
// write .timestamp data file
std::string timestamp = header.get("osmosis_replication_timestamp");
@@ -156,7 +158,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
{
timestamp = "n/a";
}
util::SimpleLogger().Write() << "timestamp: " << timestamp;
util::Log() << "timestamp: " << timestamp;
boost::filesystem::ofstream timestamp_out(config.timestamp_file_name);
timestamp_out.write(timestamp.c_str(), timestamp.length());
@@ -210,12 +212,10 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
}
}
TIMER_STOP(parsing);
util::SimpleLogger().Write() << "Parsing finished after " << TIMER_SEC(parsing)
<< " seconds";
util::Log() << "Parsing finished after " << TIMER_SEC(parsing) << " seconds";
util::SimpleLogger().Write() << "Raw input contains " << number_of_nodes << " nodes, "
<< number_of_ways << " ways, and " << number_of_relations
<< " relations";
util::Log() << "Raw input contains " << number_of_nodes << " nodes, " << number_of_ways
<< " ways, and " << number_of_relations << " relations";
// take control over the turn lane map
turn_lane_map = extractor_callbacks->moveOutLaneDescriptionMap();
@@ -224,8 +224,8 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
if (extraction_containers.all_edges_list.empty())
{
util::SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
return 1;
throw util::exception(std::string("There are no edges remaining after parsing.") +
SOURCE_REF);
}
extraction_containers.PrepareData(scripting_environment,
@@ -237,15 +237,14 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
scripting_environment.GetProfileProperties());
TIMER_STOP(extracting);
util::SimpleLogger().Write() << "extraction finished after " << TIMER_SEC(extracting)
<< "s";
util::Log() << "extraction finished after " << TIMER_SEC(extracting) << "s";
}
{
// Transform the node-based graph that OSM is based on into an edge-based graph
// that is better for routing. Every edge becomes a node, and every valid
// movement (e.g. turn from A->B, and B->A) becomes an edge
util::SimpleLogger().Write() << "Generating edge-expanded graph representation";
util::Log() << "Generating edge-expanded graph representation";
TIMER_START(expansion);
@@ -267,17 +266,16 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
TIMER_STOP(expansion);
util::SimpleLogger().Write() << "Saving edge-based node weights to file.";
util::Log() << "Saving edge-based node weights to file.";
TIMER_START(timer_write_node_weights);
util::serializeVector(config.edge_based_node_weights_output_path, edge_based_node_weights);
TIMER_STOP(timer_write_node_weights);
util::SimpleLogger().Write() << "Done writing. (" << TIMER_SEC(timer_write_node_weights)
<< ")";
util::Log() << "Done writing. (" << TIMER_SEC(timer_write_node_weights) << ")";
util::SimpleLogger().Write() << "Computing strictly connected components ...";
util::Log() << "Computing strictly connected components ...";
FindComponents(max_edge_id, edge_based_edge_list, edge_based_node_list);
util::SimpleLogger().Write() << "Building r-tree ...";
util::Log() << "Building r-tree ...";
TIMER_START(rtree);
BuildRTree(std::move(edge_based_node_list),
std::move(node_is_startpoint),
@@ -285,7 +283,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
TIMER_STOP(rtree);
util::SimpleLogger().Write() << "Writing node map ...";
util::Log() << "Writing node map ...";
WriteNodeMapping(internal_to_external_node_map);
WriteEdgeBasedGraph(config.edge_graph_output_path, max_edge_id, edge_based_edge_list);
@@ -295,10 +293,10 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
const auto edges_per_second =
static_cast<std::uint64_t>((max_edge_id + 1) / TIMER_SEC(expansion));
util::SimpleLogger().Write() << "Expansion: " << nodes_per_second << " nodes/sec and "
<< edges_per_second << " edges/sec";
util::SimpleLogger().Write() << "To prepare the data for routing, run: "
<< "./osrm-contract " << config.output_file_name << std::endl;
util::Log() << "Expansion: " << nodes_per_second << " nodes/sec and " << edges_per_second
<< " edges/sec";
util::Log() << "To prepare the data for routing, run: "
<< "./osrm-contract " << config.output_file_name;
}
return 0;
@@ -310,7 +308,7 @@ void Extractor::WriteProfileProperties(const std::string &output_path,
boost::filesystem::ofstream out_stream(output_path);
if (!out_stream)
{
throw util::exception("Could not open " + output_path + " for writing.");
throw util::exception("Could not open " + output_path + " for writing." + SOURCE_REF);
}
out_stream.write(reinterpret_cast<const char *>(&properties), sizeof(properties));
@@ -406,7 +404,7 @@ std::shared_ptr<RestrictionMap> Extractor::LoadRestrictionMap()
util::loadRestrictionsFromFile(file_reader, restriction_list);
util::SimpleLogger().Write() << " - " << restriction_list.size() << " restrictions.";
util::Log() << " - " << restriction_list.size() << " restrictions.";
return std::make_shared<RestrictionMap>(restriction_list);
}
@@ -428,16 +426,16 @@ Extractor::LoadNodeBasedGraph(std::unordered_set<NodeID> &barriers,
NodeID number_of_node_based_nodes = util::loadNodesFromFile(
file_reader, barriers_iter, traffic_signals_iter, internal_to_external_node_map);
util::SimpleLogger().Write() << " - " << barriers.size() << " bollard nodes, "
<< traffic_signals.size() << " traffic lights";
util::Log() << " - " << barriers.size() << " bollard nodes, " << traffic_signals.size()
<< " traffic lights";
std::vector<NodeBasedEdge> edge_list;
util::loadEdgesFromFile(file_reader, edge_list);
if (edge_list.empty())
{
util::SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
return std::shared_ptr<util::NodeBasedDynamicGraph>();
throw util::exception("Node-based-graph (" + config.output_file_name +
") contains no edges." + SOURCE_REF);
}
return util::NodeBasedDynamicGraphFromEdges(number_of_node_based_nodes, edge_list);
@@ -541,9 +539,9 @@ void Extractor::BuildRTree(std::vector<EdgeBasedNode> node_based_edge_list,
std::vector<bool> node_is_startpoint,
const std::vector<QueryNode> &internal_to_external_node_map)
{
util::SimpleLogger().Write() << "constructing r-tree of " << node_based_edge_list.size()
<< " edge elements build on-top of "
<< internal_to_external_node_map.size() << " coordinates";
util::Log() << "constructing r-tree of " << node_based_edge_list.size()
<< " edge elements build on-top of " << internal_to_external_node_map.size()
<< " coordinates";
BOOST_ASSERT(node_is_startpoint.size() == node_based_edge_list.size());
@@ -564,7 +562,8 @@ void Extractor::BuildRTree(std::vector<EdgeBasedNode> node_based_edge_list,
if (new_size == 0)
{
throw util::exception("There are no snappable edges left after processing. Are you "
"setting travel modes correctly in the profile? Cannot continue.");
"setting travel modes correctly in the profile? Cannot continue." +
SOURCE_REF);
}
node_based_edge_list.resize(new_size);
@@ -575,8 +574,7 @@ void Extractor::BuildRTree(std::vector<EdgeBasedNode> node_based_edge_list,
internal_to_external_node_map);
TIMER_STOP(construction);
util::SimpleLogger().Write() << "finished r-tree construction in " << TIMER_SEC(construction)
<< " seconds";
util::Log() << "finished r-tree construction in " << TIMER_SEC(construction) << " seconds";
}
void Extractor::WriteEdgeBasedGraph(
@@ -590,8 +588,7 @@ void Extractor::WriteEdgeBasedGraph(
const util::FingerPrint fingerprint = util::FingerPrint::GetValid();
file_out_stream.write((char *)&fingerprint, sizeof(util::FingerPrint));
util::SimpleLogger().Write() << "[extractor] Writing edge-based-graph edges ... "
<< std::flush;
util::Log() << "Writing edge-based-graph edges ... " << std::flush;
TIMER_START(write_edges);
std::uint64_t number_of_used_edges = edge_based_edge_list.size();
@@ -604,9 +601,9 @@ void Extractor::WriteEdgeBasedGraph(
}
TIMER_STOP(write_edges);
util::SimpleLogger().Write() << "ok, after " << TIMER_SEC(write_edges) << "s" << std::endl;
util::Log() << "ok, after " << TIMER_SEC(write_edges) << "s";
util::SimpleLogger().Write() << "Processed " << number_of_used_edges << " edges";
util::Log() << "Processed " << number_of_used_edges << " edges";
}
void Extractor::WriteIntersectionClassificationData(
@@ -618,12 +615,11 @@ void Extractor::WriteIntersectionClassificationData(
std::ofstream file_out_stream(output_file_name.c_str(), std::ios::binary);
if (!file_out_stream)
{
util::SimpleLogger().Write(logWARNING) << "Failed to open " << output_file_name
<< " for writing";
util::Log(logERROR) << "Failed to open " << output_file_name << " for writing";
return;
}
util::SimpleLogger().Write() << "Writing Intersection Classification Data";
util::Log() << "Writing Intersection Classification Data";
TIMER_START(write_edges);
util::writeFingerprint(file_out_stream);
util::serializeVector(file_out_stream, node_based_intersection_classes);
@@ -652,16 +648,15 @@ void Extractor::WriteIntersectionClassificationData(
if (!static_cast<bool>(file_out_stream))
{
throw util::exception("Failed to write to " + output_file_name + ".");
throw util::exception("Failed to write to " + output_file_name + "." + SOURCE_REF);
}
util::serializeVector(file_out_stream, entry_classes);
TIMER_STOP(write_edges);
util::SimpleLogger().Write() << "ok, after " << TIMER_SEC(write_edges) << "s for "
<< node_based_intersection_classes.size() << " Indices into "
<< bearing_classes.size() << " bearing classes and "
<< entry_classes.size() << " entry classes and " << total_bearings
<< " bearing values." << std::endl;
util::Log() << "ok, after " << TIMER_SEC(write_edges) << "s for "
<< node_based_intersection_classes.size() << " Indices into "
<< bearing_classes.size() << " bearing classes and " << entry_classes.size()
<< " entry classes and " << total_bearings << " bearing values.";
}
void Extractor::WriteTurnLaneData(const std::string &turn_lane_file) const
@@ -671,27 +666,26 @@ void Extractor::WriteTurnLaneData(const std::string &turn_lane_file) const
std::vector<guidance::TurnLaneType::Mask> turn_lane_masks;
std::tie(turn_lane_offsets, turn_lane_masks) = transformTurnLaneMapIntoArrays(turn_lane_map);
util::SimpleLogger().Write() << "Writing turn lane masks...";
util::Log() << "Writing turn lane masks...";
TIMER_START(turn_lane_timer);
std::ofstream ofs(turn_lane_file, std::ios::binary);
if (!ofs)
throw osrm::util::exception("Failed to open " + turn_lane_file + " for writing.");
throw osrm::util::exception("Failed to open " + turn_lane_file + " for writing." +
SOURCE_REF);
if (!util::serializeVector(ofs, turn_lane_offsets))
{
util::SimpleLogger().Write(logWARNING) << "Error while writing.";
return;
throw util::exception("Error while writing to " + turn_lane_file + SOURCE_REF);
}
if (!util::serializeVector(ofs, turn_lane_masks))
{
util::SimpleLogger().Write(logWARNING) << "Error while writing.";
return;
throw util::exception("Error while writing to " + turn_lane_file + SOURCE_REF);
}
TIMER_STOP(turn_lane_timer);
util::SimpleLogger().Write() << "done (" << TIMER_SEC(turn_lane_timer) << ")";
util::Log() << "done (" << TIMER_SEC(turn_lane_timer) << ")";
}
} // namespace extractor