Shark: Difference between revisions
From charlesreid1
(Created page with "Shark is a profiler for Mac. It has a nice GUI interface. Shark works much different from other profilers like gprof. Basically, you run Shark, tell it to start gathering ...") |
No edit summary |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
Shark is a profiler for Mac. It has a nice GUI interface. | Shark is a profiler for Mac. It has a nice GUI interface. | ||
Shark works much different from other profilers like [[ | Shark works much different from other profilers like [[Gprof]]. Basically, you run Shark, tell it to start gathering data, then you run your program like normal. Shark gathers information on every single process happening on the system. | ||
It is arguable whether this is a good approach or not, but that's not really the point of this article. | It is arguable whether this is a good approach or not, but that's not really the point of this article. | ||
| Line 21: | Line 21: | ||
When you press "Start," Shark will begin to gather data. This is when you run your program. | When you press "Start," Shark will begin to gather data. This is when you run your program. | ||
[[Image:Shark3.png]] | [[Image:Shark3.png|350px]] | ||
Once you've finished gathering data, you can press "Stop" and Shark will start to process your data. | Once you've finished gathering data, you can press "Stop" and Shark will start to process your data. | ||
[[Image:Shark4.png]] | [[Image:Shark4.png|350px]] | ||
After it finishes processing the data, it will show you all the different processes that were taking place on your system, and how much time each one took. | After it finishes processing the data, it will show you all the different processes that were taking place on your system, and how much time each one took. | ||
[[Image:Shark5.png|500px]] | |||
Assuming you have compiled your binary with the <code>-g</code> (debug) flag, when you double-click on a particular item in the list, it will show you the source code, and the timing for each line of code. | |||
The self column will tell you the percentage of time spent on that line out of the total time spent in that particular method. The total column will tell you the percentage of time spent on that line out of the total time spent on everything. | |||
[[Image:Shark6.png|500px]] | |||
Shark will also give you suggestions on how you can improve the performance of various bottlenecks in your code. These are often helpful, but sometimes not. | |||
{{Programs}} | |||
[[Category:Profiling]] | |||
Latest revision as of 04:15, 19 March 2017
Shark is a profiler for Mac. It has a nice GUI interface.
Shark works much different from other profilers like Gprof. Basically, you run Shark, tell it to start gathering data, then you run your program like normal. Shark gathers information on every single process happening on the system.
It is arguable whether this is a good approach or not, but that's not really the point of this article.
Timing Profiles
You can use a timing profile to determine how much time is spent in various system and function calls. This is useful for developing a sense of which particular lines or functions in the code are taking most of the computational time.
Gathering Timing Data
Start Shark and pick "Time Profile."
When you press "Start," Shark will begin to gather data. This is when you run your program.
Once you've finished gathering data, you can press "Stop" and Shark will start to process your data.
After it finishes processing the data, it will show you all the different processes that were taking place on your system, and how much time each one took.
Assuming you have compiled your binary with the -g (debug) flag, when you double-click on a particular item in the list, it will show you the source code, and the timing for each line of code.
The self column will tell you the percentage of time spent on that line out of the total time spent in that particular method. The total column will tell you the percentage of time spent on that line out of the total time spent on everything.
Shark will also give you suggestions on how you can improve the performance of various bottlenecks in your code. These are often helpful, but sometimes not.