diff --git a/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestStatistics.cs b/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestStatistics.cs deleted file mode 100644 index 66b2e34..0000000 --- a/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestStatistics.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Text.Json; -using System.Text; -using Xunit; - -namespace ConfusedPolarBear.Plugin.IntroSkipper.Tests; - -public class TestStatistics -{ - [Fact] - public void TestTSISerialization() - { - var expected = "\"TotalAnalyzedEpisodes\":42,"; - - var stats = new AnalysisStatistics(); - stats.TotalAnalyzedEpisodes.Add(42); - - var actual = Encoding.UTF8.GetString(JsonSerializer.SerializeToUtf8Bytes(stats)); - - Assert.Contains(expected, actual, StringComparison.OrdinalIgnoreCase); - } -} diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html index 4f51047..9c3cc5e 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html @@ -258,12 +258,6 @@ -
- Analysis Statistics (experimental) - -

-
-
Advanced @@ -372,7 +366,6 @@ // settings elements var visualizer = document.querySelector("details#visualizer"); - var statistics = document.querySelector("details#statistics"); var support = document.querySelector("details#support"); var btnEraseTimestamps = document.querySelector("button#btnEraseTimestamps"); @@ -470,59 +463,6 @@ Dashboard.alert("Press Ctrl+C to copy support bundle"); } - async function statisticsToggled() { - if (!statistics.open) { - return; - } - - // Blank any old statistics - const text = document.querySelector("pre#statisticsText"); - text.textContent = "All CPU times are displayed as seconds.\n\n"; - - Dashboard.showLoadingMsg(); - - // Load the statistics from the server - let stats = await getJson("Intros/Statistics"); - - // Select which fields to print and label them with more friendly descriptions - let fields = "TotalTaskTime,TotalCPUTime,FingerprintCPUTime,FirstPassCPUTime,SecondPassCPUTime," + - "IndexSearches,QuickScans,FullScans,TotalQueuedEpisodes"; - - let friendlyNames = { - TotalTaskTime: "Total task time", - TotalCPUTime: "Total CPU time", - FingerprintCPUTime: "Fingerprint CPU time", - FirstPassCPUTime: "First pass CPU time", - SecondPassCPUTime: "Second pass CPU time", - IndexSearches: "Index searches", - QuickScans: "Quick scans", - FullScans: "Full scans", - TotalQueuedEpisodes: "Episodes queued", - }; - - // Print all friendly names and data points - for (var f of fields.split(",")) { - let name = friendlyNames[f].padEnd(25); - let value = stats[f]; - - // If this statistic is a measure of CPU time, divide by 1,000 to turn milliseconds into seconds. - if (name.includes("time")) { - value = Math.round(value / 1000); - } - - text.textContent += name + value + "\n"; - } - - // Calculate the percentage of time (to two decimal places) spent waiting for fingerprints - const percentWait = Math.round((stats.FingerprintCPUTime * 10_000) / stats.TotalCPUTime) / 100; - - // Breakdown CPU time by analysis component - text.textContent += "\nCPU time breakdown:\n"; - text.textContent += "Fingerprint generation " + percentWait + "%\n"; - - Dashboard.hideLoadingMsg(); - } - // show changed, populate seasons async function showChanged() { clearSelect(selectSeason); @@ -752,7 +692,6 @@ }); visualizer.addEventListener("toggle", visualizerToggled); - statistics.addEventListener("toggle", statisticsToggled); support.addEventListener("toggle", supportToggled); txtOffset.addEventListener("change", renderTroubleshooter); selectShow.addEventListener("change", showChanged); diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs index 5cf7bc1..d4cec0d 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs @@ -166,17 +166,6 @@ public class VisualizationController : ControllerBase return NoContent(); } - /// - /// Returns the statistics for the most recent analysis. - /// - /// Analysis statistics. - /// AnalysisStatistics. - [HttpGet("Statistics")] - public ActionResult GetAnalysisStatistics() - { - return Plugin.Instance!.AnalysisStatistics; - } - private string GetSeasonName(QueuedEpisode episode) { return "Season " + episode.SeasonNumber.ToString(CultureInfo.InvariantCulture); diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Data/AnalysisStatistics.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Data/AnalysisStatistics.cs deleted file mode 100644 index 522dbdf..0000000 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Data/AnalysisStatistics.cs +++ /dev/null @@ -1,128 +0,0 @@ -namespace ConfusedPolarBear.Plugin.IntroSkipper; - -using System; -using System.Threading; -using System.Text.Json; -using System.Text.Json.Serialization; - -/// -/// Detailed statistics about the last analysis operation performed. All times are represented as milliseconds. -/// -public class AnalysisStatistics -{ - /// - /// Gets the number of episodes that have been analyzed so far. - /// - public ThreadSafeInteger TotalAnalyzedEpisodes { get; } = new ThreadSafeInteger(); - - /// - /// Gets or sets the number of episodes that need to be analyzed. - /// - public int TotalQueuedEpisodes { get; set; } - - /// - /// Gets the number of times an index search successfully located a pair of introductions. - /// - public ThreadSafeInteger IndexSearches { get; } = new ThreadSafeInteger(); - - /// - /// Gets the total CPU time spent waiting for audio fingerprints to be generated. - /// - public ThreadSafeInteger FingerprintCPUTime { get; } = new ThreadSafeInteger(); - - /// - /// Gets the total CPU time spent analyzing fingerprints. - /// - public ThreadSafeInteger AnalysisCPUTime { get; } = new ThreadSafeInteger(); - - /// - /// Gets the total task runtime across all threads. - /// - public ThreadSafeInteger TotalCPUTime { get; } = new ThreadSafeInteger(); - - /// - /// Gets the total task runtime as measured by a clock. - /// - public ThreadSafeInteger TotalTaskTime { get; } = new ThreadSafeInteger(); -} - -/// -/// Convenience wrapper around a thread safe integer. -/// -[JsonConverter(typeof(ThreadSafeIntegerJsonConverter))] -public class ThreadSafeInteger -{ - private int value = 0; - - /// - /// Gets the current value stored by this integer. - /// - public int Value - { - get - { - return value; - } - } - - /// - /// Increment the value of this integer by 1. - /// - public void Increment() - { - Add(1); - } - - /// - /// Adds the total milliseconds elapsed since a start time. - /// - /// Start time. - public void AddDuration(DateTime start) - { - if (start == DateTime.MinValue) - { - return; - } - - var elapsed = DateTime.Now.Subtract(start); - Add((int)elapsed.TotalMilliseconds); - } - - /// - /// Adds the provided amount to this integer. - /// - /// Amount to add. - public void Add(int amount) - { - Interlocked.Add(ref value, amount); - } -} - -/// -/// Serialize thread safe integers to a regular integer (instead of an object with a Value property). -/// -public class ThreadSafeIntegerJsonConverter : JsonConverter -{ - /// - /// Deserialization of TSIs is not supported and will always throw a NotSupportedException. - /// - /// Reader. - /// Type. - /// Options. - /// Never returns. - public override ThreadSafeInteger? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - throw new NotSupportedException(); - } - - /// - /// Serialize the provided TSI. - /// - /// Writer. - /// TSI. - /// Options. - public override void Write(Utf8JsonWriter writer, ThreadSafeInteger value, JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } -} diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs index b53aec6..eb96689 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs @@ -80,11 +80,6 @@ public class Plugin : BasePlugin, IHasWebPages /// public int TotalQueued { get; set; } - /// - /// Gets or sets the statistics from the most recent analysis run. - /// - public AnalysisStatistics AnalysisStatistics { get; set; } = new AnalysisStatistics(); - /// /// Gets the directory to cache fingerprints in. /// diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs index 9a5d983..e8460b0 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs @@ -31,11 +31,6 @@ public class AnalyzeEpisodesTask : IScheduledTask /// private readonly object _introsLock = new object(); - /// - /// Statistics for the currently running analysis task. - /// - private AnalysisStatistics analysisStatistics = new AnalysisStatistics(); - /// /// Minimum duration of similar audio that will be considered an introduction. /// @@ -133,8 +128,6 @@ public class AnalyzeEpisodesTask : IScheduledTask }; var taskStart = DateTime.Now; - analysisStatistics = new AnalysisStatistics(); - analysisStatistics.TotalQueuedEpisodes = Plugin.Instance!.TotalQueued; minimumIntroDuration = Plugin.Instance!.Configuration.MinimumIntroDuration; @@ -186,15 +179,8 @@ public class AnalyzeEpisodesTask : IScheduledTask } progress.Report((totalProcessed * 100) / Plugin.Instance!.TotalQueued); - - analysisStatistics.TotalCPUTime.AddDuration(workerStart); - Plugin.Instance!.AnalysisStatistics = analysisStatistics; }); - // Update analysis statistics - analysisStatistics.TotalTaskTime.AddDuration(taskStart); - Plugin.Instance!.AnalysisStatistics = analysisStatistics; - // Turn the regenerate EDL flag off after the scan completes. if (Plugin.Instance!.Configuration.RegenerateEdlFiles) { @@ -385,8 +371,6 @@ public class AnalyzeEpisodesTask : IScheduledTask if (lhsRanges.Count > 0) { _logger.LogTrace("Index search successful"); - analysisStatistics.IndexSearches.Increment(); - analysisStatistics.AnalysisCPUTime.AddDuration(start); return GetLongestTimeRange(lhsId, lhsRanges, rhsId, rhsRanges); } @@ -396,8 +380,6 @@ public class AnalyzeEpisodesTask : IScheduledTask lhsId, rhsId); - analysisStatistics.AnalysisCPUTime.AddDuration(start); - return (new Intro(lhsId), new Intro(rhsId)); }