From: Gavin Kistner Date: 2005-05-18T13:53:12+09:00 Subject: Re: ruby in WinXP as an automation tool --Apple-Mail-1-645804600 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On May 17, 2005, at 3:28 PM, Bill Guindon wrote: > Anybody have any samples of ruby/au3 scripts that are a bit more in > depth than the wiki example? I'm not using AutoIt, but in case it helps, here's a script I wrote today (inspired by this thread) that repeatedly opens different files with an application, and measures how much RAM the app is using. I've simplified the code a bit from what I'm actually using. For example, I snipped out the bit which is testing a bunch of different builds of the app to check for variations between builds. (Suggestions on cleaner ways to do things are welcome; I really don't understand OLE at all, or the WMI service. Although I did find this list[1] of properties which you can access on the processes returned by the InstancesOf call.) class Fixnum def sample_average sum=0.0 self.times{ sum += yield } sum/self end end class WIN32OLE def to_a a = [] self.each{ |p| a<

'C:/Documents and Settings/gavin.kistner/Desktop/ 25139/AMPlayer.exe' } file_base = 'D:/QA/TestProjects/v30/Performance/ MasterSlideAssetWithManySlides/' files = %w| 1x1_10Assets.am 100x1_10Assets.am 1x100_10Assets.am 100x100_10Assets.am | filepaths = {} files.each{ |filename| filepaths[ filename ] = (file_base + filename) } stats = {} samples_per_launch = 5 seconds_after_launch = 4 seconds_after_terminate = 1 players.each{ |player_name, exe| filepaths.each{ |filename, path| cmd = %Q|#{exe} "#{path}"| # Different launches use slightly different amounts of RAM # so launch it a few times and average the samples stats[ [player_name, filename ] ] = samples_per_launch.sample_average{ # Run the command (open the file with the player) asynchronously IO.popen( cmd ) # Wait to be sure it launched and initialized sleep seconds_after_launch # Find the process for the player mgmt = WIN32OLE.connect('winmgmts:\\\\.') player = mgmt.InstancesOf("win32_process").to_a.find{ | proc| proc.name =~ /AMPlayer.exe/ } # Figure out how much RAM it's using kbytes = player.workingSetSize.to_f / 1024 # Kill it player.Terminate # Make sure it's really dead (not needed?) sleep seconds_after_terminate puts "#{player_name}:#{filename} :: #{kbytes}" # Return the measured RAM, for averaging kbytes } } } [1] http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_process.asp -- "Despite the surge of power you feel upon learning Ruby, resist the urge to trip others or slap them in the bald head. DO NOT LORD YOUR RUBYNESS OVER OTHERS!" - Why the Lucky Stiff --Apple-Mail-1-645804600--