Sha256: a9bfd98788eedc48dc22af87da1959248e61c8fa464097900772045ae469e380

Contents?: true

Size: 1.49 KB

Versions: 14

Compression:

Stored size: 1.49 KB

Contents

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

module TraceView
  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)
      #     TraceView::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] = TraceView::API.backtrace if with_backtrace

        TraceView::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]

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
traceview-3.1.0-java lib/traceview/api/profiling.rb
traceview-3.1.0 lib/traceview/api/profiling.rb
traceview-3.0.5-java lib/traceview/api/profiling.rb
traceview-3.0.5 lib/traceview/api/profiling.rb
traceview-3.0.4-java lib/traceview/api/profiling.rb
traceview-3.0.4 lib/traceview/api/profiling.rb
traceview-3.0.3-java lib/traceview/api/profiling.rb
traceview-3.0.3 lib/traceview/api/profiling.rb
traceview-3.0.2-java lib/traceview/api/profiling.rb
traceview-3.0.2 lib/traceview/api/profiling.rb
traceview-3.0.1-java lib/traceview/api/profiling.rb
traceview-3.0.1 lib/traceview/api/profiling.rb
traceview-3.0.0-java lib/traceview/api/profiling.rb
traceview-3.0.0 lib/traceview/api/profiling.rb