Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auto-tx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vamp
auto-tx
Commits
149cc59b
Commit
149cc59b
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Homogenize code with ATxCommon.
parent
2eef7120
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ATxDiagnostics/ATxDiagnostics.cs
+18
-14
18 additions, 14 deletions
ATxDiagnostics/ATxDiagnostics.cs
with
18 additions
and
14 deletions
ATxDiagnostics/ATxDiagnostics.cs
+
18
−
14
View file @
149cc59b
...
...
@@ -30,25 +30,31 @@ namespace ATxDiagnostics
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
*/
Log
.
Debug
(
SystemChecks
.
GetCpuUsage
());
Log
.
Debug
(
QueryCpuLoad
());
}
private
static
int
QueryCpuLoad
()
{
Log
.
Trace
(
"Querying WMI for CPU load..."
);
var
searcher
=
new
ManagementObjectSearcher
(
"root\\CIMV2"
,
"select Name, PercentProcessorTime from
Win32_PerfFormattedData_PerfOS_Processor"
,
new
EnumerationOptions
{
Timeout
=
new
TimeSpan
(
0
,
0
,
10
),
ReturnImmediately
=
false
,
}
);
var
watch
=
Stopwatch
.
StartNew
();
var
queryString
=
"SELECT Name, PercentProcessorTime "
+
"FROM
Win32_PerfFormattedData_PerfOS_Processor"
;
var
opts
=
new
EnumerationOptions
{
Timeout
=
new
TimeSpan
(
0
,
0
,
10
),
ReturnImmediately
=
false
,
}
;
var
searcher
=
new
ManagementObjectSearcher
(
""
,
queryString
,
opts
);
Int32
usageInt32
=
-
1
;
var
managementObjects
=
searcher
.
Get
();
if
(
managementObjects
.
Count
==
0
)
{
Log
.
Error
(
"No objects returned from WMI!"
);
watch
.
Stop
();
Log
.
Debug
(
"WMI query took {0} ms."
,
watch
.
ElapsedMilliseconds
);
return
-
1
;
}
Log
.
Trace
(
"WMI query returned {0} objects."
,
managementObjects
.
Count
);
foreach
(
var
mo
in
managementObjects
)
{
var
obj
=
(
ManagementObject
)
mo
;
...
...
@@ -58,16 +64,14 @@ namespace ATxDiagnostics
usageInt32
=
Convert
.
ToInt32
(
usage
);
Log
.
Trace
(
"CPU usage {1}: {0}"
,
usageInt32
,
name
);
//if (name.ToString().Equals("_Total")) {
// usageInt32 = Convert.ToInt32(usage);
// Log.Trace("CPU usage: {0}", usageInt32);
//}
}
managementObjects
.
Dispose
();
searcher
.
Dispose
();
watch
.
Stop
();
Log
.
Debug
(
"WMI query took {0} ms."
,
watch
.
ElapsedMilliseconds
);
return
usageInt32
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment