Merge
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 19 Nov 2015 09:40:33 +0000
changeset 310 c01892c16c71
parent 309 7ee70a642b24 (current diff)
parent 306 8050d8d3681f (diff)
child 311 1109121c906f
Merge
--- a/web/Gemfile	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/Gemfile	Thu Nov 19 09:40:33 2015 +0000
@@ -21,19 +21,17 @@
 gem "quiet_assets"
 
 group :development do
-  gem "capistrano", "~> 2.15"
+  gem "capistrano", "~> 2.15", require: false
   gem "rvm-capistrano", "~> 1.3"
   gem "pry", "~> 0.9"
   gem "byebug"
   gem "pry-byebug"
   gem "annotate"
   gem "bullet"
+  gem "stackprof"
+  gem "memory_profiler"
 end
 
 group :test do
   gem "rspec-rails"
 end
-
-group :doc do
-  gem "sdoc", {:require=>false}
-end
--- a/web/Gemfile.lock	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/Gemfile.lock	Thu Nov 19 09:40:33 2015 +0000
@@ -105,6 +105,7 @@
     libv8 (3.16.14.7)
     mail (2.6.1)
       mime-types (>= 1.16, < 3)
+    memory_profiler (0.9.6)
     method_source (0.8.2)
     mime-types (2.4.3)
     minitest (5.4.2)
@@ -148,8 +149,6 @@
     rake (10.3.2)
     rake-compiler (0.9.3)
       rake
-    rdoc (4.1.2)
-      json (~> 1.4)
     ref (1.0.5)
     rspec-core (3.1.7)
       rspec-support (~> 3.1.0)
@@ -169,9 +168,6 @@
     rspec-support (3.1.2)
     rvm-capistrano (1.5.4)
       capistrano (~> 2.15.4)
-    sdoc (0.4.1)
-      json (~> 1.7, >= 1.7.7)
-      rdoc (~> 4.0)
     slop (3.6.0)
     sprockets (2.12.2)
       hike (~> 1.2)
@@ -183,6 +179,7 @@
       activesupport (>= 3.0)
       sprockets (>= 2.8, < 4.0)
     sqlite3 (1.3.9)
+    stackprof (0.2.7)
     therubyracer (0.12.1)
       libv8 (~> 3.16.14.0)
       ref
@@ -216,6 +213,7 @@
   jquery-ui-rails
   less-rails
   less-rails-bootstrap
+  memory_profiler
   pry (~> 0.9)
   pry-byebug
   quiet_assets
@@ -224,8 +222,11 @@
   rickshaw_rails!
   rspec-rails
   rvm-capistrano (~> 1.3)
-  sdoc
   sqlite3
+  stackprof
   therubyracer
   turbolinks
   uglifier
+
+BUNDLED WITH
+   1.10.6
--- a/web/app/helpers/settings/benchmark_configurations_helper.rb	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/app/helpers/settings/benchmark_configurations_helper.rb	Thu Nov 19 09:40:33 2015 +0000
@@ -1,7 +1,8 @@
 module Settings::BenchmarkConfigurationsHelper
 
   def all_configurations_for(compare_query)
-    BenchmarkConfiguration.for_benchmark_infos(compare_query.filtered_benchmark_info_ids)
+    BenchmarkConfiguration
+      .for_benchmark_infos(compare_query.filtered_benchmark_info_ids)
   end
 
   def all_configurations_options
--- a/web/app/models/benchmark_batch.rb	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/app/models/benchmark_batch.rb	Thu Nov 19 09:40:33 2015 +0000
@@ -53,10 +53,6 @@
     benchmark_results.find_by(benchmark_info_id: info_id)
   end
 
-  def all_benchmark_infos
-    benchmark_results.map(&:benchmark_info).flatten
-  end
-
   # Returns full path to archive file
   def archive_path
     File.join(self.class.archive_directory, archive_filename)
--- a/web/app/models/benchmark_configuration.rb	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/app/models/benchmark_configuration.rb	Thu Nov 19 09:40:33 2015 +0000
@@ -26,7 +26,7 @@
   end
 
   def self.find_for_results_json(configuration_id)
-    with_preloaded_environment_description.find(configuration_id)
+    includes(:benchmark_batches).find(configuration_id)
   end
 
   def self.for_benchmark_infos(info_ids)
@@ -48,28 +48,57 @@
     end
   end
 
-  def all_benchmark_infos
-    benchmark_batches.
-      includes(benchmark_results: [ :benchmark_info ]).
-      map(&:all_benchmark_infos).
-      flatten.
-      uniq
-  end
-
   def all_dates_when_performed
     SortedSet.new(benchmark_batches.map(&:performed_at).flatten).to_a
   end
 
+  # Return timestamps and durations for each benchmark info ever
+  # recorded for this configuration
+  #
+  # @return
+  #   [
+  #     { name: "Ackermann",
+  #       data: [
+  #         { timestamp: 12312341234, duration: 42 },
+  #         { timestamp: 12312341235, duration: 41 },
+  #         { timestamp: 12312341236, duration: 40 }
+  #       ]
+  #     },
+  #     { name: "Fasta",
+  #       data: [
+  #         { timestamp: 12312341234, duration: 42 },
+  #         { timestamp: 12312341235, duration: 41 },
+  #         { timestamp: 12312341236, duration: 40 }
+  #       ]
+  #     }
+  #   ]
   def to_results_json
-    all_benchmark_infos.map do |info|
-      info.to_results_json_for_configuration(self)
+    convenient_data = {}.tap do |data|
+      BenchmarkResult
+        .where(benchmark_batch_id: benchmark_batches.map(&:id))
+        .includes(:benchmark_info)
+        .includes(:benchmark_batch)
+        .includes(:benchmark_durations)
+        .each do |benchmark_result|
+        data
+          .fetch(benchmark_result.benchmark_name) do
+            data[benchmark_result.benchmark_name] = []
+          end
+          .push(benchmark_result.to_json)
+
+        benchmark_result.to_json
+      end
+    end
+
+    [].tap do |nicely_formatted_json|
+      convenient_data.each do |name, data|
+        nicely_formatted_json << { name: name, data: data }
+      end
     end
   end
 
-  def self.find_or_create_by_name(ctx, name)
-    inst = ctx.where(name: name).first
-    inst = ctx.create!(name: name) unless inst
-    inst
+  def self.find_or_create_by_name(relation, name)
+    relation.find_or_create_by(name: name)
   end
 end
 
--- a/web/app/models/benchmark_info.rb	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/app/models/benchmark_info.rb	Thu Nov 19 09:40:33 2015 +0000
@@ -18,21 +18,11 @@
     bench_info
   end
 
-  def to_results_json_for_configuration(configuration)
-    data = benchmark_results.
-      for_configuration_id(configuration.id).
-      with_batch_and_duration_preloaded.
-      map(&:to_json)
-
-    { name: name, data: data }
-  end
-
   def latest_result_for_configuration(configuration)
-    benchmark_results.
-      for_configuration_id(configuration.id).
-      with_batch_and_duration_preloaded.
-      newest_first.
-      first
+    benchmark_results
+      .select { |r| r.benchmark_batch.benchmark_configuration_id == configuration.id }
+      .sort { |r, s| r.performed_at <=> s.performed_at }
+      .first
   end
 
 end
--- a/web/app/models/benchmark_result.rb	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/app/models/benchmark_result.rb	Thu Nov 19 09:40:33 2015 +0000
@@ -5,19 +5,6 @@
   has_many :benchmark_durations, dependent: :destroy, inverse_of: :benchmark_result
   has_many :benchmark_parameters, dependent: :destroy, inverse_of: :benchmark_result
 
-  scope :for_configuration_id, -> (configuration_id) do
-    joins(:benchmark_batch).
-      where("benchmark_batches.benchmark_configuration_id = ?", configuration_id)
-  end
-
-  scope :with_batch_and_duration_preloaded, -> do
-    includes(:benchmark_batch, :benchmark_durations)
-  end
-
-  scope :newest_first, -> do
-    order("benchmark_batches.performed_at desc, benchmark_batches.created_at desc")
-  end
-
   def average_duration
     sum = benchmark_durations.inject(0) { |acc, val| acc += val.duration }
     sum / benchmark_durations.size
@@ -39,6 +26,10 @@
     benchmark_batch.performed_at
   end
 
+  def benchmark_name
+    benchmark_info.name
+  end
+
   def benchmark_parameters_json
     JSON.generate(benchmark_parameters.collect { |p| p.to_json } )
   end
--- a/web/app/models/compare_query.rb	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/app/models/compare_query.rb	Thu Nov 19 09:40:33 2015 +0000
@@ -10,11 +10,15 @@
   end
 
   def filtered_benchmark_infos
-    BenchmarkInfo.where(id: filtered_benchmark_info_ids)
+    BenchmarkInfo
+      .where(id: filtered_benchmark_info_ids)
+      .includes(benchmark_results: [ :benchmark_batch,
+                                     :benchmark_durations,
+                                     :benchmark_parameters ])
   end
 
   def filtered_benchmark_info_ids
-    benchmark_infos.compact
+    benchmark_infos.select(&:present?).compact
   end
 
 end
--- a/web/app/models/runtime.rb	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/app/models/runtime.rb	Thu Nov 19 09:40:33 2015 +0000
@@ -5,14 +5,6 @@
 
   validates_presence_of :language_id, :name
 
-  def all_benchmark_infos
-    result = Set.new
-    benchmark_batches.each do |batch|
-      batch.benchmark_results.each { |r| result.add r.benchmark_info }
-    end
-    result
-  end
-
   def all_dates_when_performed
     SortedSet.new(benchmark_batches.map(&:performed_at).flatten).to_a
   end
--- a/web/app/models/tag.rb	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/app/models/tag.rb	Thu Nov 19 09:40:33 2015 +0000
@@ -6,14 +6,6 @@
     benchmark_batches.map(&:benchmark_configuration).uniq
   end
 
-  def all_benchmark_infos
-    benchmark_batches.
-      flat_map(&:benchmark_results).
-      map(&:benchmark_info).
-      uniq.
-      sort { |a, b| a.name <=> b.name }
-  end
-
   def benchmark_batches_latest_for(benchmark_configuration)
     benchmark_batches.
       where(benchmark_configuration: benchmark_configuration)
--- a/web/app/views/index/_compare_table.html.erb	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/app/views/index/_compare_table.html.erb	Thu Nov 19 09:40:33 2015 +0000
@@ -7,21 +7,21 @@
         <% benchmark_infos.each_with_index do |benchmark_info, index| %>
 
           <% latest_result = benchmark_info.latest_result_for_configuration(bc) %>
-        <div class="chart-bar-value"
-          data-index="<%= index %>"
-          data-value="<%= latest_result.try(:min_duration) %>">
-        </div>
-        <div class="chart-bar-labels"
-          data-name="<%= benchmark_info.name %>"
-          data-index="<%= index %>"
-          data-parameters="<%= latest_result.try(:benchmark_parameters_json) %>">
-        </div>
+          <div class="chart-bar-value"
+            data-index="<%= index %>"
+            data-value="<%= latest_result.try(:min_duration) %>">
+          </div>
+          <div class="chart-bar-labels"
+            data-name="<%= benchmark_info.name %>"
+            data-index="<%= index %>"
+            data-parameters="<%= latest_result.try(:benchmark_parameters_json) %>">
+          </div>
 
-      <% end %>
-    </div>
-  <% end %>
+        <% end %>
+      </div>
+    <% end %>
 
-  <div class="chart-legend"></div>
+    <div class="chart-legend"></div>
 
     <div class="chart-container">
       <div class="chart-y-axis"></div>
--- a/web/app/views/settings/benchmark_configurations/show.html.erb	Tue Nov 03 07:42:37 2015 +0000
+++ b/web/app/views/settings/benchmark_configurations/show.html.erb	Thu Nov 19 09:40:33 2015 +0000
@@ -2,7 +2,7 @@
 
 <h1><%= @benchmark_configuration.name %> configuration</h1>
 
-<%= render 'form', 
-  benchmark_configuration: @benchmark_configuration, 
+<%= render 'form',
+  benchmark_configuration: @benchmark_configuration,
   heading: "Edit configuration #{@benchmark_configuration.name}" %>