blob: 5bd83f8ec4e5727a703243591858658d62048d6a (
plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
namespace WixToolset.Harvesters
{
using System;
using System.Linq;
using System.Diagnostics;
using WixToolset.Data;
using WixToolset.Harvesters.Data;
using WixToolset.Harvesters.Extensibility;
using Util = WixToolset.Harvesters.Serialize.Util;
using Wix = WixToolset.Harvesters.Serialize;
/// <summary>
/// Harvest WiX authoring for a file from the file system.
/// </summary>
public sealed class PerformanceCategoryHarvester : BaseHarvesterExtension
{
/// <summary>
/// Harvest a performance category.
/// </summary>
/// <param name="argument">The name of the performance category.</param>
/// <returns>A harvested performance category.</returns>
public override Wix.Fragment[] Harvest(string argument)
{
if (null == argument)
{
throw new ArgumentNullException("argument");
}
Util.PerformanceCategory perf = this.HarvestPerformanceCategory(argument);
Wix.Component component = new Wix.Component();
component.Id = this.Core.CreateIdentifierFromFilename(argument);
component.KeyPath = Wix.YesNoType.yes;
component.AddChild(perf);
var directory = DirectoryHelper.CreateDirectory("TARGETDIR");
directory.AddChild(component);
Wix.Fragment fragment = new Wix.Fragment();
fragment.AddChild(directory);
return new Wix.Fragment[] { fragment };
}
/// <summary>
/// Harvest a performance category.
/// </summary>
/// <param name="category">The name of the performance category.</param>
/// <returns>A harvested file.</returns>
public Util.PerformanceCategory HarvestPerformanceCategory(string category)
{
if (null == category)
{
throw new ArgumentNullException("category");
}
if (PerformanceCounterCategory.Exists(category))
{
Util.PerformanceCategory perfCategory = new Util.PerformanceCategory();
// Get the performance counter category and set the appropriate WiX attributes
PerformanceCounterCategory pcc = PerformanceCounterCategory.GetCategories().Single(c => string.Equals(c.CategoryName, category));
perfCategory.Id = this.Core.CreateIdentifierFromFilename(pcc.CategoryName);
perfCategory.Name = pcc.CategoryName;
perfCategory.Help = pcc.CategoryHelp;
if (PerformanceCounterCategoryType.MultiInstance == pcc.CategoryType)
{
perfCategory.MultiInstance = Util.YesNoType.yes;
}
// If it's multi-instance, check if there are any instances and get counters from there; else we get
// the counters straight up. For multi-instance, GetCounters() fails if there are any instances. If there
// are no instances, then GetCounters(instance) can't be called since there is no instance. Instances
// will exist for each counter even if only one of the counters was "intialized."
string[] instances = pcc.GetInstanceNames();
bool hasInstances = instances.Length > 0;
PerformanceCounter[] counters = hasInstances
? pcc.GetCounters(instances.First())
: pcc.GetCounters();
foreach (PerformanceCounter counter in counters)
{
Util.PerformanceCounter perfCounter = new Util.PerformanceCounter();
// Get the performance counter and set the appropriate WiX attributes
perfCounter.Name = counter.CounterName;
perfCounter.Type = this.CounterTypeToWix(counter.CounterType);
perfCounter.Help = counter.CounterHelp;
perfCategory.AddChild(perfCounter);
}
return perfCategory;
}
else
{
throw new WixException(HarvesterErrors.PerformanceCategoryNotFound(category));
}
}
/// <summary>
/// Get the WiX performance counter type.
/// </summary>
/// <param name="pct">The performance counter value to get.</param>
/// <returns>The WiX performance counter type.</returns>
private Util.PerformanceCounterTypesType CounterTypeToWix(PerformanceCounterType pct)
{
Util.PerformanceCounterTypesType type;
switch (pct)
{
case PerformanceCounterType.AverageBase:
type = Util.PerformanceCounterTypesType.averageBase;
break;
case PerformanceCounterType.AverageCount64:
type = Util.PerformanceCounterTypesType.averageCount64;
break;
case PerformanceCounterType.AverageTimer32:
type = Util.PerformanceCounterTypesType.averageTimer32;
break;
case PerformanceCounterType.CounterDelta32:
type = Util.PerformanceCounterTypesType.counterDelta32;
break;
case PerformanceCounterType.CounterTimerInverse:
type = Util.PerformanceCounterTypesType.counterTimerInverse;
break;
case PerformanceCounterType.SampleFraction:
type = Util.PerformanceCounterTypesType.sampleFraction;
break;
case PerformanceCounterType.Timer100Ns:
type = Util.PerformanceCounterTypesType.timer100Ns;
break;
case PerformanceCounterType.CounterTimer:
type = Util.PerformanceCounterTypesType.counterTimer;
break;
case PerformanceCounterType.RawFraction:
type = Util.PerformanceCounterTypesType.rawFraction;
break;
case PerformanceCounterType.Timer100NsInverse:
type = Util.PerformanceCounterTypesType.timer100NsInverse;
break;
case PerformanceCounterType.CounterMultiTimer:
type = Util.PerformanceCounterTypesType.counterMultiTimer;
break;
case PerformanceCounterType.CounterMultiTimer100Ns:
type = Util.PerformanceCounterTypesType.counterMultiTimer100Ns;
break;
case PerformanceCounterType.CounterMultiTimerInverse:
type = Util.PerformanceCounterTypesType.counterMultiTimerInverse;
break;
case PerformanceCounterType.CounterMultiTimer100NsInverse:
type = Util.PerformanceCounterTypesType.counterMultiTimer100NsInverse;
break;
case PerformanceCounterType.ElapsedTime:
type = Util.PerformanceCounterTypesType.elapsedTime;
break;
case PerformanceCounterType.SampleBase:
type = Util.PerformanceCounterTypesType.sampleBase;
break;
case PerformanceCounterType.RawBase:
type = Util.PerformanceCounterTypesType.rawBase;
break;
case PerformanceCounterType.CounterMultiBase:
type = Util.PerformanceCounterTypesType.counterMultiBase;
break;
case PerformanceCounterType.RateOfCountsPerSecond64:
type = Util.PerformanceCounterTypesType.rateOfCountsPerSecond64;
break;
case PerformanceCounterType.RateOfCountsPerSecond32:
type = Util.PerformanceCounterTypesType.rateOfCountsPerSecond32;
break;
case PerformanceCounterType.CountPerTimeInterval64:
type = Util.PerformanceCounterTypesType.countPerTimeInterval64;
break;
case PerformanceCounterType.CountPerTimeInterval32:
type = Util.PerformanceCounterTypesType.countPerTimeInterval32;
break;
case PerformanceCounterType.SampleCounter:
type = Util.PerformanceCounterTypesType.sampleCounter;
break;
case PerformanceCounterType.CounterDelta64:
type = Util.PerformanceCounterTypesType.counterDelta64;
break;
case PerformanceCounterType.NumberOfItems64:
type = Util.PerformanceCounterTypesType.numberOfItems64;
break;
case PerformanceCounterType.NumberOfItems32:
type = Util.PerformanceCounterTypesType.numberOfItems32;
break;
case PerformanceCounterType.NumberOfItemsHEX64:
type = Util.PerformanceCounterTypesType.numberOfItemsHEX64;
break;
case PerformanceCounterType.NumberOfItemsHEX32:
type = Util.PerformanceCounterTypesType.numberOfItemsHEX32;
break;
default:
throw new WixException(HarvesterErrors.UnsupportedPerformanceCounterType(pct.ToString()));
}
return type;
}
}
}
|