LogicalProcessorInfoProvider Class |
Namespace: Xcalibur.WMI.Hardware.Processor
The LogicalProcessorInfoProvider type exposes the following members.
Name | Description | |
---|---|---|
LogicalProcessorInfoProvider |
Initializes a new instance of the
LogicalProcessorInfoProvider class.
|
Name | Description | |
---|---|---|
Id |
Gets or sets the id.
(Inherited from WmiModelBaseTData, TDataModel.) | |
Query |
Gets or sets the query.
(Inherited from WmiPullModelBaseTData, TDataModel.) | |
QueryBuilder |
Gets or sets the query items.
Note: This is only used for Pull implementations.
(Inherited from WmiModelBaseTData, TDataModel.) | |
Results |
List of results from GetResults or GetResultsAsync.
This has been made public in the event that an alternate method will be used
outside of this class.
(Inherited from WmiModelBaseTData, TDataModel.) | |
Searcher |
The ManagementSeacherObject affiliates with the specific WMI class used when pulling data.
(Inherited from WmiPullModelBaseTData, TDataModel.) | |
WmiClass |
WMI class that corresponds to the searcher.
(Inherited from WmiModelBaseTData, TDataModel.) |
Name | Description | |
---|---|---|
Dispose |
Implement IDisposable.
Do not make this method virtual.
A derived class should not be able to override this method.
(Inherited from WmiModelBaseTData, TDataModel.) | |
Dispose(Boolean) |
Dispose(bool disposing) executes in two distinct scenarios.
If disposing equals true, the method has been called directly
or indirectly by a user's code. Managed and unmanaged resources
can be disposed.
If disposing equals false, the method has been called by the
runtime from inside the finalizer and you should not reference
other objects. Only unmanaged resources can be disposed.
(Inherited from WmiPullModelBaseTData, TDataModel.) | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Get |
Gets the specified object.
(Inherited from WmiModelBaseTData, TDataModel.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Pull |
Gets the results.
(Inherited from WmiPullModelBaseTData, TDataModel.) | |
Refresh |
Performs a Get operation on the current data based on a user specified override.
(Inherited from WmiPullModelBaseTData, TDataModel.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
Update(Int32) |
Updates this instance.
(Inherited from WmiPullModelBaseTData, TDataModel.) | |
UpdateTConfig(TConfig, Int32) |
Updates the specified configuration.
(Inherited from WmiModelBaseTData, TDataModel.) |
1using System; 2using System.Collections.Generic; 3using System.Management; 4using System.Threading; 5using Xcalibur.Models.Hardware.Processor; 6using Xcalibur.WMI.Hardware.Processor; 7 8// Program 9internal class Program 10{ 11 // Main 12 private static void Main() 13 { 14 // Make a connection to the local machine 15 const string computer = "."; 16 var managementScope = new ManagementScope($@"\\{computer}\root\cimv2", new ConnectionOptions 17 { 18 Impersonation = ImpersonationLevel.Impersonate, 19 Authentication = AuthenticationLevel.Connect 20 21 }); 22 managementScope.Connect(); 23 24 // Logical Processor Info Provider 25 var provider = new LogicalProcessorInfoProvider(managementScope); 26 27 // Fetch first set of data 28 provider.Refresh(); 29 30 // Store first result set so it's not overwritten 31 var storedItems = new List<ILogicalProcessorInfo>(provider.Results); 32 33 // Wait 2 seconds 34 Thread.Sleep(2000); 35 36 // Fetch second set of data 37 provider.Refresh(); 38 39 // Get logical processor count 40 var logicalProcessorCount = provider.Results.Length - 1; 41 42 // Print 43 // Assess each connection based on their time difference against the 44 // PERF_100NSEC_TIMER algorithm. 45 for (var i = 0; i < logicalProcessorCount; i++) 46 { 47 var info = provider.Results[i]; 48 var stored = storedItems[i]; 49 50 Console.WriteLine($"Processor #: \t\t{info.Name}"); 51 52 // Processor Time 53 var processorTime = CalculatePerf100NsecTimer( 54 info.PercentProcessorTime, info.TimestampSys100Ns, 55 stored.PercentProcessorTime, stored.TimestampSys100Ns, logicalProcessorCount); 56 Console.WriteLine($"Processor Time: \t{processorTime:n2}%"); 57 58 // Privileged Time 59 var kernelTime = CalculatePerf100NsecTimer( 60 info.PercentPrivilegedTime, info.TimestampSys100Ns, 61 stored.PercentPrivilegedTime, stored.TimestampSys100Ns, logicalProcessorCount); 62 Console.WriteLine($"Privileged Time: \t{kernelTime:n2}%"); 63 64 // User Time 65 var userTime = CalculatePerf100NsecTimer( 66 info.PercentUserTime, info.TimestampSys100Ns, 67 stored.PercentUserTime, stored.TimestampSys100Ns, logicalProcessorCount); 68 Console.WriteLine($"User Time: \t\t{userTime:n2}%"); 69 70 // Interrupt Time 71 var interruptTime = CalculatePerf100NsecTimer( 72 info.PercentInterruptTime, info.TimestampSys100Ns, 73 stored.PercentInterruptTime, stored.TimestampSys100Ns, logicalProcessorCount); 74 Console.WriteLine($"Interrupt Time: \t{interruptTime:n2}%"); 75 76 // Idle Time 77 var idleTime = CalculatePerf100NsecTimer( 78 info.PercentIdleTime, info.TimestampSys100Ns, 79 stored.PercentIdleTime, stored.TimestampSys100Ns, logicalProcessorCount); 80 Console.WriteLine($"Idle Time: \t\t{idleTime:n2}%"); 81 82 // Spacer 83 Console.WriteLine(""); 84 } 85 86 // Read 87 Console.Read(); 88 } 89 90 /// <summary> 91 /// PERF_100NSEC_TIMER algorithm. 92 /// <para/>PERF_100NSEC_TIMER on MSDN 93 /// </summary> 94 /// <param name="newValue">The current value.</param> 95 /// <param name="newDate">The current date.</param> 96 /// <param name="previousValue">The previous value.</param> 97 /// <param name="previousDate">The previous date.</param> 98 /// <param name="processorCount">The processor count.</param> 99 /// <returns></returns> 100 public static double CalculatePerf100NsecTimer( 101 long newValue, ulong newDate, long previousValue, ulong previousDate, int processorCount) 102 { 103 double usage = 0; 104 try 105 { 106 if (previousDate > 0) 107 { 108 double dataDifference = newValue - previousValue; 109 double timeDifference = newDate - previousDate; 110 var dUsage = (dataDifference * 100) / timeDifference; 111 usage = dUsage / processorCount; 112 113 // Enforce positive values 114 usage = usage >= 0 ? usage : 0; 115 } 116 117 else 118 { 119 usage = 0; 120 } 121 } 122 catch 123 { 124 // ignored 125 } 126 127 // Return 128 return usage; 129 } 130} 131 132/* Results: 133 * 134 * Processor #: 0 135 * Processor Time: 8.93% 136 * Privileged Time: 1.55% 137 * User Time: 1.94% 138 * Interrupt Time: 0.19% 139 * Idle Time: 8.34% 140 * 141 * Processor #: 1 142 * Processor Time: 9.61% 143 * Privileged Time: 0.78% 144 * User Time: 2.04% 145 * Interrupt Time: 0.10% 146 * Idle Time: 9.43% 147 * 148 * Processor #: 2 149 * Processor Time: 9.81% 150 * Privileged Time: 0.10% 151 * User Time: 2.52% 152 * Interrupt Time: 0.00% 153 * Idle Time: 8.73% 154 * 155 * Processor #: 3 156 * Processor Time: 7.77% 157 * Privileged Time: 1.36% 158 * User Time: 3.30% 159 * Interrupt Time: 0.00% 160 * Idle Time: 7.88% 161 * 162 * Processor #: 4 163 * Processor Time: 8.55% 164 * Privileged Time: 0.87% 165 * User Time: 3.01% 166 * Interrupt Time: 0.00% 167 * Idle Time: 8.33% 168 * 169 * Processor #: 5 170 * Processor Time: 10.49% 171 * Privileged Time: 0.58% 172 * User Time: 1.36% 173 * Interrupt Time: 0.10% 174 * Idle Time: 9.63% 175 * 176 * Processor #: 6 177 * Processor Time: 8.93% 178 * Privileged Time: 1.07% 179 * User Time: 2.43% 180 * Interrupt Time: 0.00% 181 * Idle Time: 8.46% 182 * 183 * Processor #: 7 184 * Processor Time: 9.42% 185 * Privileged Time: 1.07% 186 * User Time: 1.94% 187 * Interrupt Time: 0.10% 188 * Idle Time: 8.69% 189 * 190 */