There is no denying the fact that the world runs on ideas. A small idea executed successfully can make someone a billionaire as can be seen with people who have made money out of just one idea. The proliferation of technologies have ensured that one has tools at their disposal in order to give shape to their ideas. If you have an idea, all you need is some capital investment. You don’t even need huge cash. You can easily outsource your ideas and get it built at the fraction of costs.
Applications are really valuable in today’s business world, especially those that can be built much sooner than the conventional time and with the demand to bring the application into the market as soon as possible, many organization forgo checking the performance of the application. A badly executed application can negatively affect your website and hamper your brand name, not to mention, security issues, huge revenue loss and losing customer trust. After all, if an application does not run well, what kind of benefits can it provide?
Ruby-Prof is a performance tuning tool for Ruby based applications. As a C extension, it is much faster than standard Ruby-profiler and support both flat and graph profiles. Ruby-prof shows, graph profiles for each method, showing how long the method ran, which methods called it and which methods it called.
Ruby-prof provides both text and html and can output it to standard out or to a file. This Ruby gem can measure various different parameters, including call times, object allocations and memory usage. As this gem can support profiling of multiple threads simultaneously, it is one of the best bets for any ruby based application.
However, ruby-prof can be run only on Ruby version 1.9.3 or higher and if you use Linux or UNIX, you may need a C Compiler for the extension to compile upon installation. On Windows, you would need to install Windows specific Ruby Gem, incorporating an already built extension.
How To Install Ruby-Prof Gem
git clone git://github.com/jeremy/ruby-prof.git cd ruby-prof/ rake gem sudo gem install pkg/ruby-prof-0.6.1.gemSetting Up A New Environment For Profiling
Create config/environments/profiling.rb: config.cache_classes = true config.action_controller.consider_all_requests_local = false config.action_controller.perform_caching = true config.action_view.cache_template_loading = true #config.log_level = :debugAdd the new environment to database.yml. You might want to reuse the development database. Creating A Profiling Script : Next we’ll create a script that simply fetches the homepage, save the following code in profiling/homepage.rb:
get ‘/’ say “GET / => #{path}”Run the script Now run the script 100 times:
RAILS_ENV=profiling ./script/performance/request -n 100 profiling/homepage.rbProfiling Plain Ruby Applications You can also profile a block of code by calling RubyProf from your code:
require ‘ruby-prof’ # Profile the code RubyProf.start … [code to profile] … results = RubyProf.stop File.open “#{RAILS_ROOT}/tmp/profile-graph.html”, ‘w’ do |file| RubyProf::GraphHtmlPrinter.new(results).print(file) end File.open “#{RAILS_ROOT}/tmp/profile-flat.txt”, ‘w’ do |file| RubyProf::FlatPrinter.new(results).print(file) end File.open “#{RAILS_ROOT}/tmp/profile-tree.prof”, ‘w’ do |file| RubyProf::CallTreePrinter.new(results).print(file) endAnalyzing Results : RubyProf::CallTreePrinter to output data that kcachegrind can read. The HTML and text data is difficult to read so kcachegrind will definitely make your life easier. On OSX you can install kcachegrind with Fink (or DarwinPorts):
sudo apt-get update ; sudo apt-get install fink sudo apt-get install kcachegrindCode source: (https://github.com/ruby-prof/ruby-prof) Always ensure that you get your application tested with this ruby-gem profiler and get it measured against your app as it will not only optimize your codes but will be much cost effective, not to mention, the efficiency of your application will enhance greatly. Want to know more on how this and other gems function? With ingenious solutions, progressive business values, and proven track record, RailsCarma is best suited to help you with all your development needs. Our development process is established heavily on unrelenting attention to details, including quality, design and excellence. We convert your ideas into reality. Connect to us through our Contact Us page. Read Similar Articles :
Subscribe For Latest Updates
Related Posts