FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

DynaPyt/tutorial at main · sola-st/DynaPyt · GitHub

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Tutorial

This is the tutorial page originally designed for ASE 2023. It might not be updated on every release, so please open an issue if something does not work. Original slides of the ASE 2023 tutorial: Google slides

Table of contents:

Setup

To isolate the packages that you install during this tutorial either use Docker, or use a virtual environment.

Docker

  1. Install Docker (if it is your first time using Docker, Docker Desktop is recommended)
  2. Build the image: docker build -t dynapyt_tutorial .
  3. Run bash in the container: docker run -it dynapyt_tutorial /bin/bash

Note: Changing the code in your host machine does not change the code inside the container. So you either need to share the directory using -v option when running docker (-v .:/dynapyt/), or repeat steps 2 and 3 each time you modify or implement an analysis.

Virtual Environment

  1. Install virtual environment:
    • With pipx: pipx install virtualenv
    • With pip: python -m pip install --user virtualenv
  2. Create a directory for the virtual environment: mkdir ~/.dynapyt_virtualenv
  3. Create the virtual environment: virtualenv dynapyt_virtualenv ~/.dynapyt_virtualenv
  4. Activate the virtual environment: source ~/.dynapyt_virtualenv/bin/activate

Getting Started

Install DynaPyt

  • Install the latest release:
    pip install dynapyt
    Or
  • Install from source:
    git clone https://github.com/sola-st/DynaPyt.git
    cd DynaPyt
    pip install .

First Instrumentation

python -m dynapyt.run_instrumentation \
 --analysis dynapyt.analyses.TraceAll.TraceAll \
 --directory task1
  • Checkout the instrumented code in task1/main.py and compare it to the original code in task1/main.py.orig.
  • Checkout the metadata file task1/main-dynapyt.json.

First Analysis

python -m dynapyt.run_analysis \
 --analysis dynapyt.analyses.TraceAll.TraceAll \
 --entry task1/main.py

Branch Coverage

Generate a log of branches taken and their truth values.

Implement the analysis

  1. Create a file under tutorial-analyses/src/tutorial_analyses called BranchCoverageAnalysis.py.
  2. Implement the analysis class as a subclass of dynapyt.analyses.BaseAnalysis.
  3. Build the analysis: pip install ./tutorial-analyses

Instrument the code

python -m dynapyt.run_instrumentation \
 --analysis tutorial_analyses.BranchCoverageAnalysis.BranchCoverageAnalysis \
 --directory task2

Run the analysis

python -m dynapyt.run_analysis \
 --analysis tutorial_analyses.BranchCoverageAnalysis.BranchCoverageAnalysis \
 --entry task2/main.py

Dynamic Call Graph

Generate the graph of dynamic function calls.

Implement the analysis

  1. Create a file under tutorial-analyses/src/tutorial_analyses called CallGraphAnalysis.py.
  2. Implement the analysis class as a subclass of dynapyt.analyses.BaseAnalysis.
  3. Build the analysis: pip install ./tutorial-analyses

Instrument the code

python -m dynapyt.run_instrumentation \
 --analysis tutorial_analyses.CallGraphAnalysis.CallGraphAnalysis \
 --directory task3

Run the analysis

python -m dynapyt.run_analysis \
 --analysis tutorial_analyses.CallGraphAnalysis.CallGraphAnalysis \
 --entry task3/main.py

Hook Hierarchy

String concatenation with += is slower than "".join(). Find cases that a string gets appended in a loop.

Implement the analysis

  1. Create a file under tutorial-analyses/src/tutorial_analyses called SlowStringConcatAnalysis.py.
  2. Implement the analysis class as a subclass of dynapyt.analyses.BaseAnalysis.
  3. Build the analysis: pip install ./tutorial-analyses

Instrument the code

python -m dynapyt.run_instrumentation \
 --analysis tutorial_analyses.SlowStringConcatAnalysis.SlowStringConcatAnalysis \
 --directory task4

Run the analysis

python -m dynapyt.run_analysis \
 --analysis tutorial_analyses.SlowStringConcatAnalysis.SlowStringConcatAnalysis \
 --entry task4/main.py

Modify Execution

Force the execution to always take the opposite branch.

Implement the analysis

  1. Create a file under tutorial-analyses/src/tutorial_analyses called OppositeBranchAnalysis.py.
  2. Implement the analysis class as a subclass of dynapyt.analyses.BaseAnalysis.
  3. Build the analysis: pip install ./tutorial-analyses

Instrument the code

python -m dynapyt.run_instrumentation \
 --analysis tutorial_analyses.OppositeBranchAnalysis.OppositeBranchAnalysis \
 --directory task5

Run the analysis

python -m dynapyt.run_analysis \
 --analysis tutorial_analyses.OppositeBranchAnalysis.OppositeBranchAnalysis \
 --entry task5/main.py

Back | FazBrowse Home | New Git URL