<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.swarm.org/w/index.php?action=history&amp;feed=atom&amp;title=Swarm_FAQ</id>
		<title>Swarm FAQ - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.swarm.org/w/index.php?action=history&amp;feed=atom&amp;title=Swarm_FAQ"/>
		<link rel="alternate" type="text/html" href="http://www.swarm.org/w/index.php?title=Swarm_FAQ&amp;action=history"/>
		<updated>2026-04-28T10:21:09Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.0</generator>

	<entry>
		<id>http://www.swarm.org/w/index.php?title=Swarm_FAQ&amp;diff=10&amp;oldid=prev</id>
		<title>Pauljohn32: Created page with &quot;===How do I use the gcc profiler?=== A &amp;quot;profiler&amp;quot; is a system to tell you how much execution time your processor spends in each part of your code (and in which parts...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.swarm.org/w/index.php?title=Swarm_FAQ&amp;diff=10&amp;oldid=prev"/>
				<updated>2015-03-07T05:23:14Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;===How do I use the gcc profiler?=== A &amp;quot;profiler&amp;quot; is a system to tell you how much execution time your processor spends in each part of your code (and in which parts...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;===How do I use the gcc profiler?===&lt;br /&gt;
A &amp;amp;quot;profiler&amp;amp;quot; is a system to tell you how much execution time your processor spends in each part of your code (and in which parts of the Swarm libraries and the run-time system). The gcc compiler used for Objective-C Swarm models includes a profiling option that is easy and often very helpful to use when you are trying to make a model run faster, or trying to figure out exactly what it is doing.&lt;br /&gt;
&lt;br /&gt;
Using the gcc profiler requires (a) compiling the code with a special option, (b) running the model, and (c) using a special program that reports profiling results.&lt;br /&gt;
&lt;br /&gt;
*You need to compile and link all parts of model using the gcc compiler option &amp;amp;quot;-pg&amp;amp;quot;. (Do not also use the &amp;amp;quot;-g&amp;amp;quot; option; the profiler output will not be produced.) You can do this by inserting a couple lines into your makefile--the last two lines in the following example:&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 APPLICATION=template&lt;br /&gt;
 OBJECTS=main.o Counter.o TemplateModelSwarm.o TemplateObserverSwarm.o EcoAverager.o Critter.o&lt;br /&gt;
 APPLIBS= include $(SWARMHOME)/etc/swarm/Makefile.appl&lt;br /&gt;
 CFLAGS+=-pg&lt;br /&gt;
 EXTRACPPFLAGS+=-pg&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
*Then use &amp;amp;quot;make clean&amp;amp;quot; and &amp;amp;quot;make&amp;amp;quot; to completely recompile your code. This makes what is called an ''instrumented'' executable, which includes the extra code to report profiling information. &lt;br /&gt;
&lt;br /&gt;
*Next, run the instrumented executable just as you would normally run your model. The profiler writes a file &amp;amp;quot;gmon.out&amp;amp;quot; into your directory.&lt;br /&gt;
&lt;br /&gt;
*Finally, use the built-in program &amp;amp;quot;gprof&amp;amp;quot; to interpret gmon.out and produce the profiling report. Just use the command:&lt;br /&gt;
&lt;br /&gt;
 gprof mycode.exe&lt;br /&gt;
&lt;br /&gt;
where &amp;amp;quot;mycode.exe&amp;amp;quot; is the name of your executable. gprof writes a table of profiling results; it's best to pipe its output to a file:&lt;br /&gt;
&lt;br /&gt;
 gprof mycode.exe &amp;amp;gt; profileoutput.txt&lt;br /&gt;
&lt;br /&gt;
The following example output is from a Swarm implementation of the famous &amp;amp;quot;Boids&amp;amp;quot; model:&lt;br /&gt;
&lt;br /&gt;
 Flat profile:&lt;br /&gt;
 &lt;br /&gt;
 Each sample counts as 0.01 seconds.&lt;br /&gt;
  %   cumulative   self              self     total           &lt;br /&gt;
 time   seconds   seconds    calls  us/call  us/call  name    &lt;br /&gt;
 24.03      0.62     0.62 21624597     0.03     0.03  _i_Vector__getLength&lt;br /&gt;
 23.84      1.24     0.61                             _fu40__Member&lt;br /&gt;
  9.30      1.48     0.24 13726341     0.02     0.02  _i_Vector__sub_&lt;br /&gt;
  6.20      1.64     0.16  3867902     0.04     0.12  _i_Vector__angle_&lt;br /&gt;
  5.43      1.77     0.14 35699811     0.00     0.00  _i_Vector__getY&lt;br /&gt;
  5.43      1.92     0.14 13782653     0.01     0.02  _i_Vector__init_&lt;br /&gt;
  4.84      2.04     0.12                             _fu37___obj_scratchZone&lt;br /&gt;
  4.65      2.16     0.12 35744897     0.00     0.00  _i_Vector__getX&lt;br /&gt;
  4.26      2.27     0.11                             objc_msg_lookup&lt;br /&gt;
  3.10      2.35     0.08 15654110     0.01     0.01  _i_SimObject__getPosition&lt;br /&gt;
  2.71      2.42     0.07  4139991     0.02     0.02  _i_Vector__add_&lt;br /&gt;
  2.71      2.49     0.07  3867902     0.02     0.03  _i_Vector__dot_&lt;br /&gt;
  1.16      2.52     0.03  1972908     0.02     0.02  _i_SimObject__getObjectType&lt;br /&gt;
&lt;br /&gt;
You can see that the method using up the most time is &amp;amp;quot;getLength&amp;amp;quot; in the model's class &amp;amp;quot;Vector&amp;amp;quot;. This is not surprising because this method uses the function &amp;amp;quot;sqrt&amp;amp;quot; which is computationally demanding (because it uses a Taylor Series expansion to estimate the square root). If you wanted to speed the model up, you could replace &amp;amp;quot;sqrt&amp;amp;quot; with your own code to provide a rougher, faster estimate of the square root.&lt;br /&gt;
&lt;br /&gt;
(Almost as much time is used up in class &amp;amp;quot;fu40&amp;amp;quot; which must be a run-time system function that you can't do anything about.)&lt;br /&gt;
&lt;br /&gt;
--[[User:SFRailsback|SFRailsback]] 20:34, 23 Feb 2007 (EST); Thanks to Steve Jackson.&amp;lt;/field&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pauljohn32</name></author>	</entry>

	</feed>