Skip to content

Commit

Permalink
Make getrusage-total a sub
Browse files Browse the repository at this point in the history
- we only need it in the supervisor loop
- and it doesn't do anything with self
- more for readability and scoping than anything else
  • Loading branch information
lizmat committed Oct 27, 2017
1 parent 6aa150d commit 09e038c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/core/ThreadPoolScheduler.pm
Expand Up @@ -471,9 +471,17 @@ my class ThreadPoolScheduler does Scheduler {
scheduler-debug "Added a timer worker thread";
}

sub getrusage-total() is raw {
my \rusage = nqp::getrusage();
nqp::atpos_i(rusage, nqp::const::RUSAGE_UTIME_SEC) * 1000000
+ nqp::atpos_i(rusage, nqp::const::RUSAGE_UTIME_MSEC)
+ nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_SEC) * 1000000
+ nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_MSEC)
}

scheduler-debug "Supervisor started";
my num $last-rusage-time = nqp::time_n;
my int $last-usage = self!getrusage-total();
my int $last-usage = getrusage-total;
my num @last-utils = 0e0 xx NUM_SAMPLES;
my int $cpu-cores = nqp::cpucores();
scheduler-debug "Supervisor thinks there are $cpu-cores CPU cores";
Expand All @@ -487,7 +495,7 @@ my class ThreadPoolScheduler does Scheduler {
my num $now = nqp::time_n;
my num $rusage-period = $now - $last-rusage-time;
$last-rusage-time = $now;
my int $current-usage = self!getrusage-total();
my int $current-usage = getrusage-total();
my int $usage-delta = $current-usage - $last-usage;
$last-usage = $current-usage;

Expand Down Expand Up @@ -544,14 +552,6 @@ my class ThreadPoolScheduler does Scheduler {
}
}

method !getrusage-total() {
my \rusage = nqp::getrusage();
nqp::atpos_i(rusage, nqp::const::RUSAGE_UTIME_SEC) * 1000000 +
nqp::atpos_i(rusage, nqp::const::RUSAGE_UTIME_MSEC) +
nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_SEC) * 1000000 +
nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_MSEC)
}

# Tweak workers for non-empty queues
method !tweak-workers(\queue, \worker-list, &add-worker, $cores, $per-core-util) {

Expand Down

0 comments on commit 09e038c

Please sign in to comment.