Skip to content

Commit 1ab2c0c

Browse files
authored
1 parent bc08092 commit 1ab2c0c

File tree

5 files changed

+119
-402
lines changed

5 files changed

+119
-402
lines changed

src/Microsoft.PowerShell.Commands.Diagnostics/CounterSample.cs

Lines changed: 28 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -27,127 +27,43 @@ internal PerformanceCounterSample(string path,
2727
UInt64 timeStamp100nSec,
2828
UInt32 status)
2929
{
30-
_path = path;
31-
_instanceName = instanceName;
32-
_cookedValue = cookedValue;
33-
_rawValue = rawValue;
34-
_secondValue = secondValue;
35-
_multiCount = multiCount;
36-
_counterType = counterType;
37-
_defaultScale = defaultScale;
38-
_timeBase = timeBase;
39-
_timeStamp = timeStamp;
40-
_timeStamp100nSec = timeStamp100nSec;
41-
_status = status;
30+
Path = path;
31+
InstanceName = instanceName;
32+
CookedValue = cookedValue;
33+
RawValue = rawValue;
34+
SecondValue = secondValue;
35+
MultipleCount = multiCount;
36+
CounterType = counterType;
37+
DefaultScale = defaultScale;
38+
TimeBase = timeBase;
39+
Timestamp = timeStamp;
40+
Timestamp100NSec = timeStamp100nSec;
41+
Status = status;
4242
}
4343

44-
public string Path
45-
{
46-
get { return _path; }
47-
48-
set { _path = value; }
49-
}
50-
51-
private string _path = string.Empty;
52-
53-
public string InstanceName
54-
{
55-
get { return _instanceName; }
56-
57-
set { _instanceName = value; }
58-
}
59-
60-
private string _instanceName = string.Empty;
61-
62-
public double CookedValue
63-
{
64-
get { return _cookedValue; }
65-
66-
set { _cookedValue = value; }
67-
}
68-
69-
private double _cookedValue = 0;
70-
71-
public UInt64 RawValue
72-
{
73-
get { return _rawValue; }
74-
75-
set { _rawValue = value; }
76-
}
77-
78-
private UInt64 _rawValue = 0;
79-
80-
public UInt64 SecondValue
81-
{
82-
get { return _secondValue; }
83-
84-
set { _secondValue = value; }
85-
}
86-
87-
private UInt64 _secondValue = 0;
88-
89-
public uint MultipleCount
90-
{
91-
get { return _multiCount; }
92-
93-
set { _multiCount = value; }
94-
}
44+
public string Path { get; set; } = string.Empty;
9545

96-
private uint _multiCount = 0;
46+
public string InstanceName { get; set; } = string.Empty;
9747

98-
public PerformanceCounterType CounterType
99-
{
100-
get { return _counterType; }
101-
102-
set { _counterType = value; }
103-
}
104-
105-
private PerformanceCounterType _counterType = 0;
106-
107-
public DateTime Timestamp
108-
{
109-
get { return _timeStamp; }
110-
111-
set { _timeStamp = value; }
112-
}
113-
114-
private DateTime _timeStamp = DateTime.MinValue;
115-
116-
public UInt64 Timestamp100NSec
117-
{
118-
get { return _timeStamp100nSec; }
119-
120-
set { _timeStamp100nSec = value; }
121-
}
122-
123-
private UInt64 _timeStamp100nSec = 0;
48+
public double CookedValue { get; set; }
12449

125-
public UInt32 Status
126-
{
127-
get { return _status; }
50+
public UInt64 RawValue { get; set; }
12851

129-
set { _status = value; }
130-
}
52+
public UInt64 SecondValue { get; set; }
13153

132-
private UInt32 _status = 0;
54+
public uint MultipleCount { get; set; }
13355

134-
public UInt32 DefaultScale
135-
{
136-
get { return _defaultScale; }
56+
public PerformanceCounterType CounterType { get; set; }
13757

138-
set { _defaultScale = value; }
139-
}
58+
public DateTime Timestamp { get; set; } = DateTime.MinValue;
14059

141-
private UInt32 _defaultScale = 0;
60+
public UInt64 Timestamp100NSec { get; set; }
14261

143-
public UInt64 TimeBase
144-
{
145-
get { return _timeBase; }
62+
public UInt32 Status { get; set; }
14663

147-
set { _timeBase = value; }
148-
}
64+
public UInt32 DefaultScale { get; set; }
14965

150-
private UInt64 _timeBase = 0;
66+
public UInt64 TimeBase { get; set; }
15167
}
15268

15369
public class PerformanceCounterSampleSet
@@ -161,31 +77,17 @@ internal PerformanceCounterSampleSet(DateTime timeStamp,
16177
PerformanceCounterSample[] counterSamples,
16278
bool firstSet) : this()
16379
{
164-
_timeStamp = timeStamp;
165-
_counterSamples = counterSamples;
166-
}
167-
168-
public DateTime Timestamp
169-
{
170-
get { return _timeStamp; }
171-
172-
set { _timeStamp = value; }
80+
Timestamp = timeStamp;
81+
CounterSamples = counterSamples;
17382
}
17483

175-
private DateTime _timeStamp = DateTime.MinValue;
84+
public DateTime Timestamp { get; set; } = DateTime.MinValue;
17685

17786
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
17887
Scope = "member",
17988
Target = "Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSample.CounterSamples",
18089
Justification = "A string[] is required here because that is the type Powershell supports")]
181-
public PerformanceCounterSample[] CounterSamples
182-
{
183-
get { return _counterSamples; }
184-
185-
set { _counterSamples = value; }
186-
}
187-
188-
private PerformanceCounterSample[] _counterSamples = null;
90+
public PerformanceCounterSample[] CounterSamples { get; set; }
18991

19092
private readonly ResourceManager _resourceMgr = null;
19193
}

src/Microsoft.PowerShell.Commands.Diagnostics/CounterSet.cs

Lines changed: 21 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,74 +16,34 @@ internal CounterSet(string setName,
1616
string setHelp,
1717
ref Dictionary<string, string[]> counterInstanceMapping)
1818
{
19-
_counterSetName = setName;
19+
CounterSetName = setName;
2020
if (machineName == null || machineName.Length == 0)
2121
{
2222
machineName = ".";
2323
}
2424
else
2525
{
26-
_machineName = machineName;
27-
if (!_machineName.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase))
26+
MachineName = machineName;
27+
if (!MachineName.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase))
2828
{
29-
_machineName = @"\\" + _machineName;
29+
MachineName = @"\\" + MachineName;
3030
}
3131
}
3232

33-
_counterSetType = categoryType;
34-
_description = setHelp;
35-
_counterInstanceMapping = counterInstanceMapping;
33+
CounterSetType = categoryType;
34+
Description = setHelp;
35+
CounterInstanceMapping = counterInstanceMapping;
3636
}
3737

38-
public string CounterSetName
39-
{
40-
get
41-
{
42-
return _counterSetName;
43-
}
44-
}
45-
46-
private readonly string _counterSetName = string.Empty;
47-
48-
public string MachineName
49-
{
50-
get
51-
{
52-
return _machineName;
53-
}
54-
}
55-
56-
private readonly string _machineName = ".";
57-
58-
public PerformanceCounterCategoryType CounterSetType
59-
{
60-
get
61-
{
62-
return _counterSetType;
63-
}
64-
}
38+
public string CounterSetName { get; } = string.Empty;
6539

66-
private readonly PerformanceCounterCategoryType _counterSetType;
40+
public string MachineName { get; } = ".";
6741

68-
public string Description
69-
{
70-
get
71-
{
72-
return _description;
73-
}
74-
}
75-
76-
private readonly string _description = string.Empty;
42+
public PerformanceCounterCategoryType CounterSetType { get; }
7743

78-
internal Dictionary<string, string[]> CounterInstanceMapping
79-
{
80-
get
81-
{
82-
return _counterInstanceMapping;
83-
}
84-
}
44+
public string Description { get; } = string.Empty;
8545

86-
private readonly Dictionary<string, string[]> _counterInstanceMapping;
46+
internal Dictionary<string, string[]> CounterInstanceMapping { get; }
8747

8848
public StringCollection Paths
8949
{
@@ -95,15 +55,15 @@ public StringCollection Paths
9555
string path;
9656
if (CounterInstanceMapping[counterName].Length != 0)
9757
{
98-
path = (_machineName == ".") ?
99-
("\\" + _counterSetName + "(*)\\" + counterName) :
100-
(_machineName + "\\" + _counterSetName + "(*)\\" + counterName);
58+
path = (MachineName == ".") ?
59+
("\\" + CounterSetName + "(*)\\" + counterName) :
60+
(MachineName + "\\" + CounterSetName + "(*)\\" + counterName);
10161
}
10262
else
10363
{
104-
path = (_machineName == ".") ?
105-
("\\" + _counterSetName + "\\" + counterName) :
106-
(_machineName + "\\" + _counterSetName + "\\" + counterName);
64+
path = (MachineName == ".") ?
65+
("\\" + CounterSetName + "\\" + counterName) :
66+
(MachineName + "\\" + CounterSetName + "\\" + counterName);
10767
}
10868

10969
retColl.Add(path);
@@ -122,9 +82,9 @@ public StringCollection PathsWithInstances
12282
{
12383
foreach (string instanceName in CounterInstanceMapping[counterName])
12484
{
125-
string path = (_machineName == ".") ?
126-
("\\" + _counterSetName + "(" + instanceName + ")\\" + counterName) :
127-
(_machineName + "\\" + _counterSetName + "(" + instanceName + ")\\" + counterName);
85+
string path = (MachineName == ".") ?
86+
("\\" + CounterSetName + "(" + instanceName + ")\\" + counterName) :
87+
(MachineName + "\\" + CounterSetName + "(" + instanceName + ")\\" + counterName);
12888
retColl.Add(path);
12989
}
13090
}

0 commit comments

Comments
 (0)