summaryrefslogtreecommitdiffstats
path: root/lib/puppet/rails
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-08 18:47:26 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-04-22 14:39:36 +1000
commit589f40f8e8769d3bd8de8692222eac8a2f6f30cb (patch)
tree7ddb8499ac5741057cb00bf2e34c956c8e9284aa /lib/puppet/rails
parent042689e06bcee2882a2937b2caeab4529ae5c048 (diff)
downloadpuppet-589f40f8e8769d3bd8de8692222eac8a2f6f30cb.tar.gz
puppet-589f40f8e8769d3bd8de8692222eac8a2f6f30cb.tar.xz
puppet-589f40f8e8769d3bd8de8692222eac8a2f6f30cb.zip
Adding some more fine-grained benchmarks to Rails support
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/rails')
-rw-r--r--lib/puppet/rails/host.rb37
-rw-r--r--lib/puppet/rails/resource.rb11
2 files changed, 26 insertions, 22 deletions
diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb
index 578974555..20d29ae8a 100644
--- a/lib/puppet/rails/host.rb
+++ b/lib/puppet/rails/host.rb
@@ -197,6 +197,8 @@ class Puppet::Rails::Host < ActiveRecord::Base
additions.each do |resource|
build_rails_resource_from_parser_resource(resource)
end
+
+ log_accumulated_marks "Added resources"
}
end
@@ -208,20 +210,28 @@ class Puppet::Rails::Host < ActiveRecord::Base
# Turn a parser resource into a Rails resource.
def build_rails_resource_from_parser_resource(resource)
- args = Puppet::Rails::Resource.rails_resource_initial_args(resource)
+ db_resource = nil
+ accumulate_benchmark("Added resources", :initialization) {
+ args = Puppet::Rails::Resource.rails_resource_initial_args(resource)
+
+ db_resource = self.resources.build(args)
- db_resource = self.resources.build(args)
+ # Our file= method does the name to id conversion.
+ db_resource.file = resource.file
+ }
- # Our file= method does the name to id conversion.
- db_resource.file = resource.file
- resource.eachparam do |param|
- Puppet::Rails::ParamValue.from_parser_param(param).each do |value_hash|
- db_resource.param_values.build(value_hash)
+ accumulate_benchmark("Added resources", :parameters) {
+ resource.eachparam do |param|
+ Puppet::Rails::ParamValue.from_parser_param(param).each do |value_hash|
+ db_resource.param_values.build(value_hash)
+ end
end
- end
+ }
- resource.tags.each { |tag| db_resource.add_resource_tag(tag) }
+ accumulate_benchmark("Added resources", :tags) {
+ resource.tags.each { |tag| db_resource.add_resource_tag(tag) }
+ }
return db_resource
end
@@ -231,20 +241,15 @@ class Puppet::Rails::Host < ActiveRecord::Base
return compiled.values if resources.empty?
# Now for all resources in the catalog but not in the db, we're pretty easy.
- times = Hash.new(0)
additions = []
compiled.each do |ref, resource|
if db_resource = resources[ref]
- db_resource.merge_parser_resource(resource).each do |name, time|
- times[name] += time
- end
+ db_resource.merge_parser_resource(resource)
else
additions << resource
end
end
- times.each do |name, time|
- Puppet.debug("Resource merger(%s) took %0.2f seconds" % [name, time])
- end
+ log_accumulated_marks "Resource merger"
return additions
end
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb
index ef1317871..81505cbd4 100644
--- a/lib/puppet/rails/resource.rb
+++ b/lib/puppet/rails/resource.rb
@@ -2,11 +2,13 @@ require 'puppet'
require 'puppet/rails/param_name'
require 'puppet/rails/param_value'
require 'puppet/rails/puppet_tag'
+require 'puppet/rails/benchmark'
require 'puppet/util/rails/collection_merger'
class Puppet::Rails::Resource < ActiveRecord::Base
include Puppet::Util::CollectionMerger
include Puppet::Util::ReferenceSerializer
+ include Puppet::Rails::Benchmark
has_many :param_values, :dependent => :destroy, :class_name => "Puppet::Rails::ParamValue"
has_many :param_names, :through => :param_values, :class_name => "Puppet::Rails::ParamName"
@@ -79,12 +81,9 @@ class Puppet::Rails::Resource < ActiveRecord::Base
# Make sure this resource is equivalent to the provided Parser resource.
def merge_parser_resource(resource)
- times = {}
- times[:attributes] = Benchmark.realtime { merge_attributes(resource) }
- times[:parameters] = Benchmark.realtime { merge_parameters(resource) }
- times[:tags] = Benchmark.realtime { merge_tags(resource) }
-
- times
+ accumulate_benchmark("Individual resource merger", :attributes) { merge_attributes(resource) }
+ accumulate_benchmark("Individual resource merger", :parameters) { merge_parameters(resource) }
+ accumulate_benchmark("Individual resource merger", :tags) { merge_tags(resource) }
end
def merge_attributes(resource)