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
 
@@ -2,8 +2,7 @@ add_subdirectory(npf)
 
add_subdirectory(yapf)
 

	
 
add_files(
 
    follow_track.hpp
 
    pathfinder_func.h
 
    pathfinder_type.h
 
    pf_performance_timer.hpp
 
)
src/pathfinder/follow_track.hpp
Show inline comments
 
@@ -15,13 +15,12 @@
 
#include "../station_base.h"
 
#include "../train.h"
 
#include "../tunnelbridge.h"
 
#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
 
 *  controllers). See 6 different typedefs below for 3 different transport
 
 *  types w/ or w/o 90-deg turns allowed
 
 */
 
@@ -46,40 +45,38 @@ struct CFollowTrackT
 
	DiagDirection       m_exitdir;       ///< exit direction (leaving the old tile)
 
	bool                m_is_tunnel;     ///< last turn passed tunnel
 
	bool                m_is_bridge;     ///< last turn passed bridge ramp
 
	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;
 
		m_new_tile = INVALID_TILE;
 
		m_new_td_bits = TRACKDIR_BIT_NONE;
 
		m_exitdir = INVALID_DIAGDIR;
 
@@ -234,13 +231,12 @@ 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()) {
 
			m_new_td_bits = GetTrackdirBitsForRoad(m_new_tile, this->IsTram() ? RTT_TRAM : RTT_ROAD);
 
		} else {
 
			m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), 0));
src/pathfinder/npf/npf.cpp
Show inline comments
 
@@ -5,12 +5,13 @@
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @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"
 
#include "../../roadstop_base.h"
 
#include "../../vehicle_func.h"
 
#include "../pathfinder_func.h"
src/pathfinder/pf_performance_timer.hpp
Show inline comments
 
deleted file
src/pathfinder/yapf/yapf.hpp
Show inline comments
 
@@ -9,13 +9,12 @@
 

	
 
#ifndef YAPF_HPP
 
#define YAPF_HPP
 

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

	
 
#include "../../misc/fixedsizearray.hpp"
 
#include "../../misc/array.hpp"
 
#include "../../misc/hashtable.hpp"
 
#include "../../misc/binaryheap.hpp"
src/pathfinder/yapf/yapf_base.hpp
Show inline comments
 
@@ -10,14 +10,12 @@
 
#ifndef YAPF_BASE_HPP
 
#define YAPF_BASE_HPP
 

	
 
#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:
 
 *    Types      - used as collection of local types used in pathfinder
 
 *
 
 * Requirements for the Types struct:
 
@@ -65,18 +63,12 @@ protected:
 
	const VehicleType   *m_veh;                ///< vehicle that we are trying to drive
 

	
 
	int                  m_stats_cost_calcs;   ///< stats - how many node's costs were calculated
 
	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:
 
	/** default constructor */
 
	inline CYapfBaseT()
 
		: m_pBestDestNode(nullptr)
 
@@ -117,15 +109,12 @@ public:
 
	 * @return true if the path was found
 
	 */
 
	inline bool FindPath(const VehicleType *v)
 
	{
 
		m_veh = v;
 

	
 
		CPerformanceTimer perf;
 
		perf.Start();
 

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

	
 
		for (;;) {
 
			m_num_steps++;
 
			Node *n = m_nodes.GetBestOpenNode();
 
@@ -147,31 +136,24 @@ public:
 
				break;
 
			}
 
		}
 

	
 
		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;
 
	}
 

	
 
	/**
 
	 * If path was found return the best node that has reached the destination. Otherwise
 
	 *  return the best visited node (which was nearest to the destination).
src/pathfinder/yapf/yapf_costcache.hpp
Show inline comments
 
@@ -179,22 +179,14 @@ protected:
 
		return *static_cast<Tpf *>(this);
 
	}
 

	
 
	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;
 
			C.Flush();
 
		}
 
		return C;
src/pathfinder/yapf/yapf_costrail.hpp
Show inline comments
 
@@ -83,13 +83,12 @@ protected:
 
		return *static_cast<Tpf *>(this);
 
	}
 

	
 
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;
 
	}
 

	
 
	inline int CurveCost(Trackdir td1, Trackdir td2)
 
	{
 
@@ -169,13 +168,12 @@ public:
 
	}
 

	
 
	int SignalCost(Node &n, TileIndex tile, Trackdir trackdir)
 
	{
 
		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);
 
			if (has_signal_against && !has_signal_along && IsOnewaySignal(tile, TrackdirToTrack(trackdir))) {
 
				/* one-way signal in opposite direction */
 
				n.m_segment->m_end_segment_reason |= ESRB_DEAD_END;
 
@@ -272,14 +270,12 @@ public:
 
	inline bool PfCalcCost(Node &n, const TrackFollower *tf)
 
	{
 
		assert(!n.flags_u.flags_s.m_targed_seen);
 
		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);
 

	
 
		/* Do we already have a cached segment? */
 
		CachedData &segment = *n.m_segment;
 
		bool is_cached_segment = (segment.m_cost >= 0);
 
@@ -323,13 +319,13 @@ public:
 

	
 
		/* the previous tile will be needed for transition cost calculations */
 
		TILE prev = !has_parent ? TILE() : TILE(n.m_parent->GetLastTile(), n.m_parent->GetLastTrackdir());
 

	
 
		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. */
 
			assert(!is_cached_segment);
 
			/* Skip the first transition cost calculation. */
 
			goto no_entry_cost;
 
@@ -481,13 +477,13 @@ no_entry_cost: // jump here at the begin
 
			if (m_max_cost > 0 && (parent_cost + segment_entry_cost + segment_cost) > m_max_cost) {
 
				end_segment_reason |= ESRB_PATH_TOO_LONG;
 
			}
 

	
 
			/* 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);
 
				/* Can't move to the next tile (EOL?). */
 
				if (tf_local.m_err == TrackFollower::EC_RAIL_ROAD_TYPE) {
 
					end_segment_reason |= ESRB_RAIL_TYPE;
src/pathfinder/yapf/yapf_rail.cpp
Show inline comments
 
@@ -31,14 +31,12 @@ template <typename Tpf> void DumpState(T
 
	fwrite(dmp1.m_out.c_str(), 1, dmp1.m_out.size(), f1);
 
	fwrite(dmp2.m_out.c_str(), 1, dmp2.m_out.size(), f2);
 
	fclose(f1);
 
	fclose(f2);
 
}
 

	
 
int _total_pf_time_us = 0;
 

	
 
template <class Types>
 
class CYapfReserveTrack
 
{
 
public:
 
	typedef typename Types::Tpf Tpf;                     ///< the pathfinder class (derived from THIS class)
 
	typedef typename Types::TrackFollower TrackFollower;
0 comments (0 inline, 0 general)