Class: Profiler::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/profiler/profile.rb

Defined Under Namespace

Classes: ProfilerError

Instance Method Summary collapse

Constructor Details

#initializeProfile

Initialise redis

Author:

  • KILYA



34
35
36
37
38
39
40
# File 'lib/profiler/profile.rb', line 34

def initialize
  @redis = Redis.new(
    host: "127.0.0.1",
    port: 6379,
    db: 15
  )
end

Instance Method Details

#startObject

main point

Author:

  • KILYA



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/profiler/profile.rb', line 44

def start
  output = String.new
  result = RubyProf.profile do
    yield
  end

  printer = RubyProf::FlatPrinter.new(result)
  printer.print(output, min_percent: 0)
  @redis.set(:profile, output)

  nil
rescue StandardError => e
  raise ProfilerError.new e.message.to_s
end