BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
a8ebed60
Commit
a8ebed60
authored
Dec 12, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make `System.monotonic_time` retun seconds represented by float with microsecond precision
parent
b02db1f4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
17 deletions
+26
-17
gitaly_client.rb
lib/gitlab/gitaly_client.rb
+1
-1
method_call.rb
lib/gitlab/metrics/method_call.rb
+11
-7
ruby_sampler.rb
lib/gitlab/metrics/samplers/ruby_sampler.rb
+1
-1
system.rb
lib/gitlab/metrics/system.rb
+5
-4
transaction.rb
lib/gitlab/metrics/transaction.rb
+6
-2
system_spec.rb
spec/lib/gitlab/metrics/system_spec.rb
+2
-2
No files found.
lib/gitlab/gitaly_client.rb
View file @
a8ebed60
...
...
@@ -132,7 +132,7 @@ module Gitlab
self
.
query_time
+=
duration
gitaly_call_histogram
.
observe
(
current_transaction_labels
.
merge
(
gitaly_service:
service
.
to_s
,
rpc:
rpc
.
to_s
),
duration
/
1000.0
)
duration
)
end
def
self
.
current_transaction_labels
...
...
lib/gitlab/metrics/method_call.rb
View file @
a8ebed60
...
...
@@ -4,7 +4,7 @@ module Gitlab
class
MethodCall
MUTEX
=
Mutex
.
new
BASE_LABELS
=
{
module:
nil
,
method:
nil
}.
freeze
attr_reader
:real_time
,
:cpu_time
,
:call_count
,
:labels
attr_reader
:real_time
_seconds
,
:cpu_time
,
:call_count
,
:labels
def
self
.
call_duration_histogram
return
@call_duration_histogram
if
@call_duration_histogram
...
...
@@ -27,37 +27,41 @@ module Gitlab
@transaction
=
transaction
@name
=
name
@labels
=
{
module:
@module_name
,
method:
@method_name
}
@real_time
=
0
@real_time
_seconds
=
0
@cpu_time
=
0
@call_count
=
0
end
# Measures the real and CPU execution time of the supplied block.
def
measure
start_real
=
System
.
monotonic_time
start_real
_seconds
=
System
.
monotonic_time
start_cpu
=
System
.
cpu_time
retval
=
yield
real_time
=
System
.
monotonic_time
-
start_real
real_time
_seconds
=
System
.
monotonic_time
-
start_real_seconds
cpu_time
=
System
.
cpu_time
-
start_cpu
@real_time
+=
real_time
@real_time
_seconds
+=
real_time_seconds
@cpu_time
+=
cpu_time
@call_count
+=
1
if
call_measurement_enabled?
&&
above_threshold?
self
.
class
.
call_duration_histogram
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
real_time
/
1000.0
)
self
.
class
.
call_duration_histogram
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
real_time
_seconds
)
end
retval
end
def
real_time_milliseconds
(
real_time_seconds
*
1000.0
).
to_i
end
# Returns a Metric instance of the current method call.
def
to_metric
Metric
.
new
(
Instrumentation
.
series
,
{
duration:
real_time
,
duration:
real_time
_milliseconds
,
cpu_duration:
cpu_time
,
call_count:
call_count
},
...
...
lib/gitlab/metrics/samplers/ruby_sampler.rb
View file @
a8ebed60
...
...
@@ -52,7 +52,7 @@ module Gitlab
metrics
[
:memory_usage
].
set
(
labels
,
System
.
memory_usage
)
metrics
[
:file_descriptors
].
set
(
labels
,
System
.
file_descriptor_count
)
metrics
[
:sampler_duration
].
observe
(
labels
.
merge
(
worker_label
),
(
System
.
monotonic_time
-
start_time
)
/
1000.0
)
metrics
[
:sampler_duration
].
observe
(
labels
.
merge
(
worker_label
),
System
.
monotonic_time
-
start_time
)
ensure
GC
::
Profiler
.
clear
end
...
...
lib/gitlab/metrics/system.rb
View file @
a8ebed60
...
...
@@ -51,11 +51,12 @@ module Gitlab
Process
.
clock_gettime
(
Process
::
CLOCK_REALTIME
,
precision
)
end
# Returns the current monotonic clock time
in a given
precision.
# Returns the current monotonic clock time
as seconds with microseconds
precision.
#
# Returns the time as a Fixnum.
def
self
.
monotonic_time
(
precision
=
:millisecond
)
Process
.
clock_gettime
(
Process
::
CLOCK_MONOTONIC
,
precision
)
# Returns the time as a Float.
def
self
.
monotonic_time
Process
.
clock_gettime
(
Process
::
CLOCK_MONOTONIC
,
:float_second
)
end
end
end
...
...
lib/gitlab/metrics/transaction.rb
View file @
a8ebed60
...
...
@@ -35,6 +35,10 @@ module Gitlab
@finished_at
?
(
@finished_at
-
@started_at
)
:
0.0
end
def
duration_milliseconds
(
duration
*
1000
).
to_i
end
def
allocated_memory
@memory_after
-
@memory_before
end
...
...
@@ -50,7 +54,7 @@ module Gitlab
@memory_after
=
System
.
memory_usage
@finished_at
=
System
.
monotonic_time
self
.
class
.
metric_transaction_duration_seconds
.
observe
(
labels
,
duration
*
1000
)
self
.
class
.
metric_transaction_duration_seconds
.
observe
(
labels
,
duration
)
self
.
class
.
metric_transaction_allocated_memory_bytes
.
observe
(
labels
,
allocated_memory
*
1024.0
)
Thread
.
current
[
THREAD_KEY
]
=
nil
...
...
@@ -97,7 +101,7 @@ module Gitlab
end
def
track_self
values
=
{
duration:
duration
,
allocated_memory:
allocated_memory
}
values
=
{
duration:
duration
_milliseconds
,
allocated_memory:
allocated_memory
}
@values
.
each
do
|
name
,
value
|
values
[
name
]
=
value
...
...
spec/lib/gitlab/metrics/system_spec.rb
View file @
a8ebed60
...
...
@@ -40,8 +40,8 @@ describe Gitlab::Metrics::System do
end
describe
'.monotonic_time'
do
it
'returns a F
ixnum
'
do
expect
(
described_class
.
monotonic_time
).
to
be_an
(
Integer
)
it
'returns a F
loat
'
do
expect
(
described_class
.
monotonic_time
).
to
be_an
(
Float
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment