Module: Vedeu::Logging::Debug

Extended by:
Debug
Included in:
Debug
Defined in:
lib/vedeu/logging/debug.rb

Overview

Provides a stack trace of a running client application upon exit in a file for further analysis.

Instance Method Summary collapse

Instance Method Details

#debug(binding = nil, obj = nil) ⇒ void

This method returns an undefined value.

Parameters:

  • binding (Binding) (defaults to: nil)
  • obj (Object) (defaults to: nil)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vedeu/logging/debug.rb', line 17

def debug(binding = nil, obj = nil)
  Vedeu.requires_gem!('pry')

  if obj
    message = ::Pry::ColorPrinter.pp(obj, ''.dup)

    Vedeu.log(type: :debug, message: message)

  elsif binding
    Vedeu::Terminal.cooked_mode!
    Vedeu::Terminal.open do
      Vedeu::Terminal.debugging!

      binding.pry
    end
    Vedeu::Terminal.raw_mode!
  end
end

#ignore_classesArray (private)

Returns:

  • (Array)


104
105
106
107
108
109
110
111
# File 'lib/vedeu/logging/debug.rb', line 104

def ignore_classes
  [
    /^Array/,
    /^Hash/,
    /^String/,
    /^Fixnum/,
  ]
end

#profile(filename = Dir.tmpdir + '/vedeu_profile', &block) ⇒ void

This method returns an undefined value.

:nocov:

Parameters:

  • filename (String) (defaults to: Dir.tmpdir + '/vedeu_profile')

    Optional, and defaults to being written to the /tmp directory.

  • block (Proc)

Yield Returns:

  • (void)

    The section of the application to profile.

Raises:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/vedeu/logging/debug.rb', line 44

def profile(filename = Dir.tmpdir + '/vedeu_profile', &block)
  Vedeu.requires_gem!('ruby-prof')

  raise Vedeu::Error::RequiresBlock unless block_given?

  # ::RubyProf.measure_mode = ::RubyProf::WALL_TIME
  # ::RubyProf.measure_mode = ::RubyProf::PROCESS_TIME
  ::RubyProf.measure_mode = ::RubyProf::CPU_TIME
  # ::RubyProf.measure_mode = ::RubyProf::ALLOCATIONS
  # ::RubyProf.measure_mode = ::RubyProf::MEMORY
  # ::RubyProf.measure_mode = ::RubyProf::GC_TIME
  # ::RubyProf.measure_mode = ::RubyProf::GC_RUNS

  ::RubyProf.start

  work = yield

  result = ::RubyProf.stop
  result.eliminate_methods!(ignore_classes)

  File.open(filename, 'w') do |file|
    # - Creates a HTML visualization of the Ruby stack
    ::RubyProf::CallStackPrinter.new(result).print(file)

    # Used with KCachegrind to analyse performance.
    # ::RubyProf::CallTreePrinter.new(result).print(file)

    # Creates a flat report in text format
    # ::RubyProf::FlatPrinter.new(result).print(file)

    # - same as above but more verbose
    # ::RubyProf::FlatPrinterWithLineNumbers.new(result).print(file)

    # - Creates a call graph report in text format
    # ::RubyProf::GraphPrinter.new(result).print(file)

    # - Creates a call graph report in HTML (separate files per
    #   thread)
    # ::RubyProf::GraphHtmlPrinter.new(result).print(file)

    # - Creates a call graph report in GraphViz's DOT format
    #   which can be converted to an image
    # ::RubyProf::DotPrinter.new(result).print(file)

    # - Creates a call tree report compatible with KCachegrind.
    # ::RubyProf::CallTreePrinter.new(result).print(file)

    # - Uses the other printers to create several reports in one
    #   profiling run
    # ::RubyProf::MultiPrinter.new(result).print(file)
  end

  work
rescue NameError
  yield
end