From 3a13b8d815ec13caeccfba4cea8280dba79dd5f2 Mon Sep 17 00:00:00 2001 From: Robert Chisholm Date: Mon, 1 Jan 2024 11:40:06 +0000 Subject: [PATCH] Types of profiling overview --- episodes/profiling-introduction.md | 59 +++++++++++++++++++++++++++--- learners/setup.md | 4 +- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/episodes/profiling-introduction.md b/episodes/profiling-introduction.md index 5741c57..3310618 100644 --- a/episodes/profiling-introduction.md +++ b/episodes/profiling-introduction.md @@ -28,19 +28,19 @@ Profiling is useful when you have written any code that will be running for a su As your code grows in complexity, it becomes increasingly difficult to estimate where time is being spent during execution. Profiling allows you to narrow down where the time is being spent, to identify whether this is of concern or not. - + Profiling is a relatively quick process which can either provide you the peace of mind that your code is efficient, or highlight the performance bottleneck. Knowing the bottleneck allows you to optimise it (or more specifically request support in optimising it), potentially leading to significant speedups enabling faster research. In extreme cases, addressing bottlenecks has enabled programs to run hundreds or thousands of times faster! Increasingly, particularly with relation to HPC, attention is being paid to the energy usage of software. Profiling your software will provide you the confidence that your software is an efficient use of resources. - + ::::::::::::::::::::::::::::::::::::: callout ## All Programmers Can Benefit - + Even professional programmers make oversights that can lead to poor performance, that can be identified through profiling. For example Grand Theft Auto Online, which has allegedly earned over $7bn since it's 2013 release, was notorious for it's slow loading times. @@ -95,11 +95,60 @@ Therefore, it is better described as a tool for **benchmarking**. ::::::::::::::::::::::::::::::::::::::::::::: ### Function-Level Profiling + +Software is typically comprised of a hierarchy of function calls, both functions written by the developer and those used from the core language and third party packages. + + +Function-level profiling analyses where time is being spent with respect to functions. Typically function-level profiling will calculate the number of times each function is called and the total time spent executing each function, inclusive and exclusive of child function calls. + + +This allows functions that occupy a disproportionate amount of the total runtime to be quickly identified and investigated. + + +In this course we will cover the usage of the function-level profiler `cprofile` and how it's output can be visualised with `snakeviz`. + ### Line-Level Profiling + +Function-level profiling may not always be granular enough, perhaps your software is a single long script, or function-level profiling highlighted a particularly complex function. + + +Line-level profiling provides greater granularity, analysing where time is being spent with respect to individual lines of code. + + +This will identify individual lines of code that occupy an disproportionate amount of the total runtime. + + + + + +In this course we will cover the usage of the line-level profiler `line_profiler`. + +### Timeline Profiling + +Timeline profiling takes a different approach to visualising where time is being spent during execution. + + +Typically a subset of function-level profiling, the execution of the profiled software is instead presented as a timeline highlighting the order of function execution in addition to the time spent in each individual function call. + + +By highlighting individual functions calls patterns relating to how performance scales over time can be identified. These would be hidden with the aforementioned aggregate approaches. + + +In this course we will cover the usage of the timeline profiler `viztracer`. + ### Hardware Metric Profiling - -## +Processor manufacturers typically release advanced profilers specific to their hardware with access to internal hardware metrics. +These profilers can provide analysis of performance relative to theoretical hardware maximums (e.g. memory bandwidth or mathematical operations per second) and detail the utilisation of specific hardware features and operations. + +Using these hardware specific profilers requires an advanced understanding of the relevant processor architecture and may lead to hardware specific optimisations. + +Example of these profilers include; Intel's VTune, AMD's uProf, and NVIDIA's Nsight Compute. + +Profiling of this nature is outside the scope of this course and not typically appropriate for Python code. + + +## Selecting an appropriate Test Case diff --git a/learners/setup.md b/learners/setup.md index d2f151d..ee1a373 100644 --- a/learners/setup.md +++ b/learners/setup.md @@ -22,10 +22,10 @@ This course uses Python and was developed using Python 3.11, therefore it is rec -The non-core Python packages required by the course are `snakeviz` and `line_profiler` and can be installed via `pip`. +The non-core Python packages required by the course are `snakeviz`, `line_profiler` and `viztracer` which can be installed via `pip`. ```input -pip install snakeviz line_profiler[all] +pip install snakeviz line_profiler[all] viztracer[full] ``` :::::::::::::::::::::::::::::::::::::::::::::::::::