-
Notifications
You must be signed in to change notification settings - Fork 82
/
Counters.cs
60 lines (51 loc) · 1.01 KB
/
Counters.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) MOSA Project. Licensed under the New BSD License.
using System.Collections.Generic;
namespace Mosa.Compiler.Framework
{
/// <summary>
///
/// </summary>
public sealed class Counters
{
private Dictionary<string, int> counters;
public void Clear()
{
if (counters != null)
counters.Clear();
}
public void Update(string name, int count)
{
lock (this)
{
if (counters == null)
counters = new Dictionary<string, int>();
if (counters.ContainsKey(name))
counters[name] = counters[name] + count;
else
counters.Add(name, count);
}
}
public IList<string> Export()
{
var counts = new List<string>();
if (counters != null)
{
foreach (var item in counters)
{
counts.Add(item.Key + ": " + item.Value.ToString());
}
}
return counts;
}
public void Merge(Counters counters)
{
if (counters.counters != null)
{
foreach (var item in counters.counters)
{
Update(item.Key, item.Value);
}
}
}
}
}