Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
e2361806
Commit
e2361806
authored
Mar 21, 2018
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add query counts by model to profiler output
parent
a9a31ce3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
6 deletions
+35
-6
changelogs/unreleased/add-query-counts-to-profiler-output.yml
...gelogs/unreleased/add-query-counts-to-profiler-output.yml
+5
-0
lib/gitlab/profiler.rb
lib/gitlab/profiler.rb
+8
-4
spec/lib/gitlab/profiler_spec.rb
spec/lib/gitlab/profiler_spec.rb
+22
-2
No files found.
changelogs/unreleased/add-query-counts-to-profiler-output.yml
0 → 100644
View file @
e2361806
---
title
:
Add query counts to profiler output
merge_request
:
author
:
type
:
other
lib/gitlab/profiler.rb
View file @
e2361806
...
...
@@ -92,8 +92,8 @@ module Gitlab
if
type
&&
time
@load_times_by_model
||=
{}
@load_times_by_model
[
type
]
||=
0
@load_times_by_model
[
type
]
+=
time
.
to_f
@load_times_by_model
[
type
]
||=
[]
@load_times_by_model
[
type
]
<<
time
.
to_f
end
super
...
...
@@ -135,8 +135,12 @@ module Gitlab
def
self
.
log_load_times_by_model
(
logger
)
return
unless
logger
.
respond_to?
(
:load_times_by_model
)
logger
.
load_times_by_model
.
to_a
.
sort_by
(
&
:last
).
reverse
.
each
do
|
(
model
,
time
)
|
logger
.
info
(
"
#{
model
}
total:
#{
time
.
round
(
2
)
}
ms"
)
summarised_load_times
=
logger
.
load_times_by_model
.
to_a
.
map
do
|
(
model
,
times
)
|
[
model
,
times
.
count
,
times
.
sum
]
end
summarised_load_times
.
sort_by
(
&
:last
).
reverse
.
each
do
|
(
model
,
query_count
,
time
)
|
logger
.
info
(
"
#{
model
}
total (
#{
query_count
}
):
#{
time
.
round
(
2
)
}
ms"
)
end
end
end
...
...
spec/lib/gitlab/profiler_spec.rb
View file @
e2361806
...
...
@@ -110,8 +110,8 @@ describe Gitlab::Profiler do
custom_logger
.
debug
(
'User Load (1.3ms)'
)
custom_logger
.
debug
(
'Project Load (10.4ms)'
)
expect
(
custom_logger
.
load_times_by_model
).
to
eq
(
'User'
=>
2.5
,
'Project'
=>
10.4
)
expect
(
custom_logger
.
load_times_by_model
).
to
eq
(
'User'
=>
[
1.2
,
1.3
]
,
'Project'
=>
[
10.4
]
)
end
it
'logs the backtrace, ignoring lines as appropriate'
do
...
...
@@ -164,4 +164,24 @@ describe Gitlab::Profiler do
end
end
end
describe
'.log_load_times_by_model'
do
it
'logs the model, query count, and time by slowest first'
do
expect
(
null_logger
).
to
receive
(
:load_times_by_model
).
and_return
(
'User'
=>
[
1.2
,
1.3
],
'Project'
=>
[
10.4
]
)
expect
(
null_logger
).
to
receive
(
:info
).
with
(
'Project total (1): 10.4ms'
)
expect
(
null_logger
).
to
receive
(
:info
).
with
(
'User total (2): 2.5ms'
)
described_class
.
log_load_times_by_model
(
null_logger
)
end
it
'does nothing when called with a logger that does not have load times'
do
expect
(
null_logger
).
not_to
receive
(
:info
)
expect
(
described_class
.
log_load_times_by_model
(
null_logger
)).
to
be_nil
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