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
3b05d470
"README.md" did not exist on "c1b689f9a63f513872aec59fe68f7fbfec939eac"
Commit
3b05d470
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Improve code readability and measure WMI query execution time.
parent
59cd92cb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ATxCommon/SystemChecks.cs
+18
-13
18 additions, 13 deletions
ATxCommon/SystemChecks.cs
with
18 additions
and
13 deletions
ATxCommon/SystemChecks.cs
+
18
−
13
View file @
3b05d470
...
...
@@ -40,34 +40,39 @@ namespace ATxCommon
// TODO: fix bug #36
try
{
Log
.
Trace
(
"Querying WMI for CPU load..."
);
var
searcher
=
new
ManagementObjectSearcher
(
"select * from Win32_PerfFormattedData_PerfOS_Processor"
);
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
,
};
searcher
.
Options
=
opts
;
var
searcher
=
new
ManagementObjectSearcher
(
""
,
queryString
,
opts
)
;
Int32
usageInt32
=
-
1
;
/*
var
managementObjects
=
searcher
.
Get
();
Log.Trace("WMI query returned {0} objects.", managementObjects.Count);
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
.
Debug
(
"WMI query returned {0} objects."
,
managementObjects
.
Count
);
foreach
(
var
mo
in
managementObjects
)
{
var
obj
=
(
ManagementObject
)
mo
;
var
usage
=
obj
[
"PercentProcessorTime"
];
var
name
=
obj
[
"Name"
];
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);
}
Log
.
Debug
(
"CPU usage {1}: {0}"
,
usageInt32
,
name
);
}
watch
.
Stop
();
Log
.
Debug
(
"WMI query took {0} ms."
,
watch
.
ElapsedMilliseconds
);
return
usageInt32
;
*/
/*
var cpuTimes = searcher.Get()
.Cast<ManagementObject>()
.Select(mo => new {
...
...
@@ -87,7 +92,7 @@ namespace ATxCommon
usageInt32 = Convert.ToInt32(cpuUsage);
Log.Trace("CPU usage: {0}", usageInt32);
return usageInt32;
//
*/
*/
}
catch
(
Exception
ex
)
{
Log
.
Trace
(
"Error in GetCpuUsage: {0}"
,
ex
.
Message
);
...
...
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