1
0
Fork 0

Use SGTimestamp for statistics gathering.

Use time(0) and standard C++ <ctime> for date / time
This commit is contained in:
Peter Sadrozinski 2012-03-31 22:09:18 -04:00
parent 7777fc4bc2
commit cf5bb76ee8
3 changed files with 58 additions and 101 deletions

View file

@ -6,6 +6,7 @@
#include <list> #include <list>
#include <map> #include <map>
#include <string> #include <string>
#include <ctime>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/structure/exception.hxx> #include <simgear/structure/exception.hxx>
@ -468,15 +469,13 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
// parse main airport information // parse main airport information
double apt_lon = 0.0, apt_lat = 0.0; double apt_lon = 0.0, apt_lat = 0.0;
#if !defined(_MSC_VER) SGTimeStamp build_start;
struct timeval build_start; SGTimeStamp build_end;
struct timeval build_end; SGTimeStamp cleanup_start;
struct timeval cleanup_start; SGTimeStamp cleanup_end;
struct timeval cleanup_end; SGTimeStamp triangulation_start;
struct timeval triangulation_start; SGTimeStamp triangulation_end;
struct timeval triangulation_end; time_t log_time;
struct timeval log_time;
#endif
// Find the average of all the runway and heliport long / lats // Find the average of all the runway and heliport long / lats
int num_samples = 0; int num_samples = 0;
@ -511,9 +510,7 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
} }
// Starting to clip the polys (for now - only UNIX builds) // Starting to clip the polys (for now - only UNIX builds)
#if !defined(_MSC_VER) build_start.stamp();
gettimeofday(&build_start, NULL);
#endif
// Add the linear features // Add the linear features
if (features.size()) if (features.size())
@ -538,10 +535,8 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
SG_LOG(SG_GENERAL, SG_DEBUG, "no markings"); SG_LOG(SG_GENERAL, SG_DEBUG, "no markings");
} }
#if !defined(_MSC_VER) log_time = time(0);
gettimeofday(&log_time, NULL); SG_LOG( SG_GENERAL, SG_ALERT, "Finished building Linear Features for " << icao << " at " << ctime(&log_time) );
SG_LOG( SG_GENERAL, SG_ALERT, "Finished building Linear Features for " << icao << " at " << ctime(&log_time.tv_sec) );
#endif
// Build runways next // Build runways next
for ( unsigned int i=0; i<runways.size(); i++ ) for ( unsigned int i=0; i<runways.size(); i++ )
@ -565,10 +560,8 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
merge_slivers( rwy_polys, slivers ); merge_slivers( rwy_polys, slivers );
} }
#if !defined(_MSC_VER) log_time = time(0);
gettimeofday(&log_time, NULL); SG_LOG( SG_GENERAL, SG_ALERT, "Finished building runways for " << icao << " at " << ctime(&log_time) );
SG_LOG( SG_GENERAL, SG_ALERT, "Finished building runways for " << icao << " at " << ctime(&log_time.tv_sec) );
#endif
if (lightobjects.size()) if (lightobjects.size())
{ {
@ -636,10 +629,8 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
SG_LOG(SG_GENERAL, SG_DEBUG, "no pavements"); SG_LOG(SG_GENERAL, SG_DEBUG, "no pavements");
} }
#if !defined(_MSC_VER) log_time = time(0);
gettimeofday(&log_time, NULL); SG_LOG( SG_GENERAL, SG_ALERT, "Finished building Pavements for " << icao << " at " << ctime(&log_time) );
SG_LOG( SG_GENERAL, SG_ALERT, "Finished building pavements for " << icao << " at " << ctime(&log_time.tv_sec) );
#endif
// Build runway shoulders here // Build runway shoulders here
#if 0 #if 0
@ -677,15 +668,10 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
TGPolygon divided_base = tgPolygonSplitLongEdges( filled_base, 200.0 ); TGPolygon divided_base = tgPolygonSplitLongEdges( filled_base, 200.0 );
TGPolygon base_poly = tgPolygonDiffClipper( divided_base, accum ); TGPolygon base_poly = tgPolygonDiffClipper( divided_base, accum );
#if !defined(_MSC_VER) build_end.stamp();
gettimeofday(&build_end, NULL); build_time = build_end - build_start;
timersub(&build_end, &build_start, &build_time);
#endif
cleanup_start.stamp();
#if !defined(_MSC_VER)
gettimeofday(&cleanup_start, NULL);
#endif
// add segments to polygons to remove any possible "T" // add segments to polygons to remove any possible "T"
// intersections // intersections
@ -752,10 +738,8 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
} }
} }
#if !defined(_MSC_VER) log_time = time(0);
gettimeofday(&log_time, NULL); SG_LOG( SG_GENERAL, SG_ALERT, "Finished collecting nodes for " << icao << " at " << ctime(&log_time) );
SG_LOG( SG_GENERAL, SG_ALERT, "Finished collecting nodes for " << icao << " at " << ctime(&log_time.tv_sec) );
#endif
// second pass : runways // second pass : runways
for ( unsigned int k = 0; k < rwy_polys.size(); ++k ) for ( unsigned int k = 0; k < rwy_polys.size(); ++k )
@ -784,10 +768,8 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
line_polys[k].set_poly( poly ); line_polys[k].set_poly( poly );
} }
#if !defined(_MSC_VER) log_time = time(0);
gettimeofday(&log_time, NULL); SG_LOG( SG_GENERAL, SG_ALERT, "Finished adding intermediate nodes for " << icao << " at " << ctime(&log_time) );
SG_LOG( SG_GENERAL, SG_ALERT, "Finished adding intermediate nodes for " << icao << " at " << ctime(&log_time.tv_sec) );
#endif
for ( unsigned int k = 0; k < line_polys.size(); ++k ) for ( unsigned int k = 0; k < line_polys.size(); ++k )
{ {
@ -806,10 +788,8 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
line_polys[k].set_poly( poly ); line_polys[k].set_poly( poly );
} }
#if !defined(_MSC_VER) log_time = time(0);
gettimeofday(&log_time, NULL); SG_LOG( SG_GENERAL, SG_ALERT, "Finished cleaning polys for " << icao << " at " << ctime(&log_time) );
SG_LOG( SG_GENERAL, SG_ALERT, "Finished cleaning polys for " << icao << " at " << ctime(&log_time.tv_sec) );
#endif
SG_LOG(SG_GENERAL, SG_DEBUG, "add nodes base "); SG_LOG(SG_GENERAL, SG_DEBUG, "add nodes base ");
SG_LOG(SG_GENERAL, SG_DEBUG, " before: " << base_poly); SG_LOG(SG_GENERAL, SG_DEBUG, " before: " << base_poly);
@ -843,14 +823,10 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
pvmt_polys[k].set_poly( poly ); pvmt_polys[k].set_poly( poly );
} }
#if !defined(_MSC_VER) cleanup_end.stamp();
gettimeofday(&cleanup_end, NULL); cleanup_time = cleanup_end - cleanup_start;
timersub(&cleanup_end, &cleanup_start, &cleanup_time);
#endif
#if !defined(_MSC_VER) triangulation_start.stamp();
gettimeofday(&triangulation_start, NULL);
#endif
// tesselate the polygons and prepair them for final output // tesselate the polygons and prepair them for final output
for ( unsigned int i = 0; i < rwy_polys.size(); ++i ) for ( unsigned int i = 0; i < rwy_polys.size(); ++i )
@ -954,10 +930,8 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src )
SG_LOG(SG_GENERAL, SG_INFO, "Tesselating base poly - done : contours = " << base_tris.contours()); SG_LOG(SG_GENERAL, SG_INFO, "Tesselating base poly - done : contours = " << base_tris.contours());
#if !defined(_MSC_VER) triangulation_end.stamp();
gettimeofday(&triangulation_end, NULL); triangulation_time = triangulation_end - triangulation_start;
timersub(&triangulation_end, &triangulation_start, &triangulation_time);
#endif
// //
// We should now have the runway polygons all generated with their // We should now have the runway polygons all generated with their

View file

@ -4,13 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_CONFIG_H #include <simgear/timing/timestamp.hxx>
# include <config.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h> // for timing
#endif
#include "runway.hxx" #include "runway.hxx"
#include "object.hxx" #include "object.hxx"
@ -95,17 +89,17 @@ public:
return icao; return icao;
} }
void GetBuildTime( struct timeval& tm ) void GetBuildTime( SGTimeStamp& tm )
{ {
tm = build_time; tm = build_time;
} }
void GetTriangulationTime( struct timeval& tm ) void GetTriangulationTime( SGTimeStamp& tm )
{ {
tm = triangulation_time; tm = triangulation_time;
} }
void GetCleanupTime( struct timeval& tm ) void GetCleanupTime( SGTimeStamp& tm )
{ {
tm = cleanup_time; tm = cleanup_time;
} }
@ -133,9 +127,9 @@ private:
ClosedPoly* boundary; ClosedPoly* boundary;
// stats // stats
struct timeval build_time; SGTimeStamp build_time;
struct timeval cleanup_time; SGTimeStamp cleanup_time;
struct timeval triangulation_time; SGTimeStamp triangulation_time;
// debug // debug
int dbg_rwy_poly; int dbg_rwy_poly;

View file

@ -1,13 +1,8 @@
#ifdef HAVE_CONFIG_H #include <ctime>
# include <config.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h> // for timing
#endif
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/misc/sgstream.hxx> #include <simgear/misc/sgstream.hxx>
#include <simgear/timing/timestamp.hxx>
#include "parser.hxx" #include "parser.hxx"
@ -335,14 +330,13 @@ void Parser::Parse( string last_apt_file )
{ {
char tmp[2048]; char tmp[2048];
#if !defined(_MSC_VER) SGTimeStamp parse_start;
struct timeval parse_start; SGTimeStamp parse_end;
struct timeval parse_end; SGTimeStamp parse_time;
struct timeval parse_time; SGTimeStamp build_time;
struct timeval build_time; SGTimeStamp clean_time;
struct timeval clean_time; SGTimeStamp triangulation_time;
struct timeval triangulation_time; time_t log_time;
#endif
ifstream in( filename.c_str() ); ifstream in( filename.c_str() );
if ( !in.is_open() ) if ( !in.is_open() )
@ -357,11 +351,10 @@ void Parser::Parse( string last_apt_file )
SetState(STATE_NONE); SetState(STATE_NONE);
in.clear(); in.clear();
#if !defined(_MSC_VER) parse_start.stamp();
gettimeofday(&parse_start, NULL); log_time = time(0);
SG_LOG( SG_GENERAL, SG_ALERT, "\n*******************************************************************" ); SG_LOG( SG_GENERAL, SG_ALERT, "\n*******************************************************************" );
SG_LOG( SG_GENERAL, SG_ALERT, "Parsing airport " << airport_icaos[i] << " at " << parse_positions[i] << " start time " << ctime(&parse_start.tv_sec) ); SG_LOG( SG_GENERAL, SG_ALERT, "Start airport " << airport_icaos[i] << " at " << parse_positions[i] << ": start time " << ctime(&log_time) );
#endif
in.seekg(parse_positions[i], ios::beg); in.seekg(parse_positions[i], ios::beg);
@ -378,33 +371,29 @@ void Parser::Parse( string last_apt_file )
ParseLine(tmp); ParseLine(tmp);
} }
#if !defined(_MSC_VER) parse_end.stamp();
gettimeofday(&parse_end, NULL); parse_time = parse_end - parse_start;
timersub(&parse_end, &parse_start, &parse_time);
SG_LOG( SG_GENERAL, SG_ALERT, "Finished parsing airport " << airport_icaos[i] << " at " << ctime(&parse_end.tv_sec) );
#endif
// write the airport BTG // write the airport BTG
if (cur_airport) if (cur_airport)
{ {
cur_airport->BuildBtg( work_dir, elevation ); cur_airport->BuildBtg( work_dir, elevation );
#if !defined(_MSC_VER)
cur_airport->GetBuildTime( build_time ); cur_airport->GetBuildTime( build_time );
cur_airport->GetCleanupTime( clean_time ); cur_airport->GetCleanupTime( clean_time );
cur_airport->GetTriangulationTime( triangulation_time ); cur_airport->GetTriangulationTime( triangulation_time );
#endif
delete cur_airport; delete cur_airport;
cur_airport = NULL; cur_airport = NULL;
} }
#if !defined(_MSC_VER) log_time = time(0);
SG_LOG( SG_GENERAL, SG_DEBUG, "Time to parse " << parse_time.tv_sec << ":" << parse_time.tv_usec ); SG_LOG( SG_GENERAL, SG_ALERT, "Finished airport " << airport_icaos[i] << ": end time " << ctime(&log_time) );
SG_LOG( SG_GENERAL, SG_DEBUG, "Time to build " << build_time.tv_sec << ":" << build_time.tv_usec );
SG_LOG( SG_GENERAL, SG_DEBUG, "Time to clean up " << clean_time.tv_sec << ":" << clean_time.tv_usec ); SG_LOG( SG_GENERAL, SG_INFO, "Time to parse " << parse_time );
SG_LOG( SG_GENERAL, SG_DEBUG, "Time to triangulate " << triangulation_time.tv_sec << ":" << triangulation_time.tv_usec ); SG_LOG( SG_GENERAL, SG_INFO, "Time to build " << build_time );
#endif SG_LOG( SG_GENERAL, SG_INFO, "Time to clean up " << clean_time );
SG_LOG( SG_GENERAL, SG_INFO, "Time to triangulate " << triangulation_time );
} }
} }