• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bmresearch / Solnet / 8950601615

04 May 2024 12:47PM UTC coverage: 77.239% (-3.7%) from 80.902%
8950601615

push

github

web-flow
Update dotnet.yml

1123 of 1710 branches covered (65.67%)

Branch coverage included in aggregate %.

5199 of 6475 relevant lines covered (80.29%)

1304486.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.83
/src/Solnet.Rpc/Types/ConnectionStats.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Timers;
7

8
namespace Solnet.Rpc.Types
9
{
10
    internal class ConnectionStats : IConnectionStatistics
11
    {
12
        private Timer _timer;
13

14
        private Dictionary<long, ulong> _historicData;
15

16
        private ulong _totalReceived;
17

18
        public ulong TotalReceivedBytes
19
        {
20
            get { return _totalReceived; }
38✔
21
            set { _totalReceived = value; }
76✔
22
        }
23

24
        private ulong _averageReceived10s;
25

26
        public ulong AverageThroughput10Seconds
27
        {
28
            get { return _averageReceived10s; }
38✔
29
            set { _averageReceived10s = value; }
76✔
30
        }
31

32
        private ulong _averageReceived60s;
33

34
        public ulong AverageThroughput60Seconds
35
        {
36
            get { return _averageReceived60s; }
38✔
37
            set { _averageReceived60s = value; }
76✔
38
        }
39

40

41
        internal void AddReceived(uint count)
42
        {
43
            TotalReceivedBytes += count;
38✔
44
            var secs = (long)(DateTime.UtcNow - DateTime.UnixEpoch).TotalSeconds;
38✔
45

46
            lock (this)
38✔
47
            {
48
                if (!_timer.Enabled)
38✔
49
                    _timer.Start();
19✔
50

51
                if (_historicData.TryGetValue(secs, out var current))
38✔
52
                {
53
                    _historicData[secs] = current + count;
19✔
54
                }
55
                else
56
                {
57
                    _historicData[secs] = count;
19✔
58
                }
59

60
                AverageThroughput60Seconds += count / 60;
38✔
61
                AverageThroughput10Seconds += count / 10;
38✔
62
            }
38✔
63
        }
38✔
64

65
        internal ConnectionStats()
23✔
66
        {
67
            _timer = new Timer(1000);
23✔
68
            _timer.AutoReset = true;
23✔
69
            _timer.Elapsed += RemoveOutdatedData;
23✔
70
            _historicData = new Dictionary<long, ulong>();
23✔
71
        }
23✔
72

73
        private void RemoveOutdatedData(object sender, ElapsedEventArgs e)
74
        {
75
            var currentSec = (long)(DateTime.UtcNow - DateTime.UnixEpoch).TotalSeconds;
×
76

77
            lock (this)
×
78
            {
79
                if (_historicData.ContainsKey(currentSec - 60))
×
80
                {
81
                    _historicData.Remove(currentSec - 60);
×
82
                }
83
                if (_historicData.Count == 0)
×
84
                {
85
                    _timer.Stop();
×
86
                    AverageThroughput60Seconds = 0;
×
87
                    AverageThroughput10Seconds = 0;
×
88
                }
89
                else
90
                {
91
                    ulong total = 0, tenSecTotal = 0;
×
92
                    foreach (var kvp in _historicData)
×
93
                    {
94
                        total += kvp.Value;
×
95
                        if (kvp.Key > currentSec - 10)
×
96
                        {
97
                            tenSecTotal += kvp.Value;
×
98
                        }
99
                    }
100
                    AverageThroughput60Seconds = total / 60;
×
101
                    AverageThroughput10Seconds = tenSecTotal / 10;
×
102
                }
103
            }
×
104
        }
×
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc