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
7529d82f
Commit
7529d82f
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Logging changes only.
parent
9ae157a5
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ATxCommon/Monitoring/Cpu.cs
+5
-6
5 additions, 6 deletions
ATxCommon/Monitoring/Cpu.cs
with
5 additions
and
6 deletions
ATxCommon/Monitoring/Cpu.cs
+
5
−
6
View file @
7529d82f
...
...
@@ -83,13 +83,12 @@ namespace ATxCommon.Monitoring
_limit
=
25
;
_probation
=
40
;
Log
.
Debug
(
"Initializing CPU monitoring..."
);
try
{
_cpuCounter
=
new
PerformanceCounter
(
"Processor"
,
"% Processor Time"
,
"_Total"
);
Log
.
Debug
(
"CPU monitoring initializing PerformanceCounter (takes 1s)..."
);
_cpuCounter
.
NextValue
();
Thread
.
Sleep
(
1000
);
Log
.
Debug
(
"CPU monitoring current load: {0}"
,
_cpuCounter
.
NextValue
());
Log
.
Debug
(
"CPU monitoring current load: {0
:0.0
}"
,
_cpuCounter
.
NextValue
());
// _monitoringTimer = new Timer(_interval);
_monitoringTimer
=
new
Timer
(
_interval
);
_monitoringTimer
.
Elapsed
+=
UpdateCpuLoad
;
...
...
@@ -106,12 +105,10 @@ namespace ATxCommon.Monitoring
private
void
UpdateCpuLoad
(
object
sender
,
ElapsedEventArgs
e
)
{
_monitoringTimer
.
Enabled
=
false
;
try
{
Log
.
Trace
(
"load values: {0}, average: {1}"
,
string
.
Join
(
", "
,
_loadReadings
),
_load
);
// ConstrainedCopy seems to be the most efficient approach to shift the array:
Array
.
ConstrainedCopy
(
_loadReadings
,
1
,
_loadReadings
,
0
,
3
);
_loadReadings
[
3
]
=
_cpuCounter
.
NextValue
();
_load
=
_loadReadings
.
Average
();
Log
.
Trace
(
"load values: {0}, average: {1}"
,
string
.
Join
(
", "
,
_loadReadings
),
_load
);
if
(
_loadReadings
[
3
]
>
_limit
)
{
Log
.
Debug
(
"CPU load ({0}) violating limit ({1})!"
,
_loadReadings
[
3
],
_limit
);
_behaving
=
0
;
...
...
@@ -119,10 +116,10 @@ namespace ATxCommon.Monitoring
}
else
{
_behaving
++;
if
(
_behaving
==
_probation
)
{
Log
.
Debug
(
"CPU load below limit for {0} cycles,
yay
!"
,
_probation
);
Log
.
Debug
(
"CPU load below limit for {0} cycles,
passing probation
!"
,
_probation
);
// TODO: fire callback for load behaving well
}
else
if
(
_behaving
>
_probation
)
{
Log
.
Debug
(
"CPU load behaving well since {0} cycles."
,
_behaving
);
Log
.
Trace
(
"CPU load behaving well since {0} cycles."
,
_behaving
);
}
else
if
(
_behaving
<
0
)
{
Log
.
Warn
(
"Integer wrap around happened, resetting probation counter!"
);
_behaving
=
0
;
...
...
@@ -135,6 +132,8 @@ namespace ATxCommon.Monitoring
finally
{
_monitoringTimer
.
Enabled
=
true
;
}
Log
.
Info
(
"CPU load: {0:0.0} {1}"
,
_loadReadings
[
3
],
_loadReadings
[
3
]
<
Limit
?
" ["
+
_behaving
+
"]"
:
""
);
Log
.
Trace
(
"load values: {0}, average: {1}"
,
string
.
Join
(
", "
,
_loadReadings
),
_load
);
}
}
...
...
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