This tool allows to gather statistical profile of CPU usage of mixed native-Python code.

Overview

Sampling Profiler for Python Build Status

This tool allows to gather statistical profile of CPU usage of mixed native-Python code. Currently supported platforms are Windows and Linux, x86_64 only.

Quick usage guide for Ubuntu 18.04.

Required for Linux:

  • python-dev package
  • setuptools python package
  • autoconf tool
  • libtool
  • make tool
  • unzip tool
  • g++ compiler
  • pkg-config tool
  • cmake tool

Required for Windows:

  • python installed
  • cmake
  • Visual Studio compilers, version depends on which Python version you want to target, see correct MSVC version

Before building do:

  • On Linux:
    • git submodule update --init --recursive
    • cd 3rd_party && ./prereq-build.sh && cd ..
  • On Windows:
    • Update third-party intel-xed, mbuild, protobuf, protobuf-c and safestringlib submodules (3rd_party folder):
      • git submodule update --init -- .\3rd_party\intel-xed
      • git submodule update --init -- .\3rd_party\mbuild
      • git submodule update --init -- .\3rd_party\protobuf
      • git submodule update --init -- .\3rd_party\protobuf-c
      • git submodule update --init -- .\3rd_party\safestringlib
    • Apply protobuf-c-vs2008-support.patch (step is required for Python 2 target only):
      • cd 3rd_party\protobuf-c && git apply ..\protobuf-c-vs2008-support.patch && cd ..\..
    • If you have installed VS2017 or VS2019, apply next command (optional step) in the same command line prompt window in which next command will be applied (please note, that path to the vcvars64.bat file may vary by version of VS installed):
      • CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.0
    • For Python 2.x run:
      • cd 3rd_party && prereq-build-py2.cmd && cd ..
    • For Python 3.5 or 3.6 run:
      • cd 3rd_party && prereq-build-py3.cmd && cd ..
    • For other versions of 3.x (untested) try fixing the file up specifying correct MSVC version

For building do:

  • mkdir pyext/build
  • cd pyext/build
  • On Windows:
    • For Python 2.x:
      • cmake -G "Visual Studio 9 2008 Win64" -DCMAKE_BUILD_TYPE=Release .. -DPYTHON_EXECUTABLE=path\to\python.exe
    • For Python 3.5 or 3.6:
      • cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Release .. -DPYTHON_EXECUTABLE=path\to\python.exe
    • Open generated "pysamprof.sln" with VS2008 (if Python 2) or VS2015 (if Python 3), choose "Release" "x64" as solution configuration
    • Build solution
    • Copy Release\pysamprof.pyd and trace_writer\Release\pysamprof-server.exe to desired location
  • On Linux:
    • cmake -DCMAKE_BUILD_TYPE=Release .. -DPYTHON_EXECUTABLE=path/to/python
    • make
    • Copy pysamprof.so and trace_writer/pysamprof-server to desired location
  • NOTE: specifying -DPYTHON_EXECUTABLE=path/to/python will force which Python version to compile against; if omitted it will select highest available Python on your system.

To use:

  • Add path to location which has pysamprof and pysamprof-server inside to PYTHONPATH
  • Do import pysamprof then pysamprof.start(target_path), see pyext/test.py as a quick reference
Comments
  • Converter does not work with Python 3.5.5

    Converter does not work with Python 3.5.5

    (cudf) user@host:/pysamprof/pyext$ PYTHONPATH=../../pysamprof/3rd_party/protobuf/python/ python ../../pysamprof/trace_writer/python/raw2pprof.py --raw ./result/trace/30920.0.raw --symbols ./result/trace/30920.0.symraw --out ./result/pprof_out/trace.pprof --resolve Traceback (most recent call last): File "../../pysamprof/trace_writer/python/raw2pprof.py", line 16, in TYPE_UNDERFINEDF, TYPE_SAMPLE, TYPE_FUNCTION_INFO, TYPE_MAPPING = [struct.unpack('>i', tag)[0] for tag in 'UNDF SMPL FNCI MAPP'.split()] File "../../pysamprof/trace_writer/python/raw2pprof.py", line 16, in TYPE_UNDERFINEDF, TYPE_SAMPLE, TYPE_FUNCTION_INFO, TYPE_MAPPING = [struct.unpack('>i', tag)[0] for tag in 'UNDF SMPL FNCI MAPP'.split()] TypeError: a bytes-like object is required, not 'str'

    opened by aregm 1
  • Protobuf patch has trailing whitespace triggering warning.

    Protobuf patch has trailing whitespace triggering warning.

    Applying patch in Windows: aregm@Barmaley MINGW64 /c/Projects/pysamprof (master) $ cd 3rd_party/protobuf-c && git apply ../protobuf-c-vs2008-support.patch ../protobuf-c-vs2008-support.patch:36: trailing whitespace.

    ../protobuf-c-vs2008-support.patch:39: trailing whitespace.

    warning: protobuf-c/protobuf-c.h has type 100644, expected 100755 warning: protoc-c/c_message.cc has type 100644, expected 100755 warning: 2 lines add whitespace errors.

    bug 
    opened by aregm 1
  • cmake failures on Ubuntu 20.04

    cmake failures on Ubuntu 20.04

    While executing cmake -DCMAKE_BUILD_TYPE=Release .. -DPYTHON_EXECUTABLE=/usr/bin/python3 on Ubuntu 20.04 I get the following errors:

    -- The C compiler identification is GNU 9.3.0
    -- The CXX compiler identification is GNU 9.3.0
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Found PythonInterp: /usr/bin/python3 (found version "3.8.2")
    -- detected CFLAGS for Python extensions: -fPIC
    -- detected LDFLAGS for Python extensions: -Wl,-Bsymbolic-functions  -Wl,-z,relro -g -fwrapv -O2
    -- libunwind needs lzma on this platform
    -- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.8.so (found version "3.8.2")
    -- Configuring done
    CMake Error at /nfs/site/home/gashiman/work/pysamprof/common/CMakeLists.txt:33 (add_library):
      Target "pysamprof-common" links to item "-Wl,-Bsymbolic-functions
      -Wl,-z,relro -g -fwrapv -O2 " which has leading or trailing whitespace.
      This is now an error according to policy CMP0004.
    
    
    CMake Error at /nfs/site/home/gashiman/work/pysamprof/common/CMakeLists.txt:33 (add_library):
      Target "pysamprof-common" links to item "-Wl,-Bsymbolic-functions
      -Wl,-z,relro -g -fwrapv -O2 " which has leading or trailing whitespace.
      This is now an error according to policy CMP0004.
    
    
    CMake Error at /nfs/site/home/gashiman/work/pysamprof/common/CMakeLists.txt:33 (add_library):
      Target "pysamprof-common" links to item "-Wl,-Bsymbolic-functions
      -Wl,-z,relro -g -fwrapv -O2 " which has leading or trailing whitespace.
      This is now an error according to policy CMP0004.
    
    
    CMake Error at /nfs/site/home/gashiman/work/pysamprof/common/CMakeLists.txt:33 (add_library):
      Target "pysamprof-common" links to item "-Wl,-Bsymbolic-functions
      -Wl,-z,relro -g -fwrapv -O2 " which has leading or trailing whitespace.
      This is now an error according to policy CMP0004.
    
    
    CMake Error at /nfs/site/home/gashiman/work/pysamprof/common/CMakeLists.txt:33 (add_library):
      Target "pysamprof-common" links to item "-Wl,-Bsymbolic-functions
      -Wl,-z,relro -g -fwrapv -O2 " which has leading or trailing whitespace.
      This is now an error according to policy CMP0004.
    
    
    CMake Error at /nfs/site/home/gashiman/work/pysamprof/common/CMakeLists.txt:33 (add_library):
      Target "pysamprof-common" links to item "-Wl,-Bsymbolic-functions
      -Wl,-z,relro -g -fwrapv -O2 " which has leading or trailing whitespace.
      This is now an error according to policy CMP0004.
    
    
    -- Generating done
    CMake Generate step failed.  Build files cannot be regenerated correctly.
    

    The problem is in Python configuration files so I ended up editing /usr/lib/python3.8/_sysconfigdata__x86_64-linux-gnu.py and removing all whitespace after -O2 where I found this flag (I am not sure exactly which lines goes into cmake config). But I don't think this is a correct way of handling this problem. Here is an answer to a similar problem https://stackoverflow.com/a/51367125/4584975 explaining how to strip whitespace from cmake config variables. I think it should be added to CMakeLists.txt.

    opened by gshimansky 0
  • Fix python3 support, fix mixed callstacks in release mode

    Fix python3 support, fix mixed callstacks in release mode

    Fix Python 3 support. Tested with Python 3.5 on Ubuntu 16.04 and Python 3.6 on Windows 10.

    Fix mixed callstacks in release mode - this is done by stopping compiler from doing tail call optimization in PyEval_EvalFrameEx probe so that probe is always present in callstack.

    Also drop legacy Makefiles - all is built with CMake now. And fixed a few warnings.

    opened by vnlitvinov 0
  • Implement auto-import of pysamprof

    Implement auto-import of pysamprof

    Currently to make profiling a child process possible that child has to manually do import pysamprof. By using proper pth file in site-packages it should be possible to automatically import pysamprof upon Python interpreter startup (see https://docs.python.org/3.7/library/site.html for reference).

    opened by vnlitvinov 0
  • Modularize `_pysamprof.c`

    Modularize `_pysamprof.c`

    Currently _pysamprof.c is both the interface to Python and the implementation of some internals. It should be only implementing the functions exposed to Python interpreter, and other things should be done in separate modules.

    opened by vnlitvinov 0
  • Deprecate Python 2 support

    Deprecate Python 2 support

    pysamprof now supports both Python versions. Most likely adding support for newer versions or other platforms (like Mac) won't break Python 2 support, but, as Python 2 is being deprecated in Jan 2020, it makes sense to deprecate its support (and maybe even remove said support to reduce the amount of ifdef-s around the code).

    opened by vnlitvinov 0
  • Wrap certain POSIX syscalls

    Wrap certain POSIX syscalls

    pysamprof uses signals on POSIX to collect stacks at regular intervals.

    According to the spec, incoming signal interrupts a blocking wait of certain system calls (like recv). To make pysamprof less intrusive it needs to probe these system functions and automatically re-launch them if they were interrupted by profiling signal. Note that those functions shouldn't be restarted if they were interrupted by other signals!

    Also note that this most likely applies to both Mac and Linux.

    opened by vnlitvinov 0
  • Publish pysamprof to PyPI

    Publish pysamprof to PyPI

    Prerequisite: #21.

    This most likely requires both posting a source package and Python wheels for most popular cases (32- and 64-bit versions; Windows, Linux, Mac; Python 3.6 and 3.7).

    opened by vnlitvinov 0
Owner
Intel Corporation
Intel Corporation
PerfSpect is a system performance characterization tool based on linux perf targeting Intel microarchitectures

PerfSpect PerfSpect is a system performance characterization tool based on linux perf targeting Intel microarchitectures. The tool has two parts perf

Intel Corporation 139 Dec 30, 2022
Rip Raw - a small tool to analyse the memory of compromised Linux systems

Rip Raw Rip Raw is a small tool to analyse the memory of compromised Linux systems. It is similar in purpose to Bulk Extractor, but particularly focus

Cado Security 127 Oct 28, 2022
Pyccel stands for Python extension language using accelerators.

Pyccel stands for Python extension language using accelerators.

Pyccel 242 Jan 2, 2023
Sampling profiler for Python programs

py-spy: Sampling profiler for Python programs py-spy is a sampling profiler for Python programs. It lets you visualize what your Python program is spe

Ben Frederickson 9.5k Jan 1, 2023
A Python native, OS native GUI toolkit.

Toga A Python native, OS native GUI toolkit. Prerequisites Minimum requirements Toga requires Python 3. Python 2 is not supported. If you're on macOS,

BeeWare 3.3k Dec 31, 2022
A Python native, OS native GUI toolkit.

Toga A Python native, OS native GUI toolkit. Prerequisites Minimum requirements Toga requires Python 3. Python 2 is not supported. If you're on macOS,

BeeWare 3.3k Jan 2, 2023
Django package to log request values such as device, IP address, user CPU time, system CPU time, No of queries, SQL time, no of cache calls, missing, setting data cache calls for a particular URL with a basic UI.

django-web-profiler's documentation: Introduction: django-web-profiler is a django profiling tool which logs, stores debug toolbar statistics and also

MicroPyramid 77 Oct 29, 2022
GET-ACQ is a python tool used to gather all companies acquired by a given company domain name.

get-acq ?? GET-ACQ is a python tool used to gather all companies acquired by a given company domain name. It is done by calling SecurityTrails API. Us

Milan 7 Dec 19, 2022
Simple tool to gather domains from crt.sh using the organization name

Domain Collector: _ _ ___ _ _ _ __| | ___ _ __ ___ __ _(_)_ __ / __\___ | |

Cyber Guy 63 Dec 24, 2022
This tool for beginner and help those people they gather information about Email Header Analysis, Instagram Information, Instagram Username Check, Ip Information, Phone Number Information, Port Scan

This tool for beginner and help those people they gather information about Email Header Analysis, Instagram Information, Instagram Username Check, Ip Information, Phone Number Information, Port Scan. This tool shows your hostname and public IP first, then user give input and according to option this tool work. This tool work diffrent Oprating system.

cb-kali 5 Feb 18, 2022
BlackIP-Rep is a tool designed to gather the reputation and information of Bulk IP's.

BlackIP-Rep is a tool designed to gather the reputation and information of Bulk IP's. Focused on increasing the workflow of Security Operations(SOC) team during investigation.

0LiVEr 6 Dec 12, 2022
A Python Instagram Scraper for Downloading Profile's Posts, stories, ProfilePic and See the Details of Particular Instagram Profile.

✔ ✔ InstAstra ⚡ ⚡ ⁜ Description ~ A Python Instagram Scraper for Downloading Profile's Posts, stories, ProfilePic and See the Details of Particular In

null 12 Jun 23, 2022
Statistical Analysis 📈 focused on statistical analysis and exploration used on various data sets for personal and professional projects.

Statistical Analysis ?? This repository focuses on statistical analysis and the exploration used on various data sets for personal and professional pr

Andy Pham 1 Sep 3, 2022
Cross-platform-profile-pic-changer - Script to change profile pictures across multiple platforms

cross-platform-profile-pic-changer script to change profile pictures across mult

null 4 Jan 17, 2022
whm also known as wifi-heat-mapper is a Python library for benchmarking Wi-Fi networks and gather useful metrics that can be converted into meaningful easy-to-understand heatmaps.

whm also known as wifi-heat-mapper is a Python library for benchmarking Wi-Fi networks and gather useful metrics that can be converted into meaningful easy-to-understand heatmaps.

Nischay Mamidi 128 Dec 16, 2022
A simple tool that allows you to change your default AWS CLI profile.

Select AWS Profile Select AWS Profile (slapr) is a simple tool that lets you select which AWS Profile you want to use and sets it as the default AWS p

Antoni Yanev 2 Nov 9, 2022
Code for the prototype tool in our paper "CoProtector: Protect Open-Source Code against Unauthorized Training Usage with Data Poisoning".

CoProtector Code for the prototype tool in our paper "CoProtector: Protect Open-Source Code against Unauthorized Training Usage with Data Poisoning".

Zhensu Sun 1 Oct 26, 2021
Sink is a CLI tool that allows users to synchronize their local folders to their Google Drives. It is similar to the Git CLI and allows fast and reliable syncs with the drive.

Sink is a CLI synchronisation tool that enables a user to synchronise local system files and folders with their Google Drives. It follows a git C

Yash Thakre 16 May 29, 2022
BitPack is a practical tool to efficiently save ultra-low precision/mixed-precision quantized models.

BitPack is a practical tool that can efficiently save quantized neural network models with mixed bitwidth.

Zhen Dong 36 Dec 2, 2022
HatSploit native powerful payload generation and shellcode injection tool that provides support for common platforms and architectures.

HatVenom HatSploit native powerful payload generation and shellcode injection tool that provides support for common platforms and architectures. Featu

EntySec 100 Dec 23, 2022