From 3344f373bd19b47ea0650c98b180b96aec27f9a7 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 1 May 2014 21:26:05 +0200 Subject: [PATCH] Plot time offsets on X axes when profiling. --- profile/gnuplot/memory_time.gpi | 13 ++++--------- profile/profile_helper.rb | 8 ++++---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/profile/gnuplot/memory_time.gpi b/profile/gnuplot/memory_time.gpi index 8ef268a..2ab70d3 100644 --- a/profile/gnuplot/memory_time.gpi +++ b/profile/gnuplot/memory_time.gpi @@ -2,20 +2,15 @@ set title sample_file -set xlabel "Time" +set xlabel "Runtime (seconds)" set ylabel "Memory (MB)" -set xdata time -set timefmt "%Y-%m-%dT%H:%M:%S" - -set yrange [0:*] +set xtics 1 set term wx persist size 900,600 set grid set style line 1 lc rgb "#0060ad" lt 1 lw 2 pt 7 ps 1 +set style data linespoints -plot sample_file \ - using 1:($2 / 1024 ** 2) \ - with linespoints ls 1 \ - title "Memory" +plot sample_file using 1:($2 / 1024 ** 2) ls 1 title "Memory" diff --git a/profile/profile_helper.rb b/profile/profile_helper.rb index 763069a..aff166d 100644 --- a/profile/profile_helper.rb +++ b/profile/profile_helper.rb @@ -1,5 +1,4 @@ require 'timeout' -require 'time' require_relative '../lib/oga' @@ -41,15 +40,16 @@ def profile_memory(name, duration = 30) path = File.expand_path("../samples/#{name}.txt", __FILE__) handle = File.open(path, 'w') handle.sync = true + start_time = Time.now while monitor usage = memory_usage usage_mb = (usage / 1024 / 1024).round(2) - time = Time.now.strftime('%Y-%m-%dT%H:%M:%S') + runtime = Time.now - start_time - handle.write("#{time} #{usage}\n") + handle.write("#{runtime} #{usage}\n") - puts "#{time}: #{usage_mb} MB" + puts "#{usage_mb} MB" sleep(rand) end