Instrument Banzai code

This commit is contained in:
Yorick Peterse 2016-04-11 17:42:12 +02:00
parent 15cbbd09fb
commit 935f913165
No known key found for this signature in database
GPG key ID: EDD30D2BEB691AC9
2 changed files with 35 additions and 8 deletions

View file

@ -75,6 +75,29 @@ if Gitlab::Metrics.enabled?
config.instrument_methods(const)
config.instrument_instance_methods(const)
end
# Instruments all Banzai filters
Dir[Rails.root.join('lib', 'banzai', 'filter', '*.rb')].each do |file|
klass = File.basename(file, File.extname(file)).camelize
const = Banzai::Filter.const_get(klass)
config.instrument_methods(const)
config.instrument_instance_methods(const)
end
config.instrument_methods(Banzai::ReferenceExtractor)
config.instrument_instance_methods(Banzai::ReferenceExtractor)
config.instrument_methods(Banzai::Renderer)
config.instrument_methods(Banzai::Querying)
[Issuable, Mentionable, Participable].each do |klass|
config.instrument_instance_methods(klass)
config.instrument_instance_methods(klass::ClassMethods)
end
config.instrument_methods(Gitlab::ReferenceExtractor)
config.instrument_instance_methods(Gitlab::ReferenceExtractor)
end
GC::Profiler.enable

View file

@ -19,8 +19,10 @@ module Banzai
cache_key = full_cache_key(cache_key, context[:pipeline])
if cache_key
Rails.cache.fetch(cache_key) do
cacheless_render(text, context)
Gitlab::Metrics.measure(:banzai_cached_render) do
Rails.cache.fetch(cache_key) do
cacheless_render(text, context)
end
end
else
cacheless_render(text, context)
@ -64,13 +66,15 @@ module Banzai
private
def self.cacheless_render(text, context = {})
result = render_result(text, context)
Gitlab::Metrics.measure(:banzai_cacheless_render) do
result = render_result(text, context)
output = result[:output]
if output.respond_to?(:to_html)
output.to_html
else
output.to_s
output = result[:output]
if output.respond_to?(:to_html)
output.to_html
else
output.to_s
end
end
end