You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: episodes/profiling-functions.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ As a stack it is a last-in first-out (LIFO) data structure.
46
46
47
47
{alt="A greyscale diagram showing a (call)stack, containing 5 stack frame. Two additional stack frames are shown outside the stack, one is marked as entering the call stack with an arrow labelled push and the other is marked as exiting the call stack labelled pop."}
48
48
49
-
When a function is called, a frame to track it's variables and metadata is pushed to the call stack.
49
+
When a function is called, a frame to track its variables and metadata is pushed to the call stack.
50
50
When that same function finishes and returns, it is popped from the stack and variables local to the function are dropped.
51
51
52
52
If you've ever seen a stack overflow error, this refers to the call stack becoming too large.
@@ -88,7 +88,7 @@ Hence, this prints the following call stack:
88
88
traceback.print_stack()
89
89
```
90
90
91
-
The first line states the file and line number where `a()` was called from (the last line of code in the file shown). The second line states that it was the function `a()` that was called, this could include it's arguments. The third line then repeats this pattern, stating the line number where `b2()` was called inside `a()`. This continues until the call to `traceback.print_stack()` is reached.
91
+
The first line states the file and line number where `a()` was called from (the last line of code in the file shown). The second line states that it was the function `a()` that was called, this could include its arguments. The third line then repeats this pattern, stating the line number where `b2()` was called inside `a()`. This continues until the call to `traceback.print_stack()` is reached.
92
92
93
93
You may see stack traces like this when an unhandled exception is thrown by your code.
94
94
@@ -102,7 +102,7 @@ You may see stack traces like this when an unhandled exception is thrown by your
102
102
[`cProfile`](https://docs.python.org/3/library/profile.html#instant-user-s-manual) is a function-level profiler provided as part of the Python standard library.
103
103
104
104
<!-- How is it used? -->
105
-
It can be called directly within your Python code as an imported package, however it's easier to use it's script interface:
105
+
It can be called directly within your Python code as an imported package, however it's easier to use its script interface:
@@ -199,9 +199,9 @@ In the icicle visualization style functions are represented by rectangles. A roo
199
199
-->
200
200
201
201
The icicle diagram displayed by `snakeviz` represents an aggregate of the call stack during the execution of the profiled code.
202
-
The box which fills the top row represents the the root call, filling the row shows that it occupied 100% of the runtime.
202
+
The box which fills the top row represents the root call, filling the row shows that it occupied 100% of the runtime.
203
203
The second row holds the child methods called from the root, with their widths relative to the proportion of runtime they occupied.
204
-
This continues with each subsequent row, however where a method only occupies 50% of the runtime, it's children can only occupy a maximum of that runtime hence the appearance of "icicles" as each row gets narrower when the overhead of methods with no further children is accounted for.
204
+
This continues with each subsequent row, however where a method only occupies 50% of the runtime, its children can only occupy a maximum of that runtime hence the appearance of "icicles" as each row gets narrower when the overhead of methods with no further children is accounted for.
205
205
206
206
By clicking a box within the diagram, it will "zoom" making the selected box the root allowing more detail to be explored. The diagram is limited to 10 rows by default ("Depth") and methods with a relatively small proportion of the runtime are hidden ("Cutoff").
207
207
@@ -213,7 +213,7 @@ As you hover each box, information to the left of the diagram updates specifying
213
213
214
214
If you're more familiar with writing Python inside Jupyter notebooks you can still use `snakeviz` directly from inside notebooks using the notebooks "magic" prefix (`%`) and it will automatically call `cProfile` for you.
215
215
216
-
First `snakeviz` must be installed and it's extension loaded.
216
+
First `snakeviz` must be installed and its extension loaded.
217
217
218
218
```py
219
219
!pip install snakeviz
@@ -239,7 +239,7 @@ my_function()
239
239
240
240
In both cases, the full `snakeviz` profile visualisation will appear as an output within the notebook!
241
241
242
-
*You may wish to right click the top of the output, and select "Disable Scrolling for Outputs" to expand it's box if it begins too small.*
242
+
*You may wish to right click the top of the output, and select "Disable Scrolling for Outputs" to expand its box if it begins too small.*
243
243
244
244
:::::::::::::::::::::::::::::::::::::::::::::
245
245
@@ -323,7 +323,7 @@ As `time.sleep()` is a core Python method it is displayed as "built-in method" a
323
323
324
324
If you hover any boxes representing the methods from the above code, you will see file and line properties completed. The directory property remains empty as the profiled code was in the root of the working directory. A profile of a large project with many files across multiple directories will see this filled.
325
325
326
-
Find the box representing `c_2()` on the icicle diagram, it's children are unlabelled because they are not wide enough (but they can still be hovered). Clicking `c_2()` zooms in the diagram, showing the children to be `time.sleep()` and `d_1()`.
326
+
Find the box representing `c_2()` on the icicle diagram, its children are unlabelled because they are not wide enough (but they can still be hovered). Clicking `c_2()` zooms in the diagram, showing the children to be `time.sleep()` and `d_1()`.
327
327
328
328
To zoom back out you can either click the top row, which will zoom out one layer, or click "Reset Zoom" on the left-hand side.
0 commit comments