Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate platform implementation #150

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Jardynq
Copy link

@Jardynq Jardynq commented Jul 23, 2022

Separated platform specific implementation into separate files.
This is needed for windows support.
Though the windows implementation is currently blank.

It compiles and runs on windows and linux, but I haven't tested macos.

@YangKeao
Copy link
Member

Good! Please fix the CI and sign-off. (You could sign off a commit through git commit -s, or add a sign-off for previous commit with git commit -s --amend)

This is needed for windows support.
Though the windows implementation is currently blank.

It compiles and runs on windows and linux, but I haven't tested macos.

Signed-off-by: Christian Jordan <svorre2304@gmail.com>
Signed-off-by: Christian Jordan <svorre2304@gmail.com>
they were moved into nix_impl/profiler in previous commit

Signed-off-by: Christian Jordan <svorre2304@gmail.com>
Signed-off-by: Christian Jordan <svorre2304@gmail.com>
To make clippy happy
the .unwrap on write! shouldn't fail

Signed-off-by: Christian Jordan <svorre2304@gmail.com>
Signed-off-by: Christian Jordan <svorre2304@gmail.com>
Makes clippy happy

Signed-off-by: Christian Jordan <svorre2304@gmail.com>
use crate::profiler::PROFILER;
use crate::{MAX_DEPTH, MAX_THREAD_NAME};

pub fn register() -> Result<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about impl register in a trait? See /src/backtrace/mod.rs: trait Trace. We'll need to tell the developers which functions are needed to add a new Profiler (for different platform, or implementation)

src/report.rs Outdated
@@ -6,8 +6,8 @@ use std::fmt::{Debug, Formatter};
use parking_lot::RwLock;

use crate::frames::{Frames, UnresolvedFrames};
use crate::platform::timer::ReportTiming;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, add a trait for ReportTiming, to tell the developers that it should implement Clone, and has a .get_frequency(), .get_duration() and .get_start_time() 🤔 .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the same for validate.

@YangKeao
Copy link
Member

Thanks for your contribution again. You've done a really good job 🍻 . I was also thinking about adding more sampling methods (like add sampling methods based on perf_event_open for Linux), and this PR also helps it a lot ❤️ .

+ moved write_thread_name_fallback into profiler, since it's platform agnostic

Signed-off-by: Christian Jordan <svorre2304@gmail.com>
Signed-off-by: Christian Jordan <svorre2304@gmail.com>
@Jardynq
Copy link
Author

Jardynq commented Jul 26, 2022

I'm not sure what to do with ReportTiming since it currently just stores some info. I've made a trait for Timer instead that has a start and stop.
I have simply created a trait for each "thing" that makes sense should be implemented per platform. Then each platform module impl this onto Profiler, Timer, etc.
To see the basic idea for the traits look at the different files under windows_impl/

let me know if anything should change.

Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I'll help you to test (and do some minor modification if I could) on freebsd in a few days to solve #151 .

@sticnarf Could you help me to test on macos?

After testing, I'd approve this PR 😸

@sticnarf
Copy link
Contributor

I run the unit tests and examples on macos aarch64. Everything works fine as usual under both the dwarf and fp modes.

There are some unimportant warnings about unused functions in tests. I can fix them for you later.

criterion = {version = "0.3", optional = true}
criterion = { version = "0.3", optional = true }

[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
Copy link

@maksymsur maksymsur Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's better to use more generic and inclusive template unless some other UNIX targets but tested linux and macos may fail

[target.'cfg(target_family = "unix")'.dependencies]

Rest of the code looks good

NixError(#[from] nix::Error),
OsError(i32),

#[cfg(any(target_os = "linux", target_os = "macos"))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[target.'cfg(target_family = "unix")'.dependencies]

@@ -0,0 +1,49 @@
#[cfg(any(target_os = "linux", target_os = "macos"))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[target.'cfg(target_family = "unix")'.dependencies]

pub use backtrace_rs::Trace as TraceImpl;
}

#[cfg(any(target_os = "linux", target_os = "macos"))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[target.'cfg(target_family = "unix")'.dependencies]

@maksymsur
Copy link

maksymsur commented Jul 27, 2022

I also tested

pprof = { git = "https://github.com/Jardynq/pprof-rs", branch = "seperate-platform-impl", features = ["flamegraph"] }

as a dependency with our project and it compiles just fine. The target was Windows.

Didn't have time to actually generate graph, but think it shall be fine as well. Will try tomorrow.

@maksymsur
Copy link

maksymsur commented Jul 28, 2022

Ah... actually flamegraphs functionality is still unimplemented on win :)
Any plans on when may it appear?

@Jardynq
Copy link
Author

Jardynq commented Jul 28, 2022

@maksymsur
I have been working on a simple implementation for windows.
You can try it with:

pprof = { git = "https://github.com/Jardynq/pprof-rs/", branch = "windows-support", features = [
	"flamegraph",
] }

Though it's probably going to be a while before an actual release with windows support.
If you get a stack overflow while building a report, then try running in release or switching to a stable toolchain.
Related issue: rust-lang/rust#99693

@dveeden
Copy link

dveeden commented Aug 31, 2022

Hi @maksymsur, @Jardynq is this now pending on Windows support for flamegraph? Would it be possible to move this along before that's fully resolved to get a fix for #151 ?

@dveeden
Copy link

dveeden commented Jan 5, 2023

Hi @maksymsur, @Jardynq, is there anything I can do to help this move along?

@AntoniosBarotsis
Copy link

I would also be interested in helping if someone could explain me the basics :)

@maksymsur
Copy link

maksymsur commented Jan 19, 2023

Hi @dveeden @AntoniosBarotsis sorry for late reply!
I think @YangKeao & @Jardynq are more appropriate persons to follow up with this issue.
Personally me shifted to a Linux distro while working on my project as windows blank implementation wasn't smth I could consume. But it was enough to pass all tests without errors at least.

@dveeden
Copy link

dveeden commented Jun 27, 2023

Hi @YangKeao, @Jardynq any updates on this? Anything I can do to help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants