Rust bindings for the Windows Performance Recorder (WPR) Control API
Find a file
2026-02-20 07:59:59 -05:00
.metadata Improve bindings 2026-02-20 07:59:59 -05:00
.windows/winmd Improve bindings 2026-02-20 07:59:59 -05:00
src Improve bindings 2026-02-20 07:59:59 -05:00
.gitignore Improve bindings 2026-02-20 07:59:59 -05:00
build.rs Add bindings 2026-02-19 08:29:28 -05:00
Cargo.lock Improve bindings 2026-02-20 07:59:59 -05:00
Cargo.toml Improve bindings 2026-02-20 07:59:59 -05:00
LICENSE Improve bindings 2026-02-20 07:59:59 -05:00
README.md Improve bindings 2026-02-20 07:59:59 -05:00

wprcontrol-rs

Rust bindings for the Windows Performance Recorder (WPR) Control API (WindowsPerformanceRecorderControl.h) from the Windows Performance Toolkit.

WPRControl API Reference

Example: Start and stop a WPR recording

use windows::Win32::Foundation::VARIANT_FALSE;
use windows::Win32::System::Com::{CLSCTX_INPROC_SERVER, COINIT_MULTITHREADED, CoInitializeEx};
use windows_core::{BSTR, Interface};
use wprcontrol::*;

fn create_wpr<T: Interface>(clsid: &windows_core::GUID) -> windows_core::Result<T> {
    unsafe {
        WPRCCreateInstanceUnderInstanceName::<_, T>(
            &BSTR::new(),
            clsid,
            None,
            CLSCTX_INPROC_SERVER.0 as u32,
        )
    }
}

fn main() -> windows_core::Result<()> {
    unsafe { CoInitializeEx(None, COINIT_MULTITHREADED).ok()? };

    // Create WPR objects
    let collection: IProfileCollection = create_wpr(&CProfileCollection)?;
    let control: IControlManager = create_wpr(&CControlManager)?;

    // Load a built-in profile
    let profile: IProfile = create_wpr(&CProfile)?;
    unsafe {
        profile.LoadFromFile(&BSTR::from("CPU.Verbose.File"), &BSTR::new())?;
        collection.Add(&profile, VARIANT_FALSE)?;
    }

    // Start recording
    unsafe { control.Start(&collection)? };

    // ... do work ...

    // Stop and save the trace
    unsafe {
        control.Stop(&BSTR::from("trace.etl"), &collection, None)?;
    }

    Ok(())
}