Changeset - r25315:6db91ceda680
[Not reviewed]
master
1 8 0
Patric Stout - 3 years ago 2021-04-30 09:57:37
truebrain@openttd.org
Remove: performance measurements in YAPF

YAPF was constantly measuring its performance, but only at
certain debug-levels this information was shown.

Now after years, I sincerely wonder if anyone still knows about this
feature and who still use it. Especially with the new framerate window,
this detailed performance is not as meaningful anymore as it once
was.
9 files changed with 20 insertions and 137 deletions:
0 comments (0 inline, 0 general)
src/pathfinder/CMakeLists.txt
Show inline comments
 
@@ -5,5 +5,4 @@ add_files(
 
    follow_track.hpp
 
    pathfinder_func.h
 
    pathfinder_type.h
 
    pf_performance_timer.hpp
 
)
src/pathfinder/follow_track.hpp
Show inline comments
 
@@ -18,7 +18,6 @@
 
#include "../tunnelbridge_map.h"
 
#include "../depot_map.h"
 
#include "pathfinder_func.h"
 
#include "pf_performance_timer.hpp"
 

	
 
/**
 
 * Track follower helper template class (can serve pathfinders and vehicle
 
@@ -49,34 +48,32 @@ struct CFollowTrackT
 
	bool                m_is_station;    ///< last turn passed station
 
	int                 m_tiles_skipped; ///< number of skipped tunnel or station tiles
 
	ErrorCode           m_err;
 
	CPerformanceTimer  *m_pPerf;
 
	RailTypes           m_railtypes;
 

	
 
	inline CFollowTrackT(const VehicleType *v = nullptr, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = nullptr)
 
	inline CFollowTrackT(const VehicleType *v = nullptr, RailTypes railtype_override = INVALID_RAILTYPES)
 
	{
 
		Init(v, railtype_override, pPerf);
 
		Init(v, railtype_override);
 
	}
 

	
 
	inline CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = nullptr)
 
	inline CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES)
 
	{
 
		assert(IsRailTT());
 
		m_veh = nullptr;
 
		Init(o, railtype_override, pPerf);
 
		Init(o, railtype_override);
 
	}
 

	
 
	inline void Init(const VehicleType *v, RailTypes railtype_override, CPerformanceTimer *pPerf)
 
	inline void Init(const VehicleType *v, RailTypes railtype_override)
 
	{
 
		assert(!IsRailTT() || (v != nullptr && v->type == VEH_TRAIN));
 
		m_veh = v;
 
		Init(v != nullptr ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override, pPerf);
 
		Init(v != nullptr ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override);
 
	}
 

	
 
	inline void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf)
 
	inline void Init(Owner o, RailTypes railtype_override)
 
	{
 
		assert(!IsRoadTT() || m_veh != nullptr);
 
		assert(!IsRailTT() || railtype_override != INVALID_RAILTYPES);
 
		m_veh_owner = o;
 
		m_pPerf = pPerf;
 
		/* don't worry, all is inlined so compiler should remove unnecessary initializations */
 
		m_old_tile = INVALID_TILE;
 
		m_old_td = INVALID_TRACKDIR;
 
@@ -237,7 +234,6 @@ protected:
 
	/** stores track status (available trackdirs) for the new tile into m_new_td_bits */
 
	inline bool QueryNewTileTrackStatus()
 
	{
 
		CPerfStart perf(*m_pPerf);
 
		if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
 
			m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
 
		} else if (IsRoadTT()) {
src/pathfinder/npf/npf.cpp
Show inline comments
 
@@ -8,6 +8,7 @@
 
/** @file npf.cpp Implementation of the NPF pathfinder. */
 

	
 
#include "../../stdafx.h"
 
#include "../../debug.h"
 
#include "../../network/network.h"
 
#include "../../viewport_func.h"
 
#include "../../ship.h"
src/pathfinder/pf_performance_timer.hpp
Show inline comments
 
deleted file
src/pathfinder/yapf/yapf.hpp
Show inline comments
 
@@ -12,7 +12,6 @@
 

	
 
#include "../../landscape.h"
 
#include "../pathfinder_func.h"
 
#include "../pf_performance_timer.hpp"
 
#include "yapf.h"
 

	
 
#include "../../misc/fixedsizearray.hpp"
src/pathfinder/yapf/yapf_base.hpp
Show inline comments
 
@@ -13,8 +13,6 @@
 
#include "../../debug.h"
 
#include "../../settings_type.h"
 

	
 
extern int _total_pf_time_us;
 

	
 
/**
 
 * CYapfBaseT - A-star type path finder base class.
 
 *  Derive your own pathfinder from it. You must provide the following template argument:
 
@@ -68,12 +66,6 @@ protected:
 
	int                  m_stats_cache_hits;   ///< stats - how many node's costs were reused from cache
 

	
 
public:
 
	CPerformanceTimer    m_perf_cost;          ///< stats - total CPU time of this run
 
	CPerformanceTimer    m_perf_slope_cost;    ///< stats - slope calculation CPU time
 
	CPerformanceTimer    m_perf_ts_cost;       ///< stats - GetTrackStatus() CPU time
 
	CPerformanceTimer    m_perf_other_cost;    ///< stats - other CPU time
 

	
 
public:
 
	int                  m_num_steps;          ///< this is there for debugging purposes (hope it doesn't hurt)
 

	
 
public:
 
@@ -120,9 +112,6 @@ public:
 
	{
 
		m_veh = v;
 

	
 
		CPerformanceTimer perf;
 
		perf.Start();
 

	
 
		Yapf().PfSetStartupNodes();
 
		bool bDestFound = true;
 

	
 
@@ -150,25 +139,18 @@ public:
 

	
 
		bDestFound &= (m_pBestDestNode != nullptr);
 

	
 
		perf.Stop();
 
		if (_debug_yapf_level >= 2) {
 
			int t = perf.Get(1000000);
 
			_total_pf_time_us += t;
 
		if (_debug_yapf_level >= 3) {
 
			UnitID veh_idx = (m_veh != nullptr) ? m_veh->unitnumber : 0;
 
			char ttc = Yapf().TransportTypeChar();
 
			float cache_hit_ratio = (m_stats_cache_hits == 0) ? 0.0f : ((float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f);
 
			int cost = bDestFound ? m_pBestDestNode->m_cost : -1;
 
			int dist = bDestFound ? m_pBestDestNode->m_estimate - m_pBestDestNode->m_cost : -1;
 

	
 
			if (_debug_yapf_level >= 3) {
 
				UnitID veh_idx = (m_veh != nullptr) ? m_veh->unitnumber : 0;
 
				char ttc = Yapf().TransportTypeChar();
 
				float cache_hit_ratio = (m_stats_cache_hits == 0) ? 0.0f : ((float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f);
 
				int cost = bDestFound ? m_pBestDestNode->m_cost : -1;
 
				int dist = bDestFound ? m_pBestDestNode->m_estimate - m_pBestDestNode->m_cost : -1;
 
			DEBUG(yapf, 3, "[YAPF%c]%c%4d- %d rounds - %d open - %d closed - CHR %4.1f%% - C %d D %d",
 
				ttc, bDestFound ? '-' : '!', veh_idx, m_num_steps, m_nodes.OpenCount(), m_nodes.ClosedCount(), cache_hit_ratio, cost, dist
 
			);
 
		}
 

	
 
				DEBUG(yapf, 3, "[YAPF%c]%c%4d- %d us - %d rounds - %d open - %d closed - CHR %4.1f%% - C %d D %d - c%d(sc%d, ts%d, o%d) -- ",
 
					ttc, bDestFound ? '-' : '!', veh_idx, t, m_num_steps, m_nodes.OpenCount(), m_nodes.ClosedCount(),
 
					cache_hit_ratio, cost, dist, m_perf_cost.Get(1000000), m_perf_slope_cost.Get(1000000),
 
					m_perf_ts_cost.Get(1000000), m_perf_other_cost.Get(1000000)
 
				);
 
			}
 
		}
 
		return bDestFound;
 
	}
 

	
src/pathfinder/yapf/yapf_costcache.hpp
Show inline comments
 
@@ -182,16 +182,8 @@ protected:
 
	inline static Cache& stGetGlobalCache()
 
	{
 
		static int last_rail_change_counter = 0;
 
		static Date last_date = 0;
 
		static Cache C;
 

	
 
		/* some statistics */
 
		if (last_date != _date) {
 
			last_date = _date;
 
			DEBUG(yapf, 2, "Pf time today: %5d ms", _total_pf_time_us / 1000);
 
			_total_pf_time_us = 0;
 
		}
 

	
 
		/* delete the cache sometimes... */
 
		if (last_rail_change_counter != Cache::s_rail_change_counter) {
 
			last_rail_change_counter = Cache::s_rail_change_counter;
src/pathfinder/yapf/yapf_costrail.hpp
Show inline comments
 
@@ -86,7 +86,6 @@ protected:
 
public:
 
	inline int SlopeCost(TileIndex tile, Trackdir td)
 
	{
 
		CPerfStart perf_cost(Yapf().m_perf_slope_cost);
 
		if (!stSlopeCost(tile, td)) return 0;
 
		return Yapf().PfGetSettings().rail_slope_penalty;
 
	}
 
@@ -172,7 +171,6 @@ public:
 
	{
 
		int cost = 0;
 
		/* if there is one-way signal in the opposite direction, then it is not our way */
 
		CPerfStart perf_cost(Yapf().m_perf_other_cost);
 
		if (IsTileType(tile, MP_RAILWAY)) {
 
			bool has_signal_against = HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir));
 
			bool has_signal_along = HasSignalOnTrackdir(tile, trackdir);
 
@@ -275,8 +273,6 @@ public:
 
		assert(tf->m_new_tile == n.m_key.m_tile);
 
		assert((HasTrackdir(tf->m_new_td_bits, n.m_key.m_td)));
 

	
 
		CPerfStart perf_cost(Yapf().m_perf_cost);
 

	
 
		/* Does the node have some parent node? */
 
		bool has_parent = (n.m_parent != nullptr);
 

	
 
@@ -326,7 +322,7 @@ public:
 

	
 
		EndSegmentReasonBits end_segment_reason = ESRB_NONE;
 

	
 
		TrackFollower tf_local(v, Yapf().GetCompatibleRailTypes(), &Yapf().m_perf_ts_cost);
 
		TrackFollower tf_local(v, Yapf().GetCompatibleRailTypes());
 

	
 
		if (!has_parent) {
 
			/* We will jump to the middle of the cost calculator assuming that segment cache is not used. */
 
@@ -484,7 +480,7 @@ no_entry_cost: // jump here at the begin
 

	
 
			/* Move to the next tile/trackdir. */
 
			tf = &tf_local;
 
			tf_local.Init(v, Yapf().GetCompatibleRailTypes(), &Yapf().m_perf_ts_cost);
 
			tf_local.Init(v, Yapf().GetCompatibleRailTypes());
 

	
 
			if (!tf_local.Follow(cur.tile, cur.td)) {
 
				assert(tf_local.m_err != TrackFollower::EC_NONE);
src/pathfinder/yapf/yapf_rail.cpp
Show inline comments
 
@@ -34,8 +34,6 @@ template <typename Tpf> void DumpState(T
 
	fclose(f2);
 
}
 

	
 
int _total_pf_time_us = 0;
 

	
 
template <class Types>
 
class CYapfReserveTrack
 
{
0 comments (0 inline, 0 general)