### Home Classes Methods

### In Files

- lib/amalgalite/profile_tap.rb

### Parent

Object

### Methods

- ::new
- #mean
- #reset!
- #sample
- #stddev
- #to_a
- #to_h
- #to_s

### Files

- HISTORY.rdoc
- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- Amalgalite
- Amalgalite::Aggregate
- Amalgalite::Blob
- Amalgalite::Blob::Error
- Amalgalite::Boolean
- Amalgalite::BusyHandler
- Amalgalite::BusyTimeout
- Amalgalite::CSVTableImporter
- Amalgalite::Column
- Amalgalite::Database
- Amalgalite::Database::AggregateError
- Amalgalite::Database::BusyHandlerError
- Amalgalite::Database::FunctionError
- Amalgalite::Database::InvalidModeError
- Amalgalite::Database::ProgressHandlerError
- Amalgalite::Database::TransactionBehavior
- Amalgalite::Error
- Amalgalite::Function
- Amalgalite::Index
- Amalgalite::MemoryDatabase
- Amalgalite::Packer
- Amalgalite::Paths
- Amalgalite::ProfileSampler
- Amalgalite::ProfileTap
- Amalgalite::ProgressHandler
- Amalgalite::Requires
- Amalgalite::SQLite3
- Amalgalite::SQLite3::Constants
- Amalgalite::SQLite3::Constants::Config
- Amalgalite::SQLite3::Constants::DBStatus
- Amalgalite::SQLite3::Constants::DataType
- Amalgalite::SQLite3::Constants::Helpers
- Amalgalite::SQLite3::Constants::Open
- Amalgalite::SQLite3::Constants::ResultCode
- Amalgalite::SQLite3::Constants::StatementStatus
- Amalgalite::SQLite3::Constants::Status
- Amalgalite::SQLite3::Database
- Amalgalite::SQLite3::Database::DBStatus
- Amalgalite::SQLite3::Database::Function
- Amalgalite::SQLite3::Database::Stat
- Amalgalite::SQLite3::Stat
- Amalgalite::SQLite3::Status
- Amalgalite::SQLite3::Version
- Amalgalite::Schema
- Amalgalite::Statement
- Amalgalite::Table
- Amalgalite::Taps
- Amalgalite::Taps::IO
- Amalgalite::Taps::Stderr
- Amalgalite::Taps::Stdout
- Amalgalite::Taps::StringIO
- Amalgalite::TraceTap
- Amalgalite::TypeMap
- Amalgalite::TypeMaps
- Amalgalite::TypeMaps::DefaultMap
- Amalgalite::TypeMaps::StorageMap
- Amalgalite::TypeMaps::TextMap
- Amalgalite::Version
- Amalgalite::View
- Kernel
- Object

No matching classes.

# Amalgalite::ProfileSampler

A ProfileSampler is a sampler of profile times. It aggregates up profile events that happen for the same source. It is based upon the RFuzz::Sampler class from the rfuzz gem

### Public Class Methods

new( name ) click to toggle source

create a new sampler with the given name

    # File lib/amalgalite/profile_tap.rb, line 16
    def initialize( name )
      @name = name
      reset!
    end

### Public Instance Methods

mean() click to toggle source

return the mean of the data

    # File lib/amalgalite/profile_tap.rb, line 50
    def mean
      @sum / @n
    end

reset!() click to toggle source

reset the internal state so it may be used again

    # File lib/amalgalite/profile_tap.rb, line 24
    def reset!
      @sum   = 0.0
      @sumsq = 0.0
      @n     = 0
      @min   = 0.0
      @max   = 0.0
    end

sample( value ) click to toggle source

add a sample to the calculations

    # File lib/amalgalite/profile_tap.rb, line 35
    def sample( value )
      @sum   += value
      @sumsq += (value * value)
      if @n == 0 then
        @min = @max = value
      else
        @min = value if value < @min
        @max = value if value > @max
      end
      @n += 1
    end

stddev() click to toggle source

returns the standard deviation of the data

    # File lib/amalgalite/profile_tap.rb, line 57
    def stddev
      begin
        return 0.0 if ( 1 == @n )
        Math.sqrt( (@sumsq - ( @sum * @sum / @n)) / (@n-1) )
      rescue Errno::EDOM
        return 0.0
      end
    end

to_a() click to toggle source

return all the values as an array

    # File lib/amalgalite/profile_tap.rb, line 69
    def to_a
      [ @name, @sum, @sumsq, @n, mean, stddev, @min, @max ]
    end

to_h() click to toggle source

return all the values as a hash

    # File lib/amalgalite/profile_tap.rb, line 76
    def to_h
      { 'name'    => @name,  'n' => @n,
        'sum'     => @sum,   'sumsq'   => @sumsq, 'mean'    => mean,
        'stddev'  => stddev, 'min'     => @min,   'max'     => @max }
    end

to_s() click to toggle source

return a string containing the sampler summary

    # File lib/amalgalite/profile_tap.rb, line 85
    def to_s
      "[%s] => sum: %d, sumsq: %d, n: %d, mean: %0.6f, stddev: %0.6f, min: %d, max: %d" % self.to_a
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.