[go: nahoru, domu]

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

Add pipe uid and support more detailed log for read/write #414

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jessehui
Copy link
Contributor
@jessehui jessehui commented Apr 27, 2021

Current read/write log can't provide enough info for complicated applications. This commits improve this situation

  1. Read/write/dup/close syscalls will know the path or channel for regular file or pipe.
  2. Read/write output a part of the buffer contents
  3. Detailed log only affect debug mode

Regular file read and close:
截屏2021-04-27 下午2 33 07

Pipe file read and close:
截屏2021-04-27 下午2 33 57

Other file types could be added in the future.

@@ -201,4 +209,14 @@ impl PipeType for FileRef {
.downcast_ref::<PipeWriter>()
.ok_or_else(|| errno!(EBADF, "not a pipe writer"))
}

fn channel_uid(&self) -> Result<usize> {
let pipe_end = self.as_pipe_reader();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to get the channel, then get the channel_uid from the channel?

fn gen_uid(ring_buf: &RingBuffer<I>) -> usize {
use crate::util::random;
let mut random_buf: [u8; 8] = [0u8; 8]; // same length as usize
random::get_random(&mut random_buf).expect("failed to get random number");
Copy link
Contributor

Choose a reason for hiding this comment

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

Random does not guarantee two channels would get different id.
It maybe a good enough implementation for debug purpose. Please add a TODO here, to replace it with a more consistent implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

In case you are interested, there is an object_id crate in NGO for exact this purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tatetian Thank you for this suggestion. However, besides the uniqueness of this uid, it would be better if the developer can find all the references with this ID, which can be very helpful when we need to find the pattern of this access. So the uid should contain many digits. Maybe we can make object_id start from a big random value and then atomically increase by 1 or a small random value?

@jessehui jessehui marked this pull request as draft February 5, 2024 08:14
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

3 participants