Sha256: 7fe4134c48d96d0e91010a6a546621a0816506bf2e54d8aa271a5338c7013598

Contents?: true

Size: 1.46 KB

Versions: 43

Compression:

Stored size: 1.46 KB

Contents

# Copyright (c) 2013 AppNeta, Inc.
# All rights reserved.

module Oboe
  module API
    ##
    # Module that provides profiling of arbitrary blocks of code
    module Profiling
      ##
      # Public: Profile a given block of code. Detect any exceptions thrown by
      # the block and report errors.
      #
      # profile_name - A name used to identify the block being profiled.
      # report_kvs - A hash containing key/value pairs that will be reported along
      #              with the event of this profile (optional).
      # with_backtrace - Boolean to indicate whether a backtrace should
      #                  be collected with this trace event.
      #
      # Example
      #
      #   def computation(n)
      #     Oboe::API.profile('fib', { :n => n }) do
      #       fib(n)
      #     end
      #   end
      #
      # Returns the result of the block.
      def profile(profile_name, report_kvs = {}, with_backtrace = false)
        report_kvs[:Language] ||= :ruby
        report_kvs[:ProfileName] ||= profile_name
        report_kvs[:Backtrace] = Oboe::API.backtrace if with_backtrace

        Oboe::API.log(nil, 'profile_entry', report_kvs)

        begin
          yield
        rescue => e
          log_exception(nil, e)
          raise
        ensure
          exit_kvs = {}
          exit_kvs[:Language] = :ruby
          exit_kvs[:ProfileName] = report_kvs[:ProfileName]

          Oboe::API.log(nil, 'profile_exit', exit_kvs)
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
oboe-2.7.19-java lib/oboe/api/profiling.rb
oboe-2.7.19 lib/oboe/api/profiling.rb
oboe-2.7.18-java lib/oboe/api/profiling.rb
oboe-2.7.18 lib/oboe/api/profiling.rb
oboe-2.7.17.1-java lib/oboe/api/profiling.rb
oboe-2.7.17.1 lib/oboe/api/profiling.rb
oboe-2.7.16.1 lib/oboe/api/profiling.rb
oboe-2.7.16.1-java lib/oboe/api/profiling.rb
oboe-2.7.15.1-java lib/oboe/api/profiling.rb
oboe-2.7.15.1 lib/oboe/api/profiling.rb
oboe-2.7.14.1-java lib/oboe/api/profiling.rb
oboe-2.7.14.1 lib/oboe/api/profiling.rb
oboe-2.7.13.3-java lib/oboe/api/profiling.rb
oboe-2.7.13.3 lib/oboe/api/profiling.rb
oboe-2.7.12.1-java lib/oboe/api/profiling.rb
oboe-2.7.12.1 lib/oboe/api/profiling.rb
oboe-2.7.11.1 lib/oboe/api/profiling.rb
oboe-2.7.11.1-java lib/oboe/api/profiling.rb
oboe-2.7.10.1-java lib/oboe/api/profiling.rb
oboe-2.7.10.1 lib/oboe/api/profiling.rb