Skip to content

Commit df2097e

Browse files
authored
Add python windows #67 (#68)
* added workflow_dispatch to ci-ffi-python * added windows build * commented out all other builds * set correct windows py-platform * removed windows server 2011 * Adeed capability to get windows thread id. * Added winapi * bumped workflow file to trigger build * wrapped the function with unsafe and the error checker * made pyroscope_ffi tomls point to a path * Used the pid type from remoteprocess to accound for platform differences. * bump workflow * put back the different platform python builds * Added the windows-test file. * Corrected a typo. * added a windows test build * added powershell for installing wheel * udpated trigger on test job * updated powershell expression * updating main test file * use the re-exported Pid type instead of directly depending on remoteprocess * remove the remoteprocesd dep * removed unnecessary Cargo change * Added windows CI PySpy backend. Co-authored-by: Michael Davis <[email protected]>
1 parent 37b885f commit df2097e

File tree

7 files changed

+230
-3
lines changed

7 files changed

+230
-3
lines changed

.github/workflows/ci-backend-pyspy.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,33 @@ jobs:
5858
with:
5959
args: --manifest-path pyroscope_backends/pyroscope_pyspy/Cargo.toml
6060
command: test
61+
62+
windows-build:
63+
name: ${{ matrix.os }} - ${{ matrix.target }}
64+
runs-on: ${{ matrix.os }}
65+
strategy:
66+
matrix:
67+
os: [windows-latest]
68+
target: [x86_64-pc-windows-gnu]
69+
steps:
70+
- name: Checkout sources
71+
uses: actions/checkout@v2
72+
73+
- name: Install stable toolchain
74+
uses: omarabid-forks/rs-toolchain@v1
75+
with:
76+
profile: minimal
77+
toolchain: stable
78+
override: true
79+
80+
- name: Cargo build for pyspy
81+
uses: omarabid-forks/rs-cargo@v1
82+
with:
83+
args: --manifest-path pyroscope_backends/pyroscope_pyspy/Cargo.toml
84+
command: build
85+
86+
- name: Tests for pyspy
87+
uses: omarabid-forks/rs-cargo@v1
88+
with:
89+
args: --manifest-path pyroscope_backends/pyroscope_pyspy/Cargo.toml
90+
command: test
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Python Package Windows Only
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- 'pyroscope_ffi/python/**'
8+
- '.github/workflows/ci-ffi-python.yml'
9+
- '.github/workflows/ci-ffi-python-windows.yml'
10+
branches:
11+
- '**'
12+
pull_request:
13+
paths:
14+
- 'pyroscope_ffi/python/**'
15+
- '.github/workflows/ci-ffi-python.yml'
16+
branches:
17+
- '**'
18+
19+
jobs:
20+
windows-build:
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
include:
25+
- windows-version: "2022"
26+
target: x86_64-pc-windows-gnu
27+
py-platform: win_amd64
28+
29+
name: windows - ${{ matrix.py-platform }}
30+
runs-on: windows-${{ matrix.windows-version }}
31+
32+
steps:
33+
- uses: actions/checkout@v2
34+
35+
- uses: actions-rs/toolchain@v1
36+
with:
37+
toolchain: stable
38+
target: ${{ matrix.target }}
39+
profile: minimal
40+
override: true
41+
42+
- uses: actions/setup-python@v2
43+
with:
44+
python-version: 3.9
45+
46+
47+
- name: Build Wheel
48+
run: |
49+
pip install wheel
50+
python3 setup.py bdist_wheel -p ${{ matrix.py-platform }}
51+
working-directory: pyroscope_ffi/python
52+
env:
53+
CARGO_BUILD_TARGET: ${{ matrix.target }}
54+
55+
- uses: actions/upload-artifact@v2
56+
with:
57+
name: ${{ matrix.target }}
58+
path: pyroscope_ffi/python/dist/*
59+
60+
windows-test:
61+
strategy:
62+
fail-fast: false
63+
matrix:
64+
PYROSCOPE_DETECT_SUBPROCESSES: [1, 0]
65+
PYROSCOPE_ONCPU: [1, 0]
66+
PYROSCOPE_GIL_ONLY: [1, 0]
67+
PYROSCOPE_NATIVE: [1, 0]
68+
PYTHON_VERSION: ['2.7', '3.7', '3.8', '3.9', '3.10']
69+
needs: ['windows-build']
70+
name: Windows Test
71+
runs-on: windows-2022
72+
steps:
73+
- name: Set up Python
74+
uses: actions/setup-python@v4
75+
with:
76+
python-version: ${{ matrix.PYTHON_VERSION }}
77+
architecture: x64
78+
- uses: actions/download-artifact@master
79+
with:
80+
name: x86_64-pc-windows-gnu
81+
path: "${{github.workspace}}/python"
82+
83+
- run: "python --version"
84+
- run: "python3 --version"
85+
- run: "cd ${{ github.workspace }}/python && ls"
86+
- run: |
87+
cd ${{ github.workspace }}/python
88+
foreach($file in Get-ChildItem -Filter *.whl){pip install $file}
89+
- uses: actions/checkout@v2
90+
with:
91+
submodules: recursive
92+
- name: Run Python Script
93+
run: pyroscope_ffi/python/scripts/tests/test.py
94+
env:
95+
PYROSCOPE_RUN_ID: ${{ github.run_id }}
96+
PYROSCOPE_ARCH: x86_64-pc-windows-gnu
97+
PYROSCOPE_API_TOKEN: ${{ secrets.PYROSCOPE_API_TOKEN }}
98+
PYROSCOPE_DETECT_SUBPROCESSES: ${{ matrix.PYROSCOPE_DETECT_SUBPROCESSES }}
99+
PYROSCOPE_ONCPU: ${{ matrix.PYROSCOPE_ONCPU }}
100+
PYROSCOPE_GIL_ONLY: ${{ matrix.PYROSCOPE_GIL_ONLY }}
101+
PYROSCOPE_NATIVE: ${{ matrix.PYROSCOPE_NATIVE }}
102+
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}

.github/workflows/ci-ffi-python.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Python Package
22

33
on:
4+
workflow_dispatch:
45
push:
56
paths:
67
- 'pyroscope_ffi/python/**'
@@ -199,6 +200,90 @@ jobs:
199200
PYROSCOPE_NATIVE: ${{ matrix.PYROSCOPE_NATIVE }}
200201
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}
201202

203+
204+
windows-build:
205+
strategy:
206+
fail-fast: false
207+
matrix:
208+
include:
209+
- windows-version: "2022"
210+
target: x86_64-pc-windows-gnu
211+
py-platform: win_amd64
212+
213+
name: windows - ${{ matrix.py-platform }}
214+
runs-on: windows-${{ matrix.windows-version }}
215+
216+
steps:
217+
- uses: actions/checkout@v2
218+
219+
- uses: actions-rs/toolchain@v1
220+
with:
221+
toolchain: stable
222+
target: ${{ matrix.target }}
223+
profile: minimal
224+
override: true
225+
226+
- uses: actions/setup-python@v2
227+
with:
228+
python-version: 3.9
229+
230+
231+
- name: Build Wheel
232+
run: |
233+
pip install wheel
234+
python3 setup.py bdist_wheel -p ${{ matrix.py-platform }}
235+
working-directory: pyroscope_ffi/python
236+
env:
237+
CARGO_BUILD_TARGET: ${{ matrix.target }}
238+
239+
- uses: actions/upload-artifact@v2
240+
with:
241+
name: ${{ matrix.target }}
242+
path: pyroscope_ffi/python/dist/*
243+
244+
windows-test:
245+
strategy:
246+
fail-fast: false
247+
matrix:
248+
PYROSCOPE_DETECT_SUBPROCESSES: [1, 0]
249+
PYROSCOPE_ONCPU: [1, 0]
250+
PYROSCOPE_GIL_ONLY: [1, 0]
251+
PYROSCOPE_NATIVE: [1, 0]
252+
PYTHON_VERSION: ['2.7', '3.7', '3.8', '3.9', '3.10']
253+
needs: ['windows-build']
254+
name: Windows Test
255+
runs-on: windows-2022
256+
steps:
257+
- name: Set up Python
258+
uses: actions/setup-python@v4
259+
with:
260+
python-version: ${{ matrix.PYTHON_VERSION }}
261+
architecture: x64
262+
- uses: actions/download-artifact@master
263+
with:
264+
name: x86_64-pc-windows-gnu
265+
path: "${{github.workspace}}/python"
266+
267+
- run: "python --version"
268+
- run: "python3 --version"
269+
- run: "cd ${{ github.workspace }}/python && ls"
270+
- run: |
271+
cd ${{ github.workspace }}/python
272+
foreach($file in Get-ChildItem -Filter *.whl){pip install $file}
273+
- uses: actions/checkout@v2
274+
with:
275+
submodules: recursive
276+
- name: Run Python Script
277+
run: pyroscope_ffi/python/scripts/tests/test.py
278+
env:
279+
PYROSCOPE_RUN_ID: ${{ github.run_id }}
280+
PYROSCOPE_ARCH: x86_64-pc-windows-gnu
281+
PYROSCOPE_API_TOKEN: ${{ secrets.PYROSCOPE_API_TOKEN }}
282+
PYROSCOPE_DETECT_SUBPROCESSES: ${{ matrix.PYROSCOPE_DETECT_SUBPROCESSES }}
283+
PYROSCOPE_ONCPU: ${{ matrix.PYROSCOPE_ONCPU }}
284+
PYROSCOPE_GIL_ONLY: ${{ matrix.PYROSCOPE_GIL_ONLY }}
285+
PYROSCOPE_NATIVE: ${{ matrix.PYROSCOPE_NATIVE }}
286+
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}
202287
sdist-build:
203288
name: sdist
204289
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ url = "2.2.2"
5959
libflate = "1.2.0"
6060
libc = "^0.2.124"
6161
prost = "0.10"
62+
winapi = "0.3.9"
6263

6364
[dev-dependencies]
6465
tokio = { version = "1.18", features = ["full"] }

pyroscope_backends/pyroscope_pyspy/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::{
1414
},
1515
thread::JoinHandle,
1616
};
17+
use py_spy::Pid;
1718

1819
const LOG_TAG: &str = "Pyroscope::Pyspy";
1920

@@ -29,7 +30,7 @@ pub fn pyspy_backend(config: PyspyConfig) -> BackendImpl<BackendUninitialized> {
2930
#[derive(Debug, Clone)]
3031
pub struct PyspyConfig {
3132
/// Process to monitor
32-
pid: Option<i32>,
33+
pid: Option<Pid>,
3334
/// Sampling rate
3435
sample_rate: u32,
3536
/// Backend Config
@@ -66,7 +67,7 @@ impl Default for PyspyConfig {
6667

6768
impl PyspyConfig {
6869
/// Create a new PyspyConfig
69-
pub fn new(pid: i32) -> Self {
70+
pub fn new(pid: Pid) -> Self {
7071
PyspyConfig {
7172
pid: Some(pid),
7273
..Default::default()

pyroscope_ffi/ffikit/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
interprocess = { version = "1.1.1", features = ["nonblocking"] }
10-
pyroscope = "0.5.3"
10+
pyroscope = { path = "../../" }
1111
bincode = "2.0.0-rc.1"
1212
lazy_static = "0.1.4"
1313
log = "0.4"

src/utils.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,19 @@ mod check_err_tests {
7474
}
7575

7676
/// libc::epoll_ctl wrapper
77+
#[cfg(not(target_os = "windows"))]
7778
pub fn pthread_self() -> Result<u64> {
7879
let thread_id = check_err(unsafe { libc::pthread_self() })? as u64;
7980
Ok(thread_id)
8081
}
8182

83+
84+
#[cfg(target_os = "windows")]
85+
pub fn pthread_self() -> Result<u64> {
86+
let thread_id = check_err(unsafe { winapi::um::processthreadsapi::GetCurrentThreadId() })? as u64;
87+
Ok(thread_id)
88+
}
89+
8290
#[cfg(test)]
8391
mod pthread_self_tests {
8492
use crate::utils::pthread_self;

0 commit comments

Comments
 (0)