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
5ee528c4
Commit
5ee528c4
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Use a public field to represent the load state
Refers to
#36
parent
bd9275b7
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/Monitoring/Cpu.cs
+11
-2
11 additions, 2 deletions
ATxCommon/Monitoring/Cpu.cs
with
11 additions
and
2 deletions
ATxCommon/Monitoring/Cpu.cs
+
11
−
2
View file @
5ee528c4
...
@@ -55,6 +55,11 @@ namespace ATxCommon.Monitoring
...
@@ -55,6 +55,11 @@ namespace ATxCommon.Monitoring
/// <returns>The average CPU load from the last four readings.</returns>
/// <returns>The average CPU load from the last four readings.</returns>
public
float
Load
{
get
;
private
set
;
}
public
float
Load
{
get
;
private
set
;
}
/// <summary>
/// Flag representing whether the load is considered to be high or low.
/// </summary>
public
bool
HighLoad
{
get
;
private
set
;
}
/// <summary>
/// <summary>
/// How often (in ms) to check the CPU load.
/// How often (in ms) to check the CPU load.
/// </summary>
/// </summary>
...
@@ -116,8 +121,10 @@ namespace ATxCommon.Monitoring
...
@@ -116,8 +121,10 @@ namespace ATxCommon.Monitoring
Log
.
Debug
(
"CPU monitoring initializing PerformanceCounter (takes one second)..."
);
Log
.
Debug
(
"CPU monitoring initializing PerformanceCounter (takes one second)..."
);
_cpuCounter
.
NextValue
();
_cpuCounter
.
NextValue
();
Thread
.
Sleep
(
1000
);
Thread
.
Sleep
(
1000
);
Log
.
Debug
(
"CPU monitoring current load: {0:0.0}"
,
_cpuCounter
.
NextValue
());
var
curLoad
=
_cpuCounter
.
NextValue
();
// _monitoringTimer = new Timer(_interval);
Log
.
Debug
(
"CPU monitoring current load: {0:0.0}"
,
curLoad
);
// now initialize the load state:
HighLoad
=
curLoad
>
_limit
;
_monitoringTimer
=
new
Timer
(
_interval
);
_monitoringTimer
=
new
Timer
(
_interval
);
_monitoringTimer
.
Elapsed
+=
UpdateCpuLoad
;
_monitoringTimer
.
Elapsed
+=
UpdateCpuLoad
;
}
}
...
@@ -177,6 +184,7 @@ namespace ATxCommon.Monitoring
...
@@ -177,6 +184,7 @@ namespace ATxCommon.Monitoring
/// Raise the "LoadAboveLimit" event.
/// Raise the "LoadAboveLimit" event.
/// </summary>
/// </summary>
protected
virtual
void
OnLoadAboveLimit
()
{
protected
virtual
void
OnLoadAboveLimit
()
{
HighLoad
=
true
;
LoadAboveLimit
?.
Invoke
(
this
,
EventArgs
.
Empty
);
LoadAboveLimit
?.
Invoke
(
this
,
EventArgs
.
Empty
);
}
}
...
@@ -184,6 +192,7 @@ namespace ATxCommon.Monitoring
...
@@ -184,6 +192,7 @@ namespace ATxCommon.Monitoring
/// Raise the "LoadBelowLimit" event.
/// Raise the "LoadBelowLimit" event.
/// </summary>
/// </summary>
protected
virtual
void
OnLoadBelowLimit
()
{
protected
virtual
void
OnLoadBelowLimit
()
{
HighLoad
=
false
;
LoadBelowLimit
?.
Invoke
(
this
,
EventArgs
.
Empty
);
LoadBelowLimit
?.
Invoke
(
this
,
EventArgs
.
Empty
);
}
}
}
}
...
...
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