Class: Cubicle::Aggregation::Profiler

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aggregation) ⇒ Profiler

Returns a new instance of Profiler.



39
40
41
# File 'lib/cubicle/aggregation/profiler.rb', line 39

def initialize(aggregation)
  @aggregation = aggregation
end

Instance Attribute Details

#aggregationObject (readonly)

Instance methods



38
39
40
# File 'lib/cubicle/aggregation/profiler.rb', line 38

def aggregation
  @aggregation
end

Class Method Details

.clear!Object



32
33
34
# File 'lib/cubicle/aggregation/profiler.rb', line 32

def clear!
  collection.drop
end

.collectionObject



20
21
22
23
24
25
26
27
# File 'lib/cubicle/aggregation/profiler.rb', line 20

def collection
  @@collection_name ||= "cubicle.profiler"
  unless Cubicle.mongo.database.collection_names.include?(@@collection_name)
    @@collection = Cubicle.mongo.database.create_collection(@@collection_name, :capped=>true, :size=>max_size_in_mb * 1000000)
  else
    @@collection ||= Cubicle.mongo.database[@@collection_name]
  end
end

.collection=(collection_name) ⇒ Object



28
29
30
# File 'lib/cubicle/aggregation/profiler.rb', line 28

def collection=(collection_name)
  @@collection_name = collection_name
end

.enabled=(val) ⇒ Object



9
10
11
# File 'lib/cubicle/aggregation/profiler.rb', line 9

def enabled=(val)
  @@enabled = val
end

.enabled?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/cubicle/aggregation/profiler.rb', line 6

def enabled?
  @@enabled ||= false
end

.max_size_in_mbObject



13
14
15
# File 'lib/cubicle/aggregation/profiler.rb', line 13

def max_size_in_mb
  @@max_size_in_mb = 250
end

.max_size_in_mb=(max) ⇒ Object



16
17
18
# File 'lib/cubicle/aggregation/profiler.rb', line 16

def max_size_in_mb=(max)
  @@max_size_in_mb = max
end

Instance Method Details

#measure(action, stats) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/cubicle/aggregation/profiler.rb', line 55

def measure(action,stats)
  start = Time.now
  result = yield
  stop = Time.now
  record_stats(stats.merge({
          :action=>action,
          :timeMillis=>(stop-start)*1000
  }))
  result
end

#record_map_reduce_result(query, mr_options, result, reason, aggregation_info = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cubicle/aggregation/profiler.rb', line 43

def record_map_reduce_result(query,mr_options,result,reason,aggregation_info=nil)
  record_stats(result.merge({
          :action=>:map_reduce,
          :source=>query.source_collection_name,
          :dimensions=>query.dimensions.map{|m|m.name},
          :measures=>query.dimensions.map{|m|m.name},
          :query=>mr_options["query"].inspect,
          :reason=>reason,
          :aggregation_info_id=>aggregation_info ? aggregation_info._id : nil
  }))
end