Skip to content

Commit

Permalink
Replace rust_hawktracer with tracing-chrome
Browse files Browse the repository at this point in the history
No weird C++ with CMake dependency, more flexibility and easier to use.
  • Loading branch information
YaLTeR committed May 15, 2022
1 parent b210d49 commit a31c1f8
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 92 deletions.
31 changes: 3 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
os: [ubuntu-20.04, windows-2019]
rust: [stable, beta]
features: ['', vulkan-debug, profiling, 'vulkan-debug,profiling']
features: ['', vulkan-debug]
configuration: [debug, release]
cross: [false, true]

Expand All @@ -24,32 +24,12 @@ jobs:
rust: beta
- configuration: release
features: vulkan-debug
- configuration: release
features: 'vulkan-debug,profiling'

- cross: true
os: windows-2019

# We want only a release profile build, but on Windows hawktracer fails to build on release.
- configuration: debug
features: profiling
os: ubuntu-20.04
- configuration: release
features: profiling
os: windows-2019

# rust-hawktracer fails to build with explicit -m32 on the CI.
- features: profiling
os: ubuntu-20.04
- features: 'vulkan-debug,profiling'
os: ubuntu-20.04

- rust: beta
features: vulkan-debug
- rust: beta
features: profiling
- rust: beta
features: 'vulkan-debug,profiling'

include:
- os: ubuntu-20.04
Expand All @@ -75,11 +55,6 @@ jobs:
- configuration: release
release-flag: '--release'

- features: profiling
profiling-dep: lib32stdc++-9-dev
- features: 'vulkan-debug,profiling'
profiling-dep: lib32stdc++-9-dev

name: ${{ matrix.rust }} - ${{ matrix.label }} - ${{ matrix.configuration }} - ${{ matrix.features }}
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
Expand All @@ -104,7 +79,7 @@ jobs:
if: matrix.os == 'ubuntu-20.04'
run: |
sudo apt-get update -y
sudo apt-get install -y libc6-dev-i386 ${{ matrix.profiling-dep }} ${{ matrix.cross-dep }}
sudo apt-get install -y libc6-dev-i386 ${{ matrix.cross-dep }}
- name: Install Rust
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -132,7 +107,7 @@ jobs:
args: --all --target ${{ matrix.target }} ${{ matrix.release-flag }} --features=${{ matrix.features }}

- uses: actions/upload-artifact@v2
if: matrix.rust == 'stable' && matrix.features != 'vulkan-debug,profiling' && !matrix.cross
if: matrix.rust == 'stable' && !matrix.cross
with:
name: bxt-rs-${{ runner.os }}-${{ matrix.configuration }}-${{ matrix.features }}
path: target/${{ matrix.target }}/${{ matrix.configuration }}/${{ matrix.filename }}
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ bxt-strafe = { path = "bxt-strafe" }
color-eyre = { version = "0.5.11", default-features = false }
once_cell = "1.8.0"
ash = "0.33.0"
rust_hawktracer = "0.7.0"
thiserror = "1.0.26"
byte-slice-cast = "1.0.0"
crossbeam-channel = "0.5.1"
Expand All @@ -32,6 +31,7 @@ tap = "1.0.1"
mlua = { version = "0.7.3", features = ["luajit", "vendored", "serialize"] }
tracing = "0.1.34"
tracing-subscriber = "0.3.11"
tracing-chrome = "0.6.0"

[patch.crates-io]
luajit-src = { git = "https://github.com/YaLTeR/luajit-src-rs.git", branch = "build-fixes" }
Expand Down Expand Up @@ -61,4 +61,3 @@ gl_generator = "0.14.0"

[features]
vulkan-debug = []
profiling = ["rust_hawktracer/profiling_enabled"]
4 changes: 1 addition & 3 deletions src/gl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::os::raw::c_void;

use rust_hawktracer::*;

use crate::modules::capture;
use crate::utils::*;

Expand All @@ -20,7 +18,7 @@ pub static GL: MainThreadRefCell<Option<Gl>> = MainThreadRefCell::new(None);
///
/// [`reset_pointers()`] must be called before the library providing pointers is unloaded so the
/// pointers don't go stale.
#[hawktracer(gl_load_pointers)]
#[instrument(name = "gl::find_pointers", skip_all)]
pub unsafe fn load_pointers(
marker: MainThreadMarker,
load: impl Fn(&'static str) -> *const c_void,
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::str::FromStr;

use bxt_macros::pattern;
use bxt_patterns::Patterns;
use rust_hawktracer::*;

use crate::ffi::com_model::{mleaf_s, model_s};
use crate::ffi::command::cmd_function_s;
Expand Down Expand Up @@ -1005,7 +1004,7 @@ pub unsafe fn player_edict(marker: MainThreadMarker) -> Option<NonNull<edict_s>>
///
/// [`reset_pointers()`] must be called before hw is unloaded so the pointers don't go stale.
#[cfg(unix)]
#[hawktracer(find_pointers)]
#[instrument(name = "engine::find_pointers", skip(marker))]
unsafe fn find_pointers(marker: MainThreadMarker) {
use libc::{RTLD_NOLOAD, RTLD_NOW};
use libloading::os::unix::Library;
Expand Down Expand Up @@ -1053,7 +1052,7 @@ unsafe fn find_pointers(marker: MainThreadMarker) {
/// the pointers are reset (according to the safety section of `PointerTrait::set`).
#[allow(clippy::single_match)]
#[cfg(windows)]
#[hawktracer(find_pointers)]
#[instrument(skip(marker))]
pub unsafe fn find_pointers(marker: MainThreadMarker, base: *mut c_void, size: usize) {
use std::slice;

Expand Down Expand Up @@ -1422,7 +1421,6 @@ pub mod exported {

// This is the first function that we hook called on Linux, so do due initialization.
ensure_logging_hooks();
ensure_profiling();

#[cfg(unix)]
find_pointers(marker);
Expand Down
1 change: 1 addition & 0 deletions src/hooks/opengl32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn open_library() -> Option<libloading::Library> {
///
/// [`reset_pointers()`] must be called before opengl32.dll is unloaded so the pointers don't go
/// stale.
#[instrument(name = "opengl32::find_pointers", skip_all)]
pub unsafe fn find_pointers(marker: MainThreadMarker) {
let library = match open_library() {
Some(library) => library,
Expand Down
1 change: 1 addition & 0 deletions src/hooks/sdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn open_library() -> Option<libloading::Library> {
/// # Safety
///
/// [`reset_pointers()`] must be called before SDL is unloaded so the pointers don't go stale.
#[instrument(name = "sdl::find_pointers", skip_all)]
pub unsafe fn find_pointers(marker: MainThreadMarker) {
let library = match open_library() {
Some(library) => library,
Expand Down
7 changes: 3 additions & 4 deletions src/modules/capture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::mem;

use color_eyre::eyre::Context;
use rust_hawktracer::*;

use super::cvars::CVar;
use super::Module;
Expand Down Expand Up @@ -120,7 +119,7 @@ pub fn reset_gl_state(marker: MainThreadMarker) {
}
}

#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum SoundCaptureMode {
/// Floor time to sample boundary.
Normal,
Expand Down Expand Up @@ -227,7 +226,7 @@ pub unsafe fn capture_frame(marker: MainThreadMarker) {
return;
}

scoped_tracepoint!(_capture_frame);
let _span = info_span!("capture_frame").entered();

let (width, height) = engine::get_resolution(marker);

Expand Down Expand Up @@ -336,7 +335,7 @@ pub unsafe fn skip_paint_channels(marker: MainThreadMarker) -> bool {
matches!(*STATE.borrow_mut(marker), State::Recording(_))
}

#[hawktracer(capture_sound)]
#[instrument(skip(marker))]
pub unsafe fn capture_sound(marker: MainThreadMarker, mode: SoundCaptureMode) {
let end_time = {
let mut state = STATE.borrow_mut(marker);
Expand Down
13 changes: 6 additions & 7 deletions src/modules/capture/muxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::io::{self, Write};
use std::os::windows::process::CommandExt;
use std::process::{Child, Command, Stdio};

use rust_hawktracer::*;
use thiserror::Error;

pub struct Muxer {
Expand All @@ -20,7 +19,7 @@ pub enum MuxerInitError {
Other(#[from] io::Error),
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PixelFormat {
I420,
/// RGB24, vertically flipped (basically, output from glReadPixels).
Expand Down Expand Up @@ -97,7 +96,7 @@ fn packet<W: Write>(mut writer: W, startcode: u64, data: &[u8]) -> Result<(), io
}

impl Muxer {
#[hawktracer(muxer_new)]
#[instrument(name = "Muxer::new")]
pub fn new(
width: u64,
height: u64,
Expand Down Expand Up @@ -226,7 +225,7 @@ impl Muxer {
})
}

#[hawktracer(write_video_frame)]
#[instrument(name = "Muxer::write_video_frame", skip_all)]
pub fn write_video_frame(&mut self, data: &[u8]) -> Result<(), io::Error> {
const SYNCPOINT_STARTCODE: u64 = 0x4e4be4adeeca4569;

Expand Down Expand Up @@ -259,7 +258,7 @@ impl Muxer {
writer.write_all(&crc32(&buf).to_be_bytes()[..])?; // checksum

{
scoped_tracepoint!(_write_video_data);
let _span = info_span!("write video data").entered();
writer.write_all(data)?;
}

Expand All @@ -268,7 +267,7 @@ impl Muxer {
Ok(())
}

#[hawktracer(write_audio_frame)]
#[instrument(name = "Muxer::write_audio_frame", skip_all)]
pub fn write_audio_frame(&mut self, data: &[u8]) -> Result<(), io::Error> {
const SYNCPOINT_STARTCODE: u64 = 0x4e4be4adeeca4569;

Expand Down Expand Up @@ -308,7 +307,7 @@ impl Muxer {
}

/// Waits for the child process to exit and returns its output.
#[hawktracer(muxer_close)]
#[instrument(name = "Muxer::close", skip_all)]
pub fn close(self) -> String {
let output = self.child.wait_with_output().unwrap();
String::from_utf8_lossy(&output.stderr).into_owned()
Expand Down
5 changes: 2 additions & 3 deletions src/modules/capture/opengl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ptr::null;

use color_eyre::eyre::{self, eyre, WrapErr};
use rust_hawktracer::*;

use super::ExternalObject;
use crate::gl;
Expand Down Expand Up @@ -65,7 +64,7 @@ unsafe fn reset_gl_error(gl: &gl::Gl) {
}

impl OpenGl {
#[hawktracer(opengl_capture)]
#[instrument(name = "OpenGl::capture", skip_all)]
pub unsafe fn capture(&self) -> eyre::Result<()> {
let gl = gl::GL.borrow(self.marker);
let gl = gl.as_ref().unwrap();
Expand Down Expand Up @@ -150,7 +149,7 @@ impl OpenGl {
}
}

#[hawktracer(opengl_init)]
#[instrument(name = "OpenGl::init", skip(marker))]
pub unsafe fn init(
marker: MainThreadMarker,
width: i32,
Expand Down
23 changes: 11 additions & 12 deletions src/modules/capture/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::thread::{self, JoinHandle};

use color_eyre::eyre::{self, ensure, eyre, Context};
use crossbeam_channel::{bounded, Receiver, Sender};
use rust_hawktracer::*;

use super::muxer::{Muxer, MuxerInitError, PixelFormat};
use super::opengl::{self, OpenGl, Uuids};
Expand Down Expand Up @@ -85,7 +84,7 @@ enum ThreadToMain {
}

impl Recorder {
#[hawktracer(recorder_init)]
#[instrument(name = "Recorder::init")]
pub unsafe fn init(
width: i32,
height: i32,
Expand Down Expand Up @@ -201,7 +200,7 @@ impl Recorder {
}
}

#[hawktracer(initialize_opengl_capturing)]
#[instrument(skip_all)]
unsafe fn initialize_opengl_capturing(&mut self, marker: MainThreadMarker) -> eyre::Result<()> {
assert!(matches!(self.capture_type, CaptureType::Vulkan(_)));

Expand Down Expand Up @@ -253,7 +252,7 @@ impl Recorder {
}
}

#[hawktracer(acquire_image_if_needed)]
#[instrument(skip_all)]
unsafe fn acquire_image_if_needed(&mut self) {
assert!(matches!(self.capture_type, CaptureType::Vulkan(_)));

Expand All @@ -271,7 +270,7 @@ impl Recorder {
self.send_to_thread(MainToThread::AcquireImage);
}

#[hawktracer(record)]
#[instrument(skip(self))]
unsafe fn record(&mut self, frames: usize) -> eyre::Result<()> {
match self.capture_type {
CaptureType::Vulkan(_) => {
Expand All @@ -296,7 +295,7 @@ impl Recorder {
Ok(())
}

#[hawktracer(record_last_frame)]
#[instrument(skip_all)]
pub unsafe fn record_last_frame(&mut self) -> eyre::Result<()> {
// Push this frame as long as it takes up the most of the video frame.
// Remainder is > -0.5 at all times.
Expand Down Expand Up @@ -335,12 +334,12 @@ impl Recorder {
samples_rounded as i32
}

#[hawktracer(write_audio_frame)]
#[instrument(name = "Recorder::write_audio_frame", skip_all)]
pub fn write_audio_frame(&mut self, samples: Vec<u8>) {
self.send_to_thread(MainToThread::Audio(samples));
}

#[hawktracer(recorder_finish)]
#[instrument(name = "Recorder::finish", skip_all)]
pub fn finish(mut self) -> Option<String> {
self.send_to_thread(MainToThread::Finish);

Expand Down Expand Up @@ -423,19 +422,19 @@ fn process_message(
s.send(ThreadToMain::ExternalHandles(handles)).unwrap();
}
MainToThread::AcquireImage => {
scoped_tracepoint!(_acquire);
let _span = info_span!("acquire").entered();

unsafe { vulkan.unwrap().acquire_image() }?;

s.send(ThreadToMain::AcquiredImage).unwrap();
}
MainToThread::Record { frames } => {
scoped_tracepoint!(_record);
let _span = info_span!("record").entered();

unsafe { vulkan.unwrap().convert_colors_and_mux(muxer, frames) }?;
}
MainToThread::Mux { pixels, frames } => {
scoped_tracepoint!(_mux);
let _span = info_span!("mux").entered();

for _ in 0..frames {
muxer.write_video_frame(&pixels)?;
Expand All @@ -444,7 +443,7 @@ fn process_message(
s.send(ThreadToMain::Muxed(pixels)).unwrap();
}
MainToThread::Audio(samples) => {
scoped_tracepoint!(_audio);
let _span = info_span!("audio").entered();

muxer.write_audio_frame(&samples)?;
}
Expand Down
Loading

0 comments on commit a31c1f8

Please sign in to comment.