Browse Source

Merge branch 'master' into crash-report-api

Krzysztof Krysiński 7 months ago
parent
commit
a68c2aa413
1 changed files with 22 additions and 3 deletions
  1. 22 3
      src/PixiEditor/Models/AnalyticsAPI/PeriodicPerformanceReporter.cs

+ 22 - 3
src/PixiEditor/Models/AnalyticsAPI/PeriodicPerformanceReporter.cs

@@ -8,11 +8,21 @@ public class PeriodicPerformanceReporter(AnalyticsPeriodicReporter analyticsRepo
     private long _lastTotalAllocatedBytes;
     private long _lastTotalAllocatedBytes;
     private TimeSpan _lastTotalGcPauseTime;
     private TimeSpan _lastTotalGcPauseTime;
 
 
+    private int targetCount;
+    private int sendCount;
+    
+    private Timer timer;
+    
     public void StartPeriodicReporting()
     public void StartPeriodicReporting()
     {
     {
-        var timer = new Timer
+        var recordInterval = TimeSpan.FromSeconds(45);
+        var targetRecordingSpan = TimeSpan.FromHours(1);
+
+        targetCount = (int)(targetRecordingSpan / recordInterval);
+
+        timer = new Timer
         {
         {
-            Interval = TimeSpan.FromSeconds(45).TotalMilliseconds,
+            Interval = recordInterval.TotalMilliseconds,
             AutoReset = true
             AutoReset = true
         };
         };
 
 
@@ -30,9 +40,10 @@ public class PeriodicPerformanceReporter(AnalyticsPeriodicReporter analyticsRepo
         var collectionStartTime = DateTime.Now;
         var collectionStartTime = DateTime.Now;
         
         
         var processorTime = await SampleProcessorTimeAsync(process);
         var processorTime = await SampleProcessorTimeAsync(process);
+
         data["UserTime"] = processorTime.userTime;
         data["UserTime"] = processorTime.userTime;
         data["PrivilegedTime"] = processorTime.privilegedTime;
         data["PrivilegedTime"] = processorTime.privilegedTime;
-        
+
         data["PrivateMemorySize"] = process.PrivateMemorySize64;
         data["PrivateMemorySize"] = process.PrivateMemorySize64;
         data["WorkingSet"] = process.WorkingSet64;
         data["WorkingSet"] = process.WorkingSet64;
 
 
@@ -56,6 +67,14 @@ public class PeriodicPerformanceReporter(AnalyticsPeriodicReporter analyticsRepo
         };
         };
         
         
         analyticsReporter.AddEvent(e);
         analyticsReporter.AddEvent(e);
+        
+        sendCount++;
+
+        if (sendCount >= targetCount)
+        {
+            timer.Stop();
+            timer.Dispose();
+        }
     }
     }
 
 
     private async Task<(TimeSpan userTime, TimeSpan privilegedTime)> SampleProcessorTimeAsync(Process process)
     private async Task<(TimeSpan userTime, TimeSpan privilegedTime)> SampleProcessorTimeAsync(Process process)