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
cb1a0520
Commit
cb1a0520
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Remove unused method GetCpuUsage.
parent
4ebb8ee0
Branches
bug-cpuload
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
+0
-71
0 additions, 71 deletions
ATxCommon/SystemChecks.cs
with
0 additions
and
71 deletions
ATxCommon/SystemChecks.cs
+
0
−
71
View file @
cb1a0520
...
...
@@ -32,77 +32,6 @@ namespace ATxCommon
return
-
1
;
}
/// <summary>
/// Get the CPU usage in percent over all cores.
/// </summary>
/// <returns>CPU usage in percent or -1 if an error occured.</returns>
public
static
int
GetCpuUsage
()
{
// TODO: fix bug #36
return
0
;
try
{
Log
.
Trace
(
"Querying WMI for CPU load..."
);
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
.
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
.
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 {
Name = mo["Name"],
Usage = mo["PercentProcessorTime"]
}
)
.ToList();
if (cpuTimes.Count == 0)
return -1;
Log.Trace("WMI query returned {0} objects.", cpuTimes.Count);
// The '_Total' value represents the average usage across all cores,
// and is the best representation of overall CPU usage
var query = cpuTimes.Where(x => x.Name.ToString() == "_Total").Select(x => x.Usage);
var cpuUsage = query.SingleOrDefault();
usageInt32 = Convert.ToInt32(cpuUsage);
Log.Trace("CPU usage: {0}", usageInt32);
return usageInt32;
*/
}
catch
(
Exception
ex
)
{
Log
.
Trace
(
"Error in GetCpuUsage: {0}"
,
ex
.
Message
);
}
Log
.
Trace
(
"Failed querying CPU usage!"
);
return
-
1
;
}
/// <summary>
/// Get the free space of a drive in bytes.
/// </summary>
...
...
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