group patches and load after environment setup

Fixes #2668
This commit is contained in:
Joao Duarte 2015-02-23 11:16:51 +00:00 committed by Jordan Sissel
parent e470807399
commit 9561ade035
7 changed files with 41 additions and 36 deletions

View file

@ -158,3 +158,5 @@ module LogStash
end
end
end
require "logstash/patches"

3
lib/logstash/patches.rb Normal file
View file

@ -0,0 +1,3 @@
require "logstash/patches/bugfix_jruby_2558"
require "logstash/patches/cabin"
require "logstash/patches/profile_require_calls"

View file

@ -0,0 +1,34 @@
if ENV["PROFILE_BAD_LOG_CALLS"] || $DEBUGLIST.include?("log")
# Set PROFILE_BAD_LOG_CALLS=1 in your environment if you want
# to track down logger calls that cause performance problems
#
# Related research here:
# https://github.com/jordansissel/experiments/tree/master/ruby/logger-string-vs-block
#
# Basically, the following is wastes tons of effort creating objects that are
# never used if the log level hides the log:
#
# logger.debug("something happend", :what => Happened)
#
# This is shown to be 4x faster:
#
# logger.debug(...) if logger.debug?
#
# I originally intended to use RubyParser and SexpProcessor to
# process all the logstash ruby code offline, but it was much
# faster to write this monkeypatch to warn as things are called.
require "cabin/mixins/logger"
module Cabin::Mixins::Logger
LEVELS.keys.each do |level|
m = "original_#{level}".to_sym
predicate = "#{level}?".to_sym
alias_method m, level
define_method(level) do |*args|
if !send(predicate)
warn("Unconditional log call", :location => caller[0])
end
send(m, *args)
end
end
end
end # PROFILE_BAD_LOG_CALLS

View file

@ -1,3 +1,5 @@
$DEBUGLIST = (ENV["DEBUG"] || "").split(",")
require "logstash/environment"
ENV["GEM_HOME"] = ENV["GEM_PATH"] = LogStash::Environment.logstash_gem_home

View file

@ -9,43 +9,7 @@ LogStash::Environment.bundler_setup!
LogStash::Environment.load_locale!
Thread.abort_on_exception = true
if ENV["PROFILE_BAD_LOG_CALLS"] || $DEBUGLIST.include?("log")
# Set PROFILE_BAD_LOG_CALLS=1 in your environment if you want
# to track down logger calls that cause performance problems
#
# Related research here:
# https://github.com/jordansissel/experiments/tree/master/ruby/logger-string-vs-block
#
# Basically, the following is wastes tons of effort creating objects that are
# never used if the log level hides the log:
#
# logger.debug("something happend", :what => Happened)
#
# This is shown to be 4x faster:
#
# logger.debug(...) if logger.debug?
#
# I originally intended to use RubyParser and SexpProcessor to
# process all the logstash ruby code offline, but it was much
# faster to write this monkeypatch to warn as things are called.
require "cabin/mixins/logger"
module Cabin::Mixins::Logger
LEVELS.keys.each do |level|
m = "original_#{level}".to_sym
predicate = "#{level}?".to_sym
alias_method m, level
define_method(level) do |*args|
if !send(predicate)
warn("Unconditional log call", :location => caller[0])
end
send(m, *args)
end
end
end
end # PROFILE_BAD_LOG_CALLS
require "logstash/monkeypatches-for-bugs"
require "logstash/monkeypatches-for-debugging"
require "logstash/namespace"
require "logstash/program"