-
Notifications
You must be signed in to change notification settings - Fork 0
/
SchedulerCore_StateCount.cpp
86 lines (73 loc) · 2.16 KB
/
SchedulerCore_StateCount.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// Created by simon on 3/18/16.
//
#include "SchedulerCore_StateCount.h"
#include "JobInfo.h"
#include "misc.h"
using namespace Scheduler;
using namespace Core;
const char* ::Scheduler::Core::JobStateString[] = { "none", "queued", "running", "held", "waiting", "transit", "exiting", "suspended", "completed", nullptr };
StateCount::StateCount() : running(0), queued(0), held(0), transit(0), waiting(0), exiting(0), suspended(0), completed(0), crossrun(0), total(0) {}
void StateCount::reset()
{
running = 0;
queued = 0;
transit = 0;
exiting = 0;
held = 0;
waiting = 0;
suspended = 0;
completed = 0;
crossrun = 0;
total = 0;
}
void StateCount::count_states(const std::vector<JobInfo*>& jobs)
{
for (auto j : jobs)
{
switch (j->state)
{
case JobQueued: queued++; break;
case JobRunning: running++; break;
case JobTransit: transit++; break;
case JobExiting: exiting++; break;
case JobHeld: held++; break;
case JobWaiting: waiting++; break;
case JobSuspended: suspended++; break;
case JobCompleted: completed++; break;
case JobCrossRun: crossrun++; break;
default:
sched_log(PBSEVENT_JOB, PBS_EVENTCLASS_JOB, j->job_id.c_str(), "Job in unknown state");
}
}
total = queued + running + transit + exiting + held + waiting + suspended + completed + crossrun;
}
StateCount& StateCount::operator+=(const StateCount& sc)
{
queued += sc.queued;
running += sc.running;
transit += sc.transit;
exiting += sc.exiting;
held += sc.held;
waiting += sc.waiting;
suspended += sc.suspended;
completed += sc.completed;
crossrun += sc.crossrun;
return *this;
}
StateCount StateCount::operator+(const StateCount& rhs) const
{
StateCount sc(*this);
sc.queued += rhs.queued;
sc.running += rhs.running;
sc.transit += rhs.transit;
sc.exiting += rhs.exiting;
sc.held += rhs.held;
sc.waiting += rhs.waiting;
sc.suspended += rhs.suspended;
sc.completed += rhs.completed;
sc.crossrun += rhs.crossrun;
return sc;
}
const char* StateCount::asString(JobState state) const
{ return JobStateString[state]; }