private IEnumerable <string> GetDefaultCounters() { return(DefaultCounters.Select(path => { return PdhHelper.TranslateLocalCounterPath(path); })); }
// // BeginProcessing() is invoked once per pipeline // protected override void BeginProcessing() { if (Platform.IsIoT) { // IoT does not have the '$env:windir\System32\pdh.dll' assembly which is required by this cmdlet. throw new PlatformNotSupportedException(); } _pdhHelper = new PdhHelper(); _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager(); uint res = _pdhHelper.ConnectToDataSource(); if (res != PdhResults.PDH_CSTATUS_VALID_DATA) { ReportPdhError(res, true); return; } if (Continuous.IsPresent && _maxSamplesSpecified) { Exception exc = new Exception(string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterContinuousOrMaxSamples"))); ThrowTerminatingError(new ErrorRecord(exc, "CounterContinuousOrMaxSamples", ErrorCategory.InvalidArgument, null)); } }
protected override void BeginProcessing() { this._resourceMgr = new ResourceManager("GetEventResources", Assembly.GetExecutingAssembly()); if ((Environment.OSVersion.Version.Major < 6) || ((Environment.OSVersion.Version.Major == 6) && (Environment.OSVersion.Version.Minor < 1))) { Exception exception = new Exception(this._resourceMgr.GetString("ExportCtrWin7Required")); base.ThrowTerminatingError(new ErrorRecord(exception, "ExportCtrWin7Required", ErrorCategory.NotImplemented, null)); } this._pdhHelper = new PdhHelper(Environment.OSVersion.Version.Major < 6); this.ValidateFormat(); if (this.Circular.IsPresent && (this._maxSize == 0)) { Exception exception2 = new Exception(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("CounterCircularNoMaxSize"), new object[0])); base.WriteError(new ErrorRecord(exception2, "CounterCircularNoMaxSize", ErrorCategory.InvalidResult, null)); } long res = this._pdhHelper.ConnectToDataSource(); if (res != 0) { this.ReportPdhError(res, true); } res = this._pdhHelper.OpenQuery(); if (res != 0) { this.ReportPdhError(res, true); } }
// // BeginProcessing() is invoked once per pipeline // protected override void BeginProcessing() { #if CORECLR if (Platform.IsIoT) { // IoT does not have the '$env:windir\System32\pdh.dll' assembly which is required by this cmdlet. throw new PlatformNotSupportedException(); } // PowerShell Core requires at least Windows 7, // so no version test is needed _pdhHelper = new PdhHelper(false); #else _pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6); #endif _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager(); uint res = _pdhHelper.ConnectToDataSource(); if (res != 0) { ReportPdhError(res, true); return; } if (Continuous.IsPresent && _maxSamplesSpecified) { Exception exc = new Exception(string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterContinuousOrMaxSamples"))); ThrowTerminatingError(new ErrorRecord(exc, "CounterContinuousOrMaxSamples", ErrorCategory.InvalidArgument, null)); } }
public void ReadNextSet_WithComputersOverload_DefaultCounters_RetrievesAll() { using (var pdhHelper = new PdhHelper(new string[] { Environment.MachineName }, PerfmonCounterReader.DefaultCounters, true)) { var counters = pdhHelper.ReadNextSet(); Assert.True(counters.CounterSamples.Count >= 6); } }
public void ReadNextSet_DefaultCounters_RetrievesAll() { using (var pdhHelper = new PdhHelper(PerfmonCounterReader.DefaultCounters)) { var counters = pdhHelper.ReadNextSet(); Assert.True(counters.CounterSamples.Count >= 6); } }
public void ReadNextSet_WithComputersOverload_DefaultCounters_RetrievesAll() { using (var pdhHelper = new PdhHelper(PerfmonCounterReader.DefaultCounters, true)) { var counters = pdhHelper.ReadNextSet(); Assert.True(counters.CounterSamples.Count >= 6); } }
public void ReadNextSet_DefaultCounters_DataHasApproximatelyCorrectTimestamps() { using (var pdhHelper = new PdhHelper(PerfmonCounterReader.DefaultCounters)) { DateTime now = DateTime.Now; var counters = pdhHelper.ReadNextSet(); Assert.True(counters.CounterSamples.All(sample => Math.Abs((sample.Timestamp - now).TotalSeconds) <= 4)); } }
// // BeginProcessing() is invoked once per pipeline // protected override void BeginProcessing() { #if CORECLR if (Platform.IsIoT) { // IoT does not have the '$env:windir\System32\pdh.dll' assembly which is required by this cmdlet. throw new PlatformNotSupportedException(); } // PowerShell Core requires at least Windows 7, // so no version test is needed _pdhHelper = new PdhHelper(false); #else // // Determine the OS version: this cmdlet requires Windows 7 // because it uses new Pdh functionality. // Version osVersion = System.Environment.OSVersion.Version; if (osVersion.Major < 6 || (osVersion.Major == 6 && osVersion.Minor < 1)) { string msg = _resourceMgr.GetString("ExportCtrWin7Required"); Exception exc = new Exception(msg); ThrowTerminatingError(new ErrorRecord(exc, "ExportCtrWin7Required", ErrorCategory.NotImplemented, null)); } _pdhHelper = new PdhHelper(osVersion.Major < 6); #endif _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager(); // // Validate the Format and CounterSamples arguments // ValidateFormat(); if (Circular.IsPresent && _maxSize == 0) { string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterCircularNoMaxSize")); Exception exc = new Exception(msg); WriteError(new ErrorRecord(exc, "CounterCircularNoMaxSize", ErrorCategory.InvalidResult, null)); } uint res = _pdhHelper.ConnectToDataSource(); if (res != 0) { ReportPdhError(res, true); } res = _pdhHelper.OpenQuery(); if (res != 0) { ReportPdhError(res, true); } }
// // BeginProcessing() is invoked once per pipeline // protected override void BeginProcessing() { _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager(); #if CORECLR // PowerShell Core requires at least Windows 7, // so no version test is needed _pdhHelper = new PdhHelper(false); #else _pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6); #endif }
protected override void BeginProcessing() { this._resourceMgr = new ResourceManager("GetEventResources", Assembly.GetExecutingAssembly()); this._pdhHelper = new PdhHelper(Environment.OSVersion.Version.Major < 6); long res = this._pdhHelper.ConnectToDataSource(); if (res != 0) { this.ReportPdhError(res, true); } else if (this.Continuous.IsPresent && this._maxSamplesSpecified) { Exception exception = new Exception(string.Format(CultureInfo.CurrentCulture, this._resourceMgr.GetString("CounterContinuousOrMaxSamples"), new object[0])); base.ThrowTerminatingError(new ErrorRecord(exception, "CounterContinuousOrMaxSamples", ErrorCategory.InvalidArgument, null)); } }
// // BeginProcessing() is invoked once per pipeline // protected override void BeginProcessing() { #if CORECLR if (Platform.IsIoT) { // IoT does not have the '$env:windir\System32\pdh.dll' assembly which is required by this cmdlet. throw new PlatformNotSupportedException(); } // PowerShell Core requires at least Windows 7, // so no version test is needed _pdhHelper = new PdhHelper(false); #else _pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6); #endif _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager(); }
private IEnumerable <PerformanceCounterSampleSet> ProcessGetCounter(IEnumerable <string> counters, TimeSpan sampleInterval, int maxSamples, CancellationToken token) { using (PdhHelper helper = new PdhHelper(this._computerNames, counters, this._ignoreBadStatusCodes)) { int samplesRead = 0; do { PerformanceCounterSampleSet set = helper.ReadNextSet(); if (null != set) { yield return(set); } samplesRead++; }while (((maxSamples == INFINITIY) || (samplesRead < maxSamples)) && !token.WaitHandle.WaitOne(sampleInterval, true)); } }
// // BeginProcessing() is invoked once per pipeline // protected override void BeginProcessing() { _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager(); // // Determine the OS version: this cmdlet requires Windows 7 // because it uses new Pdh functionality. // if (System.Environment.OSVersion.Version.Major < 6 || (System.Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor < 1)) { string msg = _resourceMgr.GetString("ExportCtrWin7Required"); Exception exc = new Exception(msg); ThrowTerminatingError(new ErrorRecord(exc, "ExportCtrWin7Required", ErrorCategory.NotImplemented, null)); } _pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6); // // Validate the Format and CounterSamples arguments // ValidateFormat(); if (Circular.IsPresent && _maxSize == 0) { string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterCircularNoMaxSize")); Exception exc = new Exception(msg); WriteError(new ErrorRecord(exc, "CounterCircularNoMaxSize", ErrorCategory.InvalidResult, null)); } uint res = _pdhHelper.ConnectToDataSource(); if (res != 0) { ReportPdhError(res, true); } res = _pdhHelper.OpenQuery(); if (res != 0) { ReportPdhError(res, true); } }
// // BeginProcessing() is invoked once per pipeline // protected override void BeginProcessing() { _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager(); _pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6); uint res = _pdhHelper.ConnectToDataSource(); if (res != 0) { ReportPdhError(res, true); return; } if (Continuous.IsPresent && _maxSamplesSpecified) { Exception exc = new Exception(string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterContinuousOrMaxSamples"))); ThrowTerminatingError(new ErrorRecord(exc, "CounterContinuousOrMaxSamples", ErrorCategory.InvalidArgument, null)); } }
// // BeginProcessing() is invoked once per pipeline // protected override void BeginProcessing() { _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager(); _pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6); }
protected override void BeginProcessing() { this._resourceMgr = new ResourceManager("GetEventResources", Assembly.GetExecutingAssembly()); this._pdhHelper = new PdhHelper(Environment.OSVersion.Version.Major < 6); }
protected override bool ReleaseHandle() { return(PdhHelper.PdhCloseLog(handle, 0) == 0); }
protected override bool ReleaseHandle() { return(PdhHelper.PdhCloseQuery(handle) == 0); }