replace all timing by C++11's chrono

This commit is contained in:
Dennis Luxen 2014-05-06 18:15:45 +02:00
parent ffddea75a4
commit c1e7ba7118
9 changed files with 103 additions and 294 deletions

View File

@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ExtractionContainers.h" #include "ExtractionContainers.h"
#include "ExtractionWay.h" #include "ExtractionWay.h"
#include "../Util/SimpleLogger.h" #include "../Util/SimpleLogger.h"
#include "../Util/TimingUtil.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
@ -59,7 +58,7 @@ void ExtractionContainers::PrepareData(
try { try {
unsigned number_of_used_nodes = 0; unsigned number_of_used_nodes = 0;
unsigned number_of_used_edges = 0; unsigned number_of_used_edges = 0;
double time = get_timestamp(); std::chrono::time_point<std::chrono::steady_clock> time1 = std::chrono::steady_clock::now();
std::cout << "[extractor] Sorting used nodes ... " << std::flush; std::cout << "[extractor] Sorting used nodes ... " << std::flush;
stxxl::sort( stxxl::sort(
@ -68,14 +67,19 @@ void ExtractionContainers::PrepareData(
Cmp(), Cmp(),
4294967296 4294967296
); );
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; std::chrono::time_point<std::chrono::steady_clock> time2 = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
time = get_timestamp(); time1 = std::chrono::steady_clock::now();
std::cout << "[extractor] Erasing duplicate nodes ... " << std::flush; std::cout << "[extractor] Erasing duplicate nodes ... " << std::flush;
stxxl::vector<NodeID>::iterator NewEnd = std::unique ( used_node_id_list.begin(),used_node_id_list.end() ) ; stxxl::vector<NodeID>::iterator NewEnd = std::unique ( used_node_id_list.begin(),used_node_id_list.end() ) ;
used_node_id_list.resize ( NewEnd - used_node_id_list.begin() ); used_node_id_list.resize ( NewEnd - used_node_id_list.begin() );
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
time = get_timestamp(); elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
time1 = std::chrono::steady_clock::now();
std::cout << "[extractor] Sorting all nodes ... " << std::flush; std::cout << "[extractor] Sorting all nodes ... " << std::flush;
stxxl::sort( stxxl::sort(
@ -84,8 +88,11 @@ void ExtractionContainers::PrepareData(
CmpNodeByID(), CmpNodeByID(),
4294967296 4294967296
); );
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
time = get_timestamp(); elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
time1 = std::chrono::steady_clock::now();
std::cout << "[extractor] Sorting used ways ... " << std::flush; std::cout << "[extractor] Sorting used ways ... " << std::flush;
stxxl::sort( stxxl::sort(
@ -94,7 +101,10 @@ void ExtractionContainers::PrepareData(
CmpWayByID(), CmpWayByID(),
4294967296 4294967296
); );
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
std::cout << "[extractor] Sorting restrictions. by from... " << std::flush; std::cout << "[extractor] Sorting restrictions. by from... " << std::flush;
stxxl::sort( stxxl::sort(
@ -103,7 +113,10 @@ void ExtractionContainers::PrepareData(
CmpRestrictionContainerByFrom(), CmpRestrictionContainerByFrom(),
4294967296 4294967296
); );
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
std::cout << "[extractor] Fixing restriction starts ... " << std::flush; std::cout << "[extractor] Fixing restriction starts ... " << std::flush;
STXXLRestrictionsVector::iterator restrictions_iterator = restrictions_list.begin(); STXXLRestrictionsVector::iterator restrictions_iterator = restrictions_list.begin();
@ -139,8 +152,11 @@ void ExtractionContainers::PrepareData(
++restrictions_iterator; ++restrictions_iterator;
} }
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
time = get_timestamp(); elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
time1 = std::chrono::steady_clock::now();
std::cout << "[extractor] Sorting restrictions. by to ... " << std::flush; std::cout << "[extractor] Sorting restrictions. by to ... " << std::flush;
stxxl::sort( stxxl::sort(
@ -149,9 +165,12 @@ void ExtractionContainers::PrepareData(
CmpRestrictionContainerByTo(), CmpRestrictionContainerByTo(),
4294967296 4294967296
); );
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
time = get_timestamp();
time1 = std::chrono::steady_clock::now();
unsigned usableRestrictionsCounter(0); unsigned usableRestrictionsCounter(0);
std::cout << "[extractor] Fixing restriction ends ... " << std::flush; std::cout << "[extractor] Fixing restriction ends ... " << std::flush;
restrictions_iterator = restrictions_list.begin(); restrictions_iterator = restrictions_list.begin();
@ -187,7 +206,10 @@ void ExtractionContainers::PrepareData(
} }
++restrictions_iterator; ++restrictions_iterator;
} }
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
SimpleLogger().Write() << "usable restrictions: " << usableRestrictionsCounter; SimpleLogger().Write() << "usable restrictions: " << usableRestrictionsCounter;
//serialize restrictions //serialize restrictions
std::ofstream restrictions_out_stream; std::ofstream restrictions_out_stream;
@ -218,7 +240,7 @@ void ExtractionContainers::PrepareData(
file_out_stream.open(output_file_name.c_str(), std::ios::binary); file_out_stream.open(output_file_name.c_str(), std::ios::binary);
file_out_stream.write((char*)&uuid, sizeof(UUID)); file_out_stream.write((char*)&uuid, sizeof(UUID));
file_out_stream.write((char*)&number_of_used_nodes, sizeof(unsigned)); file_out_stream.write((char*)&number_of_used_nodes, sizeof(unsigned));
time = get_timestamp(); time1 = std::chrono::steady_clock::now();
std::cout << "[extractor] Confirming/Writing used nodes ... " << std::flush; std::cout << "[extractor] Confirming/Writing used nodes ... " << std::flush;
//identify all used nodes by a merging step of two sorted lists //identify all used nodes by a merging step of two sorted lists
@ -248,7 +270,10 @@ void ExtractionContainers::PrepareData(
++node_iterator; ++node_iterator;
} }
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
std::cout << "[extractor] setting number of nodes ... " << std::flush; std::cout << "[extractor] setting number of nodes ... " << std::flush;
std::ios::pos_type previous_file_position = file_out_stream.tellp(); std::ios::pos_type previous_file_position = file_out_stream.tellp();
@ -257,7 +282,7 @@ void ExtractionContainers::PrepareData(
file_out_stream.seekp(previous_file_position); file_out_stream.seekp(previous_file_position);
std::cout << "ok" << std::endl; std::cout << "ok" << std::endl;
time = get_timestamp(); time1 = std::chrono::steady_clock::now();
// Sort edges by start. // Sort edges by start.
std::cout << "[extractor] Sorting edges by start ... " << std::flush; std::cout << "[extractor] Sorting edges by start ... " << std::flush;
@ -267,8 +292,11 @@ void ExtractionContainers::PrepareData(
CmpEdgeByStartID(), CmpEdgeByStartID(),
4294967296 4294967296
); );
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
time = get_timestamp(); elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
time1 = std::chrono::steady_clock::now();
std::cout << "[extractor] Setting start coords ... " << std::flush; std::cout << "[extractor] Setting start coords ... " << std::flush;
file_out_stream.write((char*)&number_of_used_edges, sizeof(unsigned)); file_out_stream.write((char*)&number_of_used_edges, sizeof(unsigned));
@ -293,8 +321,11 @@ void ExtractionContainers::PrepareData(
edge_iterator->startCoord.lon = node_iterator->lon; edge_iterator->startCoord.lon = node_iterator->lon;
++edge_iterator; ++edge_iterator;
} }
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
time = get_timestamp(); elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
time1 = std::chrono::steady_clock::now();
// Sort Edges by target // Sort Edges by target
std::cout << "[extractor] Sorting edges by target ... " << std::flush; std::cout << "[extractor] Sorting edges by target ... " << std::flush;
@ -304,8 +335,11 @@ void ExtractionContainers::PrepareData(
CmpEdgeByTargetID(), CmpEdgeByTargetID(),
4294967296 4294967296
); );
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
time = get_timestamp(); elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
time1 = std::chrono::steady_clock::now();
std::cout << "[extractor] Setting target coords ... " << std::flush; std::cout << "[extractor] Setting target coords ... " << std::flush;
// Traverse list of edges and nodes in parallel and set target coord // Traverse list of edges and nodes in parallel and set target coord
@ -399,14 +433,17 @@ void ExtractionContainers::PrepareData(
} }
++edge_iterator; ++edge_iterator;
} }
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
std::cout << "[extractor] setting number of edges ... " << std::flush; std::cout << "[extractor] setting number of edges ... " << std::flush;
file_out_stream.seekp(previous_file_position); file_out_stream.seekp(previous_file_position);
file_out_stream.write((char*)&number_of_used_edges, sizeof(unsigned)); file_out_stream.write((char*)&number_of_used_edges, sizeof(unsigned));
file_out_stream.close(); file_out_stream.close();
std::cout << "ok" << std::endl; std::cout << "ok" << std::endl;
time = get_timestamp(); time1 = std::chrono::steady_clock::now();
std::cout << "[extractor] writing street name index ... " << std::flush; std::cout << "[extractor] writing street name index ... " << std::flush;
std::string name_file_streamName = (output_file_name + ".names"); std::string name_file_streamName = (output_file_name + ".names");
@ -451,7 +488,10 @@ void ExtractionContainers::PrepareData(
} }
name_file_stream.close(); name_file_stream.close();
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; time2 = std::chrono::steady_clock::now();
elapsed_seconds = time2-time1;
std::cout << "ok, after " << elapsed_seconds.count() << "s" << std::endl;
SimpleLogger().Write() << "Processed " << SimpleLogger().Write() << "Processed " <<
number_of_used_nodes << " nodes and " << number_of_used_nodes << " nodes and " <<
number_of_used_edges << " edges"; number_of_used_edges << " edges";

View File

@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "BasicRoutingInterface.h" #include "BasicRoutingInterface.h"
#include "../DataStructures/SearchEngineData.h" #include "../DataStructures/SearchEngineData.h"
#include "../Util/TimingUtil.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>

View File

@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../DataStructures/QueryEdge.h" #include "../DataStructures/QueryEdge.h"
#include "../DataStructures/TurnInstructions.h" #include "../DataStructures/TurnInstructions.h"
#include "../Util/GraphLoader.h" #include "../Util/GraphLoader.h"
#include "../Util/InputFileUtil.h"
#include "../Util/OSRMException.h" #include "../Util/OSRMException.h"
#include "../Util/SimpleLogger.h" #include "../Util/SimpleLogger.h"
#include "../Util/UUID.h" #include "../Util/UUID.h"

View File

@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../Util/GitDescription.h" #include "../Util/GitDescription.h"
#include "../Util/OSRMException.h" #include "../Util/OSRMException.h"
#include "../Util/SimpleLogger.h" #include "../Util/SimpleLogger.h"
#include "../Util/TimingUtil.h"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
@ -100,35 +99,36 @@ int main(int argc, char *argv[])
throw OSRMException("Data file already exists"); throw OSRMException("Data file already exists");
} }
double time1, time2; std::chrono::time_point<std::chrono::steady_clock> time1, time2;
int *random_array = new int[number_of_elements]; int *random_array = new int[number_of_elements];
std::generate(random_array, random_array + number_of_elements, std::rand); std::generate(random_array, random_array + number_of_elements, std::rand);
#ifdef __APPLE__ #ifdef __APPLE__
FILE *fd = fopen(test_path.string().c_str(), "w"); FILE *fd = fopen(test_path.string().c_str(), "w");
fcntl(fileno(fd), F_NOCACHE, 1); fcntl(fileno(fd), F_NOCACHE, 1);
fcntl(fileno(fd), F_RDAHEAD, 0); fcntl(fileno(fd), F_RDAHEAD, 0);
time1 = get_timestamp(); time1 = std::chrono::steady_clock::now();
write(fileno(fd), (char *)random_array, number_of_elements * sizeof(unsigned)); write(fileno(fd), (char *)random_array, number_of_elements * sizeof(unsigned));
time2 = get_timestamp(); time2 = std::chrono::steady_clock::now();;
fclose(fd); fclose(fd);
#endif #endif
#ifdef __linux__ #ifdef __linux__
int f = int f =
open(test_path.string().c_str(), O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, S_IRWXU); open(test_path.string().c_str(), O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, S_IRWXU);
time1 = get_timestamp(); time1 = std::chrono::steady_clock::now();
int ret = write(f, random_array, number_of_elements * sizeof(unsigned)); int ret = write(f, random_array, number_of_elements * sizeof(unsigned));
if (-1 == ret) if (-1 == ret)
{ {
throw OSRMException("could not write random data file"); throw OSRMException("could not write random data file");
} }
time2 = get_timestamp(); time2 = std::chrono::steady_clock::now();
close(f); close(f);
#endif #endif
std::chrono::duration<double> elapsed_seconds = time2-time1;
delete[] random_array; delete[] random_array;
SimpleLogger().Write(logDEBUG) << "writing raw 1GB took " << (time2 - time1) * 1000 SimpleLogger().Write(logDEBUG) << "writing raw 1GB took " << elapsed_seconds.count()
<< "ms"; << "ms";
SimpleLogger().Write() << "raw write performance: " << std::setprecision(5) SimpleLogger().Write() << "raw write performance: " << std::setprecision(5)
<< std::fixed << 1024 * 1024 / ((time2 - time1) * 1000) << std::fixed << 1024 * 1024 / (elapsed_seconds.count())
<< "MB/sec"; << "MB/sec";
SimpleLogger().Write(logDEBUG) SimpleLogger().Write(logDEBUG)
@ -146,7 +146,7 @@ int main(int argc, char *argv[])
throw OSRMException("data file does not exist"); throw OSRMException("data file does not exist");
} }
double time1, time2; std::chrono::time_point<std::chrono::steady_clock> time1, time2;
// volatiles do not get optimized // volatiles do not get optimized
Statistics stats; Statistics stats;
@ -168,7 +168,7 @@ int main(int argc, char *argv[])
} }
char *raw_array = (char *)memalign(512, number_of_elements * sizeof(unsigned)); char *raw_array = (char *)memalign(512, number_of_elements * sizeof(unsigned));
#endif #endif
time1 = get_timestamp(); time1 = std::chrono::steady_clock::now();
#ifdef __APPLE__ #ifdef __APPLE__
read(fileno(fd), raw_array, number_of_elements * sizeof(unsigned)); read(fileno(fd), raw_array, number_of_elements * sizeof(unsigned));
close(fileno(fd)); close(fileno(fd));
@ -182,12 +182,13 @@ int main(int argc, char *argv[])
f = open(test_path.string().c_str(), O_RDONLY | O_DIRECT | O_SYNC); f = open(test_path.string().c_str(), O_RDONLY | O_DIRECT | O_SYNC);
SimpleLogger().Write(logDEBUG) << "opened, error: " << strerror(errno); SimpleLogger().Write(logDEBUG) << "opened, error: " << strerror(errno);
#endif #endif
time2 = get_timestamp(); time2 = std::chrono::steady_clock::now();
SimpleLogger().Write(logDEBUG) << "reading raw 1GB took " << (time2 - time1) * 1000 std::chrono::duration<double> elapsed_seconds = time2-time1;
SimpleLogger().Write(logDEBUG) << "reading raw 1GB took " << elapsed_seconds.count()
<< "ms"; << "ms";
SimpleLogger().Write() << "raw read performance: " << std::setprecision(5) << std::fixed SimpleLogger().Write() << "raw read performance: " << std::setprecision(5) << std::fixed
<< 1024 * 1024 / ((time2 - time1) * 1000) << "MB/sec"; << 1024 * 1024 / (elapsed_seconds.count()) << "MB/sec";
std::vector<double> timing_results_raw_random; std::vector<double> timing_results_raw_random;
SimpleLogger().Write(logDEBUG) << "running 1000 random I/Os of 4KB"; SimpleLogger().Write(logDEBUG) << "running 1000 random I/Os of 4KB";
@ -204,7 +205,7 @@ int main(int argc, char *argv[])
{ {
unsigned block_to_read = std::rand() % number_of_blocks; unsigned block_to_read = std::rand() % number_of_blocks;
off_t current_offset = block_to_read * 4096; off_t current_offset = block_to_read * 4096;
time1 = get_timestamp(); time1 = std::chrono::steady_clock::now();
#ifdef __APPLE__ #ifdef __APPLE__
int ret1 = fseek(fd, current_offset, SEEK_SET); int ret1 = fseek(fd, current_offset, SEEK_SET);
int ret2 = read(fileno(fd), (char *)&single_block[0], 4096); int ret2 = read(fileno(fd), (char *)&single_block[0], 4096);
@ -219,7 +220,7 @@ int main(int argc, char *argv[])
int ret1 = lseek(f, current_offset, SEEK_SET); int ret1 = lseek(f, current_offset, SEEK_SET);
int ret2 = read(f, (char *)single_block, 4096); int ret2 = read(f, (char *)single_block, 4096);
#endif #endif
time2 = get_timestamp(); time2 = std::chrono::steady_clock::now();
if (((off_t) - 1) == ret1) if (((off_t) - 1) == ret1)
{ {
SimpleLogger().Write(logWARNING) << "offset: " << current_offset; SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
@ -232,7 +233,7 @@ int main(int argc, char *argv[])
SimpleLogger().Write(logWARNING) << "read error " << strerror(errno); SimpleLogger().Write(logWARNING) << "read error " << strerror(errno);
throw OSRMException("read error"); throw OSRMException("read error");
} }
timing_results_raw_random.push_back((time2 - time1) * 1000.); timing_results_raw_random.push_back(elapsed_seconds.count());
} }
// Do statistics // Do statistics
@ -264,7 +265,7 @@ int main(int argc, char *argv[])
for (unsigned i = 0; i < 1000; ++i) for (unsigned i = 0; i < 1000; ++i)
{ {
off_t current_offset = i * 4096; off_t current_offset = i * 4096;
time1 = get_timestamp(); time1 = std::chrono::steady_clock::now();
#ifdef __APPLE__ #ifdef __APPLE__
int ret1 = fseek(fd, current_offset, SEEK_SET); int ret1 = fseek(fd, current_offset, SEEK_SET);
int ret2 = read(fileno(fd), (char *)&single_block, 4096); int ret2 = read(fileno(fd), (char *)&single_block, 4096);
@ -280,7 +281,7 @@ int main(int argc, char *argv[])
int ret2 = read(f, (char *)single_block, 4096); int ret2 = read(f, (char *)single_block, 4096);
#endif #endif
time2 = get_timestamp(); time2 = std::chrono::steady_clock::now();
if (((off_t) - 1) == ret1) if (((off_t) - 1) == ret1)
{ {
SimpleLogger().Write(logWARNING) << "offset: " << current_offset; SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
@ -293,7 +294,7 @@ int main(int argc, char *argv[])
SimpleLogger().Write(logWARNING) << "read error " << strerror(errno); SimpleLogger().Write(logWARNING) << "read error " << strerror(errno);
throw OSRMException("read error"); throw OSRMException("read error");
} }
timing_results_raw_seq.push_back((time2 - time1) * 1000.); timing_results_raw_seq.push_back(elapsed_seconds.count());
} }
#ifdef __APPLE__ #ifdef __APPLE__
fclose(fd); fclose(fd);

View File

@ -1,100 +0,0 @@
/*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "IniFile.h"
#include "OSRMException.h"
#include "../DataStructures/HashTable.h"
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <iostream>
IniFile::IniFile(const char * config_filename) {
boost::filesystem::path config_file(config_filename);
if ( !boost::filesystem::exists( config_file ) ) {
std::string error = std::string(config_filename) + " not found";
throw OSRMException(error);
}
if ( 0 == boost::filesystem::file_size( config_file ) ) {
std::string error = std::string(config_filename) + " is empty";
throw OSRMException(error);
}
boost::filesystem::ifstream config( config_file );
std::string line;
if (config.is_open()) {
while ( config.good() ) {
getline (config,line);
std::vector<std::string> tokens;
Tokenize(line, tokens);
if(2 == tokens.size() ) {
parameters.insert(std::make_pair(tokens[0], tokens[1]));
}
}
config.close();
}
}
std::string IniFile::GetParameter(const std::string & key){
return parameters.Find(key);
}
std::string IniFile::GetParameter(const std::string & key) const {
return parameters.Find(key);
}
bool IniFile::Holds(const std::string & key) const {
return parameters.Holds(key);
}
void IniFile::SetParameter(const char* key, const char* value) {
SetParameter(std::string(key), std::string(value));
}
void IniFile::SetParameter(const std::string & key, const std::string & value) {
parameters.insert(std::make_pair(key, value));
}
void IniFile::Tokenize(
const std::string& str,
std::vector<std::string>& tokens,
const std::string& delimiters
) {
std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
std::string::size_type pos = str.find_first_of(delimiters, lastPos);
while (std::string::npos != pos || std::string::npos != lastPos) {
std::string temp = str.substr(lastPos, pos - lastPos);
boost::trim(temp);
tokens.push_back( temp );
lastPos = str.find_first_not_of(delimiters, pos);
pos = str.find_first_of(delimiters, lastPos);
}
}

View File

@ -1,60 +0,0 @@
/*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef INI_FILE_H_
#define INI_FILE_H_
#include "../DataStructures/HashTable.h"
#include <string>
#include <vector>
class IniFile {
public:
explicit IniFile(const char * config_filename);
std::string GetParameter(const std::string & key);
std::string GetParameter(const std::string & key) const;
bool Holds(const std::string & key) const;
void SetParameter(const char* key, const char* value);
void SetParameter(const std::string & key, const std::string & value);
private:
void Tokenize(
const std::string& str,
std::vector<std::string>& tokens,
const std::string& delimiters = "="
);
HashTable<std::string, std::string> parameters;
};
#endif /* INI_FILE_H_ */

View File

@ -1,71 +0,0 @@
/*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TIMINGUTIL_H_
#define TIMINGUTIL_H_
// excluded as this requires boost 1.47 (for now)
// #include <boost/chrono.hpp>
// #include <boost/timer/timer.hpp>
// static boost::timer::cpu_timer my_timer;
// /** Returns a timestamp (now) in seconds (incl. a fractional part). */
// static inline double get_timestamp() {
// boost::chrono::duration<double> duration = boost::chrono::nanoseconds(
// my_timer.elapsed().user + my_timer.elapsed().system +
// my_timer.elapsed().wall
// );
// return duration.count();
// }
#include <climits>
#include <cstdlib>
#ifdef _WIN32
#include <sys/timeb.h>
#include <sys/types.h>
#include <winsock.h>
void gettimeofday(struct timeval* t,void* timezone) {
struct _timeb timebuffer;
_ftime( &timebuffer );
t->tv_sec=timebuffer.time;
t->tv_usec=1000*timebuffer.millitm;
}
#else
#include <sys/time.h>
#endif
/** Returns a timestamp (now) in seconds (incl. a fractional part). */
static inline double get_timestamp() {
struct timeval tp;
gettimeofday(&tp, NULL);
return double(tp.tv_sec) + tp.tv_usec / 1000000.;
}
#endif /* TIMINGUTIL_H_ */

View File

@ -35,11 +35,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "DataStructures/StaticRTree.h" #include "DataStructures/StaticRTree.h"
#include "Util/GitDescription.h" #include "Util/GitDescription.h"
#include "Util/GraphLoader.h" #include "Util/GraphLoader.h"
#include "Util/InputFileUtil.h"
#include "Util/LuaUtil.h" #include "Util/LuaUtil.h"
#include "Util/OpenMPWrapper.h" #include "Util/OpenMPWrapper.h"
#include "Util/OSRMException.h" #include "Util/OSRMException.h"
#include "Util/TimingUtil.h"
#include "Util/SimpleLogger.h" #include "Util/SimpleLogger.h"
#include "Util/StringUtil.h" #include "Util/StringUtil.h"
#include "typedefs.h" #include "typedefs.h"
@ -50,6 +49,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <luabind/luabind.hpp> #include <luabind/luabind.hpp>
#include <chrono>
#include <string> #include <string>
#include <vector> #include <vector>
@ -66,7 +66,8 @@ std::vector<ImportEdge> edgeList;
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
try { try {
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
double startupTime = get_timestamp(); std::chrono::time_point<std::chrono::steady_clock> startupTime = std::chrono::steady_clock::now();
boost::filesystem::path config_file_path, input_path, restrictions_path, profile_path; boost::filesystem::path config_file_path, input_path, restrictions_path, profile_path;
int requested_num_threads; int requested_num_threads;
@ -267,8 +268,7 @@ int main (int argc, char *argv[]) {
edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList); edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList);
delete edgeBasedGraphFactory; delete edgeBasedGraphFactory;
double expansionHasFinishedTime = get_timestamp() - startupTime; std::chrono::duration<double> expansionHasFinishedTime = std::chrono::steady_clock::now() - startupTime;
// Building grid-like nearest-neighbor data structure // Building grid-like nearest-neighbor data structure
SimpleLogger().Write() << "building r-tree ..."; SimpleLogger().Write() << "building r-tree ...";
@ -307,12 +307,13 @@ int main (int argc, char *argv[]) {
SimpleLogger().Write() << "initializing contractor"; SimpleLogger().Write() << "initializing contractor";
Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList ); Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList );
double contractionStartedTimestamp(get_timestamp()); std::chrono::time_point<std::chrono::steady_clock> contraction_start_timestamp = std::chrono::steady_clock::now();
contractor->Run(); contractor->Run();
const double contraction_duration = (get_timestamp() - contractionStartedTimestamp); std::chrono::duration<double> contraction_duration = std::chrono::steady_clock::now() - contraction_start_timestamp;
SimpleLogger().Write() << SimpleLogger().Write() <<
"Contraction took " << "Contraction took " <<
contraction_duration << contraction_duration.count() <<
" sec"; " sec";
DeallocatingVector< QueryEdge > contractedEdgeList; DeallocatingVector< QueryEdge > contractedEdgeList;
@ -414,15 +415,16 @@ int main (int argc, char *argv[]) {
} }
hsgr_output_stream.close(); hsgr_output_stream.close();
SimpleLogger().Write() << "Preprocessing : " << std::chrono::duration<double> entire_duration = std::chrono::steady_clock::now() - startupTime;
(get_timestamp() - startupTime) << " seconds";
SimpleLogger().Write() << "Preprocessing : " << entire_duration.count() << " seconds";
SimpleLogger().Write() << "Expansion : " << SimpleLogger().Write() << "Expansion : " <<
(nodeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and " << (nodeBasedNodeNumber/expansionHasFinishedTime.count()) << " nodes/sec and " <<
(edgeBasedNodeNumber/expansionHasFinishedTime) << " edges/sec"; (edgeBasedNodeNumber/expansionHasFinishedTime.count()) << " edges/sec";
SimpleLogger().Write() << "Contraction: " << SimpleLogger().Write() << "Contraction: " <<
(edgeBasedNodeNumber/contraction_duration) << " nodes/sec and " << (edgeBasedNodeNumber/contraction_duration.count()) << " nodes/sec and " <<
usedEdgeCounter/contraction_duration << " edges/sec"; usedEdgeCounter/contraction_duration.count() << " edges/sec";
node_array.clear(); node_array.clear();
SimpleLogger().Write() << "finished preprocessing"; SimpleLogger().Write() << "finished preprocessing";

View File

@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Server/ServerFactory.h" #include "Server/ServerFactory.h"
#include "Util/GitDescription.h" #include "Util/GitDescription.h"
#include "Util/InputFileUtil.h"
#include "Util/ProgramOptions.h" #include "Util/ProgramOptions.h"
#include "Util/SimpleLogger.h" #include "Util/SimpleLogger.h"
#include "Util/UUID.h" #include "Util/UUID.h"