The subject sounds almost too grandiose. I''m currently trying to find out where my cycles are burned. Rails already comes with some support for this and Stefan Kaes''s rails-bench adds to that. I wanted something different, that helps me drill down on where exactly the time is spent. This is how it works: Stopwatch.measure(''complicated_calculation'') do complicated_calculation(x) end At http://127.0.0.1/stopwatch/ (or equivalent for your app) you can have a look at current stopwatch readings, take a snapshot, and export to CSV and YAML. If you''re interested, please have a look at http://www.schuerig.de/michael/ruby/#stopwatch There even is a picture. Michael -- Michael Schuerig There is no matrix, mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org only reality. http://www.schuerig.de/michael/ --Lawrence Fishburn
Great! I just added this to my project and it seems to work nicely. However. What do I need to do with the code in order for it to run as a module, as for example via the url http://127.0.0.1/admin/stopwatch. I am still quite new to ruby & rails and I can''t figure out what I need to change. I''ve tried changing the classname in the controller to Admin::Stopwatch, and also to prefix all the references to the StopwatchController with Admin::. Also I went around changing the paths referenced in the controller to /admin/stopwatch_controller/ instead of /stopwatch_controller/. But I am just not able to make it work :( ------------------------------------------------------------------------ /*Ronny Hanssen*/ Michael Schuerig wrote:> The subject sounds almost too grandiose. I''m currently trying to find > out where my cycles are burned. Rails already comes with some support > for this and Stefan Kaes''s rails-bench adds to that. I wanted something > different, that helps me drill down on where exactly the time is spent. > > This is how it works: > > Stopwatch.measure(''complicated_calculation'') do > complicated_calculation(x) > end > > At > > http://127.0.0.1/stopwatch/ > > (or equivalent for your app) you can have a look at current stopwatch > readings, take a snapshot, and export to CSV and YAML. > > If you''re interested, please have a look at > > http://www.schuerig.de/michael/ruby/#stopwatch > > There even is a picture. > > Michael >
On Saturday 27 August 2005 01:28, Ronny Hanssen wrote:> Great! I just added this to my project and it seems to work nicely. > However. What do I need to do with the code in order for it to run as > a module, as for example via the url > http://127.0.0.1/admin/stopwatch. I am still quite new to ruby & > rails and I can''t figure out what I need to change.I''m sorry, the problem was with my code. When I wrote the controller originally, I''ve been cutting a few corners and hard coded the links. I''ve corrected this and uploaded a new version[*]. You''ll have to put the stopwatch_controller.rb into app/controllers/admin *and* change put the class into the appropriate module, i.e. change class StopwatchController < ... to class Admin::StopwatchController < ... Michael [*] http://www.schuerig.de/michael/ruby/#stopwatch -- Michael Schuerig All good people read good books mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org Now your conscience is clear http://www.schuerig.de/michael/ --Tanita Tikaram, Twist In My Sobriety
Great! Works now - with some minor tweaks. You might like to take another look at the controller code. You had left a couple of Admin:: references. Which were of course perfect for me, but maybe not for others :) I also like to find out what the best approach would be for including the stopwatch code? Right now I am including it in the application.rb controller. Although I am considering moving the require to the environment.rb file. Whaddayathink? And finally: Your controller has a require for stopwatch that references the boilerplate library path. Since I am already requiring stopwatch in my application controller I just commented it out. Works for me. And, thanks a million for sharing! ------------------------------------------------------------------------ /*Ronny Hanssen*/ Michael Schuerig wrote:> On Saturday 27 August 2005 01:28, Ronny Hanssen wrote: > >>Great! I just added this to my project and it seems to work nicely. >>However. What do I need to do with the code in order for it to run as >>a module, as for example via the url >>http://127.0.0.1/admin/stopwatch. I am still quite new to ruby & >>rails and I can''t figure out what I need to change. > > > I''m sorry, the problem was with my code. When I wrote the controller > originally, I''ve been cutting a few corners and hard coded the links. > I''ve corrected this and uploaded a new version[*]. > > You''ll have to put the stopwatch_controller.rb into > app/controllers/admin *and* change put the class into the appropriate > module, i.e. change > > class StopwatchController < ... > > to > > class Admin::StopwatchController < ... > > Michael > > [*] http://www.schuerig.de/michael/ruby/#stopwatch >
On Monday 29 August 2005 17:04, Ronny Hanssen wrote:> You might like to take another look at the controller code. You had > left a couple of Admin:: references. Which were of course perfect for > me, but maybe not for others :)Yes, that was deliberate.> I also like to find out what the best approach would be for including > the stopwatch code? Right now I am including it in the application.rb > controller. Although I am considering moving the require to the > environment.rb file. Whaddayathink?As with other libraries, I require it where I use it. I usually don''t keep stopwatches permanently in my code, but rather I add them only to check some dusty corners. When I remove the timing code, I remove the require, too, and don''t have to think of other places I might have to touch.> And finally: Your controller has a require for stopwatch that > references the boilerplate library path. Since I am already requiring > stopwatch in my application controller I just commented it out. Works > for me.Yes, that''s just where I keep it. Change it to suit your needs. I haven''t put it into a Module as I don''t want to impose that on others. If (big if) I find the time, I might make the Stopwatch into a gem, but it''s almost too trivial for that. Michael -- Michael Schuerig Life is just as deadly mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org As it looks http://www.schuerig.de/michael/ --Richard Thompson, Sibella