< Summary

Class:Itinero.Routing.ReachabilityCounters
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Routing/ReachabilityCounters.cs
Covered lines:16
Uncovered lines:38
Coverable lines:54
Total lines:161
Line coverage:29.6% (16 of 54)
Covered branches:2
Total branches:8
Branch coverage:25% (2 of 8)
Tag:284_38118444584

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_Routes()100%10%
get_PocketsComposed()100%10%
CountPocketComposed()100%1100%
get_PocketsAbandoned()100%10%
CountPocketAbandoned()100%10%
get_OriginAdvances()100%10%
get_DestinationAdvances()100%10%
get_Searches()100%10%
get_SettledStates()100%10%
get_RoutesRetried()100%10%
get_SettledClean()100%10%
get_SettledRetried()100%10%
get_WastedStates()100%10%
CountRoute()100%1100%
CountRouteOutcome(...)100%2100%
CountWasted(...)100%1100%
CountOriginAdvance()100%1100%
CountDestinationAdvance()100%10%
CountSearch()100%1100%
CountSettled(...)100%1100%
Describe()0%20%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Routing/ReachabilityCounters.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3using System.Threading;
 4
 5namespace Itinero.Routing;
 6
 7/// <summary>
 8/// Process-wide tallies for <see cref="ReachabilityRouter"/>, so the cost of the optimistic
 9/// path can be attributed rather than guessed at.
 10/// </summary>
 11/// <remarks>
 12/// Free-running, read by subtracting two snapshots; nothing resets them, which keeps the write
 13/// path to one uncontended increment.
 14/// </remarks>
 15public static class ReachabilityCounters
 16{
 17    private static long _routes;
 18    private static long _originAdvances;
 19    private static long _destinationAdvances;
 20    private static long _searches;
 21    private static long _settledStates;
 22
 23
 24
 25    // Split by whether the route ever abandoned a candidate: the retried group's share of total
 26    // settled states is the cost of retrying.
 27    private static long _routesRetried;
 28    private static long _settledClean;
 29    private static long _settledRetried;
 30    private static long _wastedStates;
 31
 32    /// <summary>Route requests entered.</summary>
 033    public static long Routes => Interlocked.Read(ref _routes);
 34
 35    private static long _pocketsComposed;
 36    private static long _pocketsAbandoned;
 37
 38    /// <summary>
 39    /// Times a stranded candidate got a pocket composed for it — the local-access fallback.
 40    /// </summary>
 41    /// <remarks>
 42    /// Per route this is how often phase 1 was not enough. Nothing is composed for a candidate
 43    /// that routes straight away, so the common path never pays for it.
 44    /// </remarks>
 045    public static long PocketsComposed => Interlocked.Read(ref _pocketsComposed);
 46
 347    public static void CountPocketComposed() => Interlocked.Increment(ref _pocketsComposed);
 48
 49    /// <summary>
 50    /// Pockets that outgrew their budget, so the candidate got no relabelling.
 51    /// </summary>
 52    /// <remarks>
 53    /// Should stay at zero: a local-access region larger than the island threshold means the
 54    /// tagging or the bound is wrong, not that the route is unusual.
 55    /// </remarks>
 056    public static long PocketsAbandoned => Interlocked.Read(ref _pocketsAbandoned);
 57
 058    public static void CountPocketAbandoned() => Interlocked.Increment(ref _pocketsAbandoned);
 59
 60    /// <summary>Times the origin gave up on a candidate and took the next one.</summary>
 61    /// <remarks>
 62    /// Counts only candidates abandoned after a failed search. The first snap is not an advance
 63    /// — so zero here means every route was served by the edge nearest its origin.
 64    /// </remarks>
 065    public static long OriginAdvances => Interlocked.Read(ref _originAdvances);
 66
 67    /// <summary>Times the destination gave up on a candidate and took the next one.</summary>
 068    public static long DestinationAdvances => Interlocked.Read(ref _destinationAdvances);
 69
 70    /// <summary>Bidirectional searches run, including continuations of a surviving half.</summary>
 071    public static long Searches => Interlocked.Read(ref _searches);
 72
 73    /// <summary>States settled across both halves, summed over all searches.</summary>
 74    /// <remarks>
 75    /// The per-route figure is what compares against the baseline's A* search: a router paying
 76    /// for goal direction settles far fewer states for the same path, and that difference is
 77    /// CPU rather than I/O, so it shows up most in the hot regime.
 78    /// </remarks>
 079    public static long SettledStates => Interlocked.Read(ref _settledStates);
 80
 81    /// <summary>Routes that abandoned at least one candidate.</summary>
 082    public static long RoutesRetried => Interlocked.Read(ref _routesRetried);
 83
 84    /// <summary>Settled states charged to routes that never retried.</summary>
 085    public static long SettledClean => Interlocked.Read(ref _settledClean);
 86
 87    /// <summary>Settled states charged to routes that retried at least once.</summary>
 088    public static long SettledRetried => Interlocked.Read(ref _settledRetried);
 89
 90    /// <summary>
 91    /// States settled by halves that were then thrown away — the work a retry actually wastes.
 92    /// </summary>
 93    /// <remarks>
 94    /// Bounded by construction: a half is abandoned only when its heap empties below threshold,
 95    /// so it had already exhausted a component smaller than that.
 96    /// </remarks>
 097    public static long WastedStates => Interlocked.Read(ref _wastedStates);
 98
 2899    internal static void CountRoute() => Interlocked.Increment(ref _routes);
 100
 101    /// Called once per route, at exit, with what that route cost.
 102    internal static void CountRouteOutcome(bool retried, long settled)
 28103    {
 28104        if (retried)
 2105        {
 2106            Interlocked.Increment(ref _routesRetried);
 2107            Interlocked.Add(ref _settledRetried, settled);
 2108        }
 109        else
 26110        {
 26111            Interlocked.Add(ref _settledClean, settled);
 26112        }
 28113    }
 114
 1115    internal static void CountWasted(long states) => Interlocked.Add(ref _wastedStates, states);
 116
 117
 118
 119
 1120    internal static void CountOriginAdvance() => Interlocked.Increment(ref _originAdvances);
 121
 0122    internal static void CountDestinationAdvance() => Interlocked.Increment(ref _destinationAdvances);
 123
 32124    internal static void CountSearch() => Interlocked.Increment(ref _searches);
 125
 32126    internal static void CountSettled(long states) => Interlocked.Add(ref _settledStates, states);
 127
 128    /// <summary>A one-line summary, for a log heartbeat.</summary>
 129    public static string Describe()
 0130    {
 0131        var routes = Routes;
 0132        if (routes == 0) return "reachability: no routes yet";
 133
 134        string Per(long value, string format) =>
 0135            (value / (double)routes).ToString(format, CultureInfo.InvariantCulture);
 136
 0137        var retried = RoutesRetried;
 0138        var clean = routes - retried;
 139
 0140        string Mean(long total, long count, string format) => count == 0
 0141            ? "n/a"
 0142            : (total / (double)count).ToString(format, CultureInfo.InvariantCulture);
 143
 0144        string Pct(long part, long whole) => whole == 0
 0145            ? "n/a"
 0146            : (part * 100.0 / whole).ToString("0.0", CultureInfo.InvariantCulture) + "%";
 147
 0148        return "reachability: routes=" + routes.ToString(CultureInfo.InvariantCulture) +
 0149               ", searches/route=" + Per(Searches, "0.000") +
 0150               ", origin_advances/route=" + Per(OriginAdvances, "0.000") +
 0151               ", dest_advances/route=" + Per(DestinationAdvances, "0.000") +
 0152               ", settled/route=" + Per(SettledStates, "0.0") +
 0153               " | retried=" + Pct(retried, routes) +
 0154               " of routes, settled/route clean=" + Mean(SettledClean, clean, "0.0") +
 0155               " retried=" + Mean(SettledRetried, retried, "0.0") +
 0156               ", wasted_states=" + Pct(WastedStates, SettledStates) + " of all settled" +
 0157               " (" + Mean(WastedStates, routes, "0.0") + "/route)" +
 0158               " | pockets/route=" + Per(PocketsComposed, "0.000") +
 0159               ", pockets_abandoned=" + PocketsAbandoned.ToString(CultureInfo.InvariantCulture);
 0160    }
 161}