<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pivotal Labs &#187; Sam Coward</title>
	<atom:link href="http://pivotallabs.com/author/scoward/feed/" rel="self" type="application/rss+xml" />
	<link>http://pivotallabs.com</link>
	<description>Agility Developed</description>
	<lastBuildDate>Tue, 21 May 2013 16:50:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Cedar target templates for Xcode 4.3.x</title>
		<link>http://pivotallabs.com/cedar-target-templates-for-xcode-4-3-x/</link>
		<comments>http://pivotallabs.com/cedar-target-templates-for-xcode-4-3-x/#comments</comments>
		<pubDate>Fri, 13 Jul 2012 02:50:00 +0000</pubDate>
		<dc:creator>Sam Coward</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[cedar]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/cedar-target-templates-for-xcode-4-3-x/</guid>
		<description><![CDATA[<p><p>Announcing Cedar target templates for Xcode 4.3.x:  Getting started with Cedar has never been easier!</p>

<p>These templates let you quickly add Cedar targets to your iOS or Mac OS X project.  It's super simple to build and install from source now:</p>

<pre><code>git clone http://github.com/pivotal/cedar --recursive &#38;&#38; cd cedar ; rake install
</code></pre>

<p>If you don't like building from source, you can also install a build of the Cedar templates from the <a href="https://github.com/pivotal/cedar/downloads">downloads page</a> - just untar to your home directory.</p>

<h2>Using Cedar Templates</h2>

<p>Restart Xcode after installing, open your project and add a new target.  You'll find targets for both iOS and Mac OS X.  There are 2 types of targets: Suites and Bundles.  A Suite target will build your tests as a separate application which you then run to execute your tests.  Bundle targets work just like OCUnit testing bundles, providing closer integration with Xcode.  If you do create a bundle target, make sure to edit the scheme of your application and add the new target to the list of tests.</p>

<p>Every template comes with a simple example which should run out of the box to help you get running.</p>

<h2>ARC: A word of caution</h2>

<p>Automatic Reference Counting setting:  Don't use it for your spec targets.  Your application is free to use ARC, just don't use it for any Cedar targets.  This is because there is a flaw in the compiler that ships with Xcode &#40;see <a href="https://gist.github.com/3102360">here</a> for the details, and if you care please feel free to use this information to <a href="http://bugreport.apple.com/">file a bug with apple</a>&#41;.</p>

<h2>Have fun speccing</h2>

<p>We really hope these changes help you to get started writing specs and spending less time setting up Cedar.  If you have any feedback, whether it's about these templates or something else about Cedar, please feel welcome stop by the <a href="http://groups.google.com/group/cedar-discuss">discussion group</a> and share your thoughts.</p> <a href="http://pivotallabs.com/cedar-target-templates-for-xcode-4-3-x/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/cedar-target-templates-for-xcode-4-3-x/">Cedar target templates for Xcode 4.3.x</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Announcing Cedar target templates for Xcode 4.3.x:  Getting started with Cedar has never been easier!</p>
<p>These templates let you quickly add Cedar targets to your iOS or Mac OS X project.  It&#8217;s super simple to build and install from source now:</p>
<pre><code>git clone http://github.com/pivotal/cedar --recursive &amp;&amp; cd cedar ; rake install
</code></pre>
<p>If you don&#8217;t like building from source, you can also install a build of the Cedar templates from the <a href="https://github.com/pivotal/cedar/downloads">downloads page</a> &#8211; just untar to your home directory.</p>
<h2>Using Cedar Templates</h2>
<p>Restart Xcode after installing, open your project and add a new target.  You&#8217;ll find targets for both iOS and Mac OS X.  There are 2 types of targets: Suites and Bundles.  A Suite target will build your tests as a separate application which you then run to execute your tests.  Bundle targets work just like OCUnit testing bundles, providing closer integration with Xcode.  If you do create a bundle target, make sure to edit the scheme of your application and add the new target to the list of tests.</p>
<p>Every template comes with a simple example which should run out of the box to help you get running.</p>
<h2>ARC: A word of caution</h2>
<p>Automatic Reference Counting setting:  Don&#8217;t use it for your spec targets.  Your application is free to use ARC, just don&#8217;t use it for any Cedar targets.  This is because there is a flaw in the compiler that ships with Xcode &#40;see <a href="https://gist.github.com/3102360">here</a> for the details, and if you care please feel free to use this information to <a href="http://bugreport.apple.com/">file a bug with apple</a>&#41;.</p>
<h2>Have fun speccing</h2>
<p>We really hope these changes help you to get started writing specs and spending less time setting up Cedar.  If you have any feedback, whether it&#8217;s about these templates or something else about Cedar, please feel welcome stop by the <a href="http://groups.google.com/group/cedar-discuss">discussion group</a> and share your thoughts.</p>
<p>The post <a href="http://pivotallabs.com/cedar-target-templates-for-xcode-4-3-x/">Cedar target templates for Xcode 4.3.x</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/cedar-target-templates-for-xcode-4-3-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Identify memory abusing partials with GC stats</title>
		<link>http://pivotallabs.com/identify-memory-abusing-partials-with-gc-stats/</link>
		<comments>http://pivotallabs.com/identify-memory-abusing-partials-with-gc-stats/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 02:01:00 +0000</pubDate>
		<dc:creator>Sam Coward</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/identify-memory-abusing-partials-with-gc-stats/</guid>
		<description><![CDATA[<p><p>Recently we had to investigate a page that had very poor performance.  The project used <em>newrelic</em>, but neither that, the application’s logs nor render traces gave clear results.  The database wasn’t the bottleneck, but there were well over 100 partials in the render trace.  These partials seemed to perform well, except sometimes the same partial would take hundreds to thousands of milliseconds.</p>

<p>As it turns out, the cause of these random delays was actually garbage collection triggered by abusive memory consumption within many of the partials - millions of objects and heap growth in excess of 100mb.  We discovered this by using the memory and GC statistics features of <em>Ruby Enterprise Edition</em>.  You can get an idea of how much memory is being used and garbage collected during rendering by wrapping parts of your page in a block passed to this helper:</p>

<pre><code>def gc_profile
  raise "Dude, you left GC profiling on!" unless Rails.env.development?
  allocated_objects_before = ObjectSpace.allocated_objects
  GC.enable_stats
  GC.clear_stats

  yield if block_given?

  growth = GC.growth
  collections = GC.collections
  time = GC.time
  mallocs = GC.num_allocations
  allocated_objects = ObjectSpace.allocated_objects - allocated_objects_before
  GC.disable_stats

  concat content_tag :span, "GC growth: #{growth}b, collections: #{collections}, time #{time / 1000000.0}sec, #{mallocs} mallocs, #{allocated_objects} objects created."
end
</code></pre>

<p>Because there were so many partials on the page, moving the helper around to identify the most egregious memory abusers got tiring so I wrote a monkeypatch to the <a href="http://github.com/brynary/rack-bug" title="brynary's rack-bug at master - GitHub">venerable Rack::Bug plug-in</a> which shows you memory consumption and garbage collection statistics for each template shown in the Rack::Bug template trace, as well as on the memory panel.</p>

<p><img title="Example template trace" src="http://assets.pivotallabs.com/798/original/template_trace_example.png" alt="Example template trace" /></p>

<p><img title="Memory panel example" src="http://assets.pivotallabs.com/796/original/memory_panel_example.png" alt="Memory panel example" /></p>

<p>First, install Rack::Bug and make sure it's working properly, then add the code below in an initializer.  Keep in mind this was written to work with Ruby Enterprise Edition 1.8.7 2010.02.  Various 1.8 patches and Ruby 1.9 also provide some GC statistics reporting tools which you could probably customize this patch to use instead.</p>

<pre><code>if Rails.env.development?
  require 'rack/bug'

  Rack::Bug::TemplatesPanel::Trace.class_eval do
    alias_method :old_start, :start
    def start&#40;template_name&#41;
      old_start&#40;template_name&#41;
      @initial_allocated_objects = ObjectSpace.allocated_objects
      @initial_allocated_size = GC.allocated_size
      @initial_num_allocations = GC.num_allocations
      @initial_gc_count = GC.collections
      @initial_gc_time = GC.time
    end

    alias_method :old_finished, :finished
    def finished&#40;template_name&#41;
      @current.allocated_objects = ObjectSpace.allocated_objects - @initial_allocated_objects
      @current.allocated_size = GC.allocated_size - @initial_allocated_size
      @current.num_allocations = GC.num_allocations - @initial_num_allocations
      @current.gc_count = GC.collections - @initial_gc_count
      @current.gc_time = &#40;GC.time - @initial_gc_time&#41;/1000.0
      old_finished&#40;template_name&#41;
    end
  end

  Rack::Bug::TemplatesPanel::Rendering.class_eval do
    attr_accessor :allocated_objects
    attr_accessor :allocated_size
    attr_accessor :num_allocations
    attr_accessor :gc_count
    attr_accessor :gc_time

    def memory_summary
      %{&#60;strong&#62;%.2fms&#60;/strong&#62;&#60;small&#62;in&#60;/small&#62;&#60;strong&#62;%d&#60;/strong&#62;&#60;small&#62;GCs&#60;/small&#62;
      &#60;strong&#62;%d&#60;/strong&#62;&#60;small&#62;new objects&#60;/small&#62;
      &#60;strong&#62;%d&#60;/strong&#62;&#60;small&#62;bytes in&#60;/small&#62;&#60;strong&#62;%d&#60;/strong&#62;&#60;small&#62;mallocs&#60;/small&#62;} % [gc_time, gc_count, allocated_objects, allocated_size, num_allocations]
    end

    def html
      %{&#60;li&#62;
          &#60;p&#62;#{name} &#40;#{time_summary}&#41; [#{memory_summary}]&#60;/p&#62;
          #{children_html}
        &#60;/li&#62;}
    end
  end

  Rack::Bug::MemoryPanel.class_eval do
    alias_method :old_before, :before
    def before&#40;env&#41;
      old_before&#40;env&#41;
      GC.enable_stats
      GC.clear_stats
      @initial_allocated_objects = ObjectSpace.allocated_objects
      @initial_allocated_size = GC.allocated_size
      @initial_num_allocations = GC.num_allocations
    end

    alias_method :old_after, :after
    def after&#40;env, status, headers, body&#41;
      old_after&#40;env, status, headers, body&#41;
      @gc_count = GC.collections
      @gc_time = GC.time / 1000.0
      @allocated_objects = ObjectSpace.allocated_objects - @initial_allocated_objects
      @allocated_size = GC.allocated_size - @initial_allocated_size
      @num_allocations = GC.num_allocations - @initial_num_allocations
    end

    def heading
      "#{@memory_increase} KB &#38;#916;, #{@total_memory} KB total, %.2fms in #{@gc_count} GCs" % @gc_time
    end

    def has_content?
      true
    end

    def name
      "memory_panel"
    end

    def content
      %{&#60;style&#62;#memory_panel dd { font-size: large; }&#60;/style&#62;
        &#60;h3&#62;Garbage Collection Stats&#60;/h3&#62;
        &#60;dl&#62;
          &#60;dt&#62;Garbage collection runs&#60;/dt&#62;
          &#60;dd&#62;%d&#60;/dd&#62;
          &#60;dt&#62;Time spent in GC&#60;/dt&#62;
          &#60;dd&#62;%.2fms&#60;/dd&#62;
          &#60;dt&#62;Objects created&#60;/dt&#62;
          &#60;dd&#62;%d&#60;/dd&#62;
          &#60;dt&#62;Bytes allocated&#60;/dt&#62;
          &#60;dd&#62;%d&#60;/dd&#62;
          &#60;dt&#62;Allocation calls&#60;/dt&#62;
          &#60;dd&#62;%d&#60;/dd&#62;
      &#60;/dl&#62;} % [@gc_count, @gc_time, @allocated_objects, @allocated_size, @num_allocations]
    end
  end
end
</code></pre> <a href="http://pivotallabs.com/identify-memory-abusing-partials-with-gc-stats/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/identify-memory-abusing-partials-with-gc-stats/">Identify memory abusing partials with GC stats</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Recently we had to investigate a page that had very poor performance.  The project used <em>newrelic</em>, but neither that, the application’s logs nor render traces gave clear results.  The database wasn’t the bottleneck, but there were well over 100 partials in the render trace.  These partials seemed to perform well, except sometimes the same partial would take hundreds to thousands of milliseconds.</p>
<p>As it turns out, the cause of these random delays was actually garbage collection triggered by abusive memory consumption within many of the partials &#8211; millions of objects and heap growth in excess of 100mb.  We discovered this by using the memory and GC statistics features of <em>Ruby Enterprise Edition</em>.  You can get an idea of how much memory is being used and garbage collected during rendering by wrapping parts of your page in a block passed to this helper:</p>
<pre><code>def gc_profile
  raise "Dude, you left GC profiling on!" unless Rails.env.development?
  allocated_objects_before = ObjectSpace.allocated_objects
  GC.enable_stats
  GC.clear_stats

  yield if block_given?

  growth = GC.growth
  collections = GC.collections
  time = GC.time
  mallocs = GC.num_allocations
  allocated_objects = ObjectSpace.allocated_objects - allocated_objects_before
  GC.disable_stats

  concat content_tag :span, "GC growth: #{growth}b, collections: #{collections}, time #{time / 1000000.0}sec, #{mallocs} mallocs, #{allocated_objects} objects created."
end
</code></pre>
<p>Because there were so many partials on the page, moving the helper around to identify the most egregious memory abusers got tiring so I wrote a monkeypatch to the <a href="http://github.com/brynary/rack-bug" title="brynary's rack-bug at master - GitHub">venerable Rack::Bug plug-in</a> which shows you memory consumption and garbage collection statistics for each template shown in the Rack::Bug template trace, as well as on the memory panel.</p>
<p><img title="Example template trace" src="http://assets.pivotallabs.com/798/original/template_trace_example.png" alt="Example template trace" /></p>
<p><img title="Memory panel example" src="http://assets.pivotallabs.com/796/original/memory_panel_example.png" alt="Memory panel example" /></p>
<p>First, install Rack::Bug and make sure it&#8217;s working properly, then add the code below in an initializer.  Keep in mind this was written to work with Ruby Enterprise Edition 1.8.7 2010.02.  Various 1.8 patches and Ruby 1.9 also provide some GC statistics reporting tools which you could probably customize this patch to use instead.</p>
<pre><code>if Rails.env.development?
  require 'rack/bug'

  Rack::Bug::TemplatesPanel::Trace.class_eval do
    alias_method :old_start, :start
    def start&#40;template_name&#41;
      old_start&#40;template_name&#41;
      @initial_allocated_objects = ObjectSpace.allocated_objects
      @initial_allocated_size = GC.allocated_size
      @initial_num_allocations = GC.num_allocations
      @initial_gc_count = GC.collections
      @initial_gc_time = GC.time
    end

    alias_method :old_finished, :finished
    def finished&#40;template_name&#41;
      @current.allocated_objects = ObjectSpace.allocated_objects - @initial_allocated_objects
      @current.allocated_size = GC.allocated_size - @initial_allocated_size
      @current.num_allocations = GC.num_allocations - @initial_num_allocations
      @current.gc_count = GC.collections - @initial_gc_count
      @current.gc_time = &#40;GC.time - @initial_gc_time&#41;/1000.0
      old_finished&#40;template_name&#41;
    end
  end

  Rack::Bug::TemplatesPanel::Rendering.class_eval do
    attr_accessor :allocated_objects
    attr_accessor :allocated_size
    attr_accessor :num_allocations
    attr_accessor :gc_count
    attr_accessor :gc_time

    def memory_summary
      %{&lt;strong&gt;%.2fms&lt;/strong&gt;&lt;small&gt;in&lt;/small&gt;&lt;strong&gt;%d&lt;/strong&gt;&lt;small&gt;GCs&lt;/small&gt;
      &lt;strong&gt;%d&lt;/strong&gt;&lt;small&gt;new objects&lt;/small&gt;
      &lt;strong&gt;%d&lt;/strong&gt;&lt;small&gt;bytes in&lt;/small&gt;&lt;strong&gt;%d&lt;/strong&gt;&lt;small&gt;mallocs&lt;/small&gt;} % [gc_time, gc_count, allocated_objects, allocated_size, num_allocations]
    end

    def html
      %{&lt;li&gt;
          &lt;p&gt;#{name} &#40;#{time_summary}&#41; [#{memory_summary}]&lt;/p&gt;
          #{children_html}
        &lt;/li&gt;}
    end
  end

  Rack::Bug::MemoryPanel.class_eval do
    alias_method :old_before, :before
    def before&#40;env&#41;
      old_before&#40;env&#41;
      GC.enable_stats
      GC.clear_stats
      @initial_allocated_objects = ObjectSpace.allocated_objects
      @initial_allocated_size = GC.allocated_size
      @initial_num_allocations = GC.num_allocations
    end

    alias_method :old_after, :after
    def after&#40;env, status, headers, body&#41;
      old_after&#40;env, status, headers, body&#41;
      @gc_count = GC.collections
      @gc_time = GC.time / 1000.0
      @allocated_objects = ObjectSpace.allocated_objects - @initial_allocated_objects
      @allocated_size = GC.allocated_size - @initial_allocated_size
      @num_allocations = GC.num_allocations - @initial_num_allocations
    end

    def heading
      "#{@memory_increase} KB &amp;#916;, #{@total_memory} KB total, %.2fms in #{@gc_count} GCs" % @gc_time
    end

    def has_content?
      true
    end

    def name
      "memory_panel"
    end

    def content
      %{&lt;style&gt;#memory_panel dd { font-size: large; }&lt;/style&gt;
        &lt;h3&gt;Garbage Collection Stats&lt;/h3&gt;
        &lt;dl&gt;
          &lt;dt&gt;Garbage collection runs&lt;/dt&gt;
          &lt;dd&gt;%d&lt;/dd&gt;
          &lt;dt&gt;Time spent in GC&lt;/dt&gt;
          &lt;dd&gt;%.2fms&lt;/dd&gt;
          &lt;dt&gt;Objects created&lt;/dt&gt;
          &lt;dd&gt;%d&lt;/dd&gt;
          &lt;dt&gt;Bytes allocated&lt;/dt&gt;
          &lt;dd&gt;%d&lt;/dd&gt;
          &lt;dt&gt;Allocation calls&lt;/dt&gt;
          &lt;dd&gt;%d&lt;/dd&gt;
      &lt;/dl&gt;} % [@gc_count, @gc_time, @allocated_objects, @allocated_size, @num_allocations]
    end
  end
end
</code></pre>
<p>The post <a href="http://pivotallabs.com/identify-memory-abusing-partials-with-gc-stats/">Identify memory abusing partials with GC stats</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/identify-memory-abusing-partials-with-gc-stats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using apc
Database Caching using apc
Object Caching 486/519 objects using apc

 Served from: pivotallabs.com @ 2013-05-21 13:48:21 by W3 Total Cache -->