Merge branch '63874-use-process-cpu-time-instead-of-thread-for-cpu-metrics' into 'master'

Use PROCESS_CPUTIME_ID for cpu time metrics

Closes #63874

See merge request gitlab-org/gitlab-ce!30166
This commit is contained in:
Stan Hu 2019-06-28 19:34:25 +00:00
commit 388a496443
2 changed files with 5 additions and 13 deletions

View File

@ -57,17 +57,9 @@ module Gitlab
end
end
# THREAD_CPUTIME is not supported on OS X
if Process.const_defined?(:CLOCK_THREAD_CPUTIME_ID)
def self.cpu_time
Process
.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :float_second)
end
else
def self.cpu_time
Process
.clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :float_second)
end
def self.cpu_time
Process
.clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :float_second)
end
# Returns the current real time in a given precision.

View File

@ -52,13 +52,13 @@ describe Gitlab::Metrics::System do
end
describe '.cpu_time' do
it 'returns a Fixnum' do
it 'returns a Float' do
expect(described_class.cpu_time).to be_an(Float)
end
end
describe '.real_time' do
it 'returns a Fixnum' do
it 'returns a Float' do
expect(described_class.real_time).to be_an(Float)
end
end