New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Profiling #232
Comments
you can try |
Hello,
|
Having never run it myself, I can't help much. It appears that it should output at program exit. It's quite possible that you or Shoes uses a different exit (since it's not really ruby). Perhaps there is a call you can make before quitting? There are other gems that might work but I suspect not. |
Ruby Benchmark should do in most cases. |
https://github.com/ruby-prof/ruby-prof looks interesting. Somebody could try it. The only time I had performance issues with ruby or shoes involved sqlite3 speed at inserting rows and easily diagnosed from observation. |
out of curiosity : Based on ruby's Process and TracePoint libs and this : https://github.com/emilsoman/diy_prof/tree/dot-reporter |
I think Benchmark is only to get the total time, not giving a breakdown of elapsed time down to method level. |
And the other solutions are not very straightforward to implement unfortunately :-/ |
It is not profiling per se but using a profiler through Shoes sounds like challenging because of the extra layer shoes is adding. At best you might be able to profile at Ruby method level but not at Shoes level. You wouldn't get entries for windows, slots, stacks, etc. Benchmark would work though. Alternatively, you can write your business logic in plain Ruby and profile your code using Ruby instead of Shoes. You will be able to profile Ruby methods and optimize. Then you use Benchmark at Shoes level in areas you feel are bottlenecks. |
Profiling is difficult. gem install is not difficult now days since they often come with win32 binaries libs. Interpreting the results is difficult. That said, @passenger94 just demonstrated his Shoes app in a profiler with what appears to be a Shoes written method of presentation so it clearly can be done. |
just a start, [ you can only trace an app at launching time, balloons dimensions are bounded to the length of the biggest method name,they could be big ...] https://gist.github.com/passenger94/61230af6e154973ea960d5f5cd29ac8c |
I don't want this to get lost in the issues, so I started https://github.com/Shoes3/shoes3/wiki/DIY-Profiling This is another Shoes app that uses Shoes, I like those! This is even Shoe4 compatible should they ever arise from grave and notice it. This is one of those Proof of Concept that really showcases Shoes and Ruby. Congratulations. I hinted at some TODO's in the wiki article. Maybe a less graphical - write strings to an edit_box with Edit: |
Cool ! |
* chdir to script being tested * needs a hook for window close of target * the diy_prof code should be moved from lib/shoes/diy_prof to lib/diy_prof and de-gemmed.
* head's up to @passenger94. It's not correct yet.
* Changed from radios to button - moved code around * needs to handle a command line option (-e <script>) * needs code for textscreen (display all 3 metrics and % time and .... in one report (that can be copied to the clipboard) and look more like profiler. * needs trace.start and trace.end
It works well enough to be part of Shoes 3.2.2. Needs a lot more work , of course. I'm going to work on the -e command line option and moving the diy_prof code to a Shoes friendly place. Also functional Ruby makes my head hurt. Better left for someone with skills. |
* allows profiling more than the startup code. * I consider this workable. It might help some people. * still some bugs to fix and features to write.
* needs lots of huh? testing on OSX and Windows (shoes.exe, cshoes.exe) if it passess those tests, it's good enough although I really want to get a more sophiscated report for terminal: method_name: calls, ms/call, total/call %whole/call .... and convert to mille-sec and fractions of.
Fun. The newer profiler works on OSX (subject to OSX command line funk) and crashes on Win7 when |
* not my forte - very will to accept better code.
* calc script load time * calc wall time * improve formatting * compute percentages * add sort by mtime. If you can't find a bottle neck with these two, there is is no hope. * I'm calling it done even though it's kind of hacky.
The Windows crash is because Windows Ruby doesn't implement many posix things.
Fails in irb. There does appear to be a way to get the answer with some C code. |
ouch ! cross platform plumbing is an art :-D |
I'm thinking of adding new Shoes methods app.wall_time and app.cpu_time. They could be useful for other purposes than our profiler. Thoughts? |
More tools to fiddle with ? sounds reasonable to me :-) |
An quick and easy way to measure the wall time of an sql-query or a download or... |
a way to precisely target the function to be measured ? |
Any thing that is smaller than what Ruby Time supplies. Who knows? Might not be useful to others. |
* still meaningful data for developers. just not as good on windows * works Linux, osx, windows * still clunky timehelper hack. needs thinking.
new shoes methods are not going to happen. I know Windows Ruby only supports REAL_TIME and MONOTONIC clocks and if there was an easy way for PROCESS_CPUTIME_ID it would have been included in in win32.c That's a dos window. Oddly enough, you can set some cross platform colors on it that are compatible. Go figure. |
Heya ! I tried toe Profile but somehow it breaks my code. Here it is what happens. I open shoes -> Profile an App, then select my main.rb. When I start the profile the APP starts running but I am unable to click on elements that have click event. Some files are opened for each clicked event but when launched through the profiler this error appears is "No such file or directory available "text/factions/Academy.txt". The app works when launched normally. Why is that? Does the default app path gets modified while launched through the profiler? |
Windows? Depending on the beta version, it may have problems profiling anything on Windows. Try profiling a very simple program to see if it works. |
Further, I believe profiling does Dir.chdir( to location of script) but that may not work as expected - it works for sample/good-cardflip which loads a file. There is also a bug I just discovered with profiling scripts that use the url/visit method of navigation. |
I am using R2619. I believe what you say is true about Chdir not working as it covers the issue. Actually the profiler works and my code gets executed but due to issues with the chdirs with works halfway. |
Windows and paths and pwd have always been a problem. The r2629 version of shoes 3.3.2 only allows profiling from the command line.
part of the reason for forcing command line only, is the confusion about where the script (and dependencies are located. Putting profile in the splash was a regrettable error. |
hm... tried this but the result was the same :/ e:\shoes3> cshoes.exe -e \path\to\script.rb |
I did discover some code in samples/good-cardflip.rb that explains why it works -e on Windows/Mac/Linux. It looks in several places for the resource: # finding script resources is odd when developing a samples/myprogram.rb
# particularly on osx when invoked with ./cshoes mydir/myprogram.rb
# DIR is not sufficient.
# its best to return a full path.
def find_paris
cdir = Dir.getwd
if File.exist? "paris.svg"
"#{cdir}/paris.svg"
elsif File.exist? "#{DIR}/paris.svg"
"#{DIR}/paris.svg"
else
ask_open_file "Locate paris.svg"
end
end This actually not a profiler problem, it's an old Shoes thing with Windows (and sometimes OSX), particularly for a package script. I remember it from Shoes 2. Getting the real directory that your running in with Dir.getwd and then using that value to find your resource is a good work around. Perhaps even a best practice for cross platform Shoes (undocumented - sigh). Here's the 'offending' code in lib/shoes/profiler.rb starting at line 247 @trace_button = button 'Start Profile', state: (@file == nil ? "disabled": nil) do
load_st = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
$shoes_profiler.add_c_calls = @cc.checked?
Dir.chdir(File.dirname(@file)) do
$shoes_profiler.start{ eval IO.read(File.basename(@file)).force_encoding("UTF-8"), TOPLEVEL_BINDING }
load_end = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
end
end
@end_button = button 'End Profile' do
nodes, links = $shoes_profiler.stop(load_st, load_end, Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)) When you press the start button, it does chdir - but only long enough to load and start the script for monitoring. Then current dir will revert to where it was before. you then button click -> load resource of in your script and the current dir is set to ??? - probably where shoes.exe is installed because thats how Windows does things. Opening a script from the Splash screen works because it does a chdir to the script location, without the {block} so it's a permanent change of current dir. But, packaging and cross platform is going to bite you again if you do not use the Dir.getwd trick in your script to find the resources. |
@dredknight - Shoes 3.3.2 r2630 should fix the problem with |
I will test tomorrow :) |
Profiler works correctly with Shoes 3.3.2 r2658. A noob profiler question. What can I do if certain tasks like "draw" and "image" take the longest time? |
Closed in Shoes 3.3.2 |
Hello,
My GUI is a bit slow: are there tools within Shoes to profile the code and find where to optimize please?
Regards,
David
The text was updated successfully, but these errors were encountered: