Xuanwo commented on code in PR #4053:
URL: https://github.com/apache/opendal/pull/4053#discussion_r1462617357


##########
core/src/layers/dtrace.rs:
##########
@@ -0,0 +1,227 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use async_trait::async_trait;
+use std::fmt::Debug;
+use std::fmt::Formatter;
+
+use crate::raw::*;
+use crate::*;
+use std::ffi::CString;
+
+/// Support User Statically-Defined Tracing(aka USDT) on Linux
+///
+/// This layer is an experimental feature, it will be enabled by `features = 
["layers-dtrace"]` in Cargo.toml.
+///
+/// Example:
+/// ```
+///
+/// use anyhow::Result;
+/// use opendal::services::Fs;
+/// use opendal::Operator;
+/// use opendal::layers::DTraceLayer;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = Fs::default();
+///
+///     builder.root("/tmp");
+///
+///     // `Accessor` provides the low level APIs, we will use `Operator` 
normally.
+///     let op: Operator = 
Operator::new(builder)?.layer(DTraceLayer{}).finish();

Review Comment:
   We don't encourage users to init layers in this way. Please provide a 
`DtraceLayer::new()` or `DtraceLayer::default()` API.



##########
core/src/layers/mod.rs:
##########
@@ -101,3 +101,9 @@ pub use self::await_tree::AwaitTreeLayer;
 mod async_backtrace;
 #[cfg(feature = "layers-async-backtrace")]
 pub use self::async_backtrace::AsyncBacktraceLayer;
+
+#[cfg(all(target_os = "linux", feature = "layers-dtrace"))]
+mod dtrace;
+

Review Comment:
   remove this line.



##########
core/src/layers/dtrace.rs:
##########
@@ -0,0 +1,227 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use async_trait::async_trait;
+use std::fmt::Debug;
+use std::fmt::Formatter;
+
+use crate::raw::*;
+use crate::*;
+use std::ffi::CString;
+
+/// Support User Statically-Defined Tracing(aka USDT) on Linux
+///
+/// This layer is an experimental feature, it will be enabled by `features = 
["layers-dtrace"]` in Cargo.toml.
+///
+/// Example:
+/// ```
+///
+/// use anyhow::Result;
+/// use opendal::services::Fs;
+/// use opendal::Operator;
+/// use opendal::layers::DTraceLayer;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = Fs::default();
+///
+///     builder.root("/tmp");
+///
+///     // `Accessor` provides the low level APIs, we will use `Operator` 
normally.
+///     let op: Operator = 
Operator::new(builder)?.layer(DTraceLayer{}).finish();
+///     
+///     let path="/tmp/test.txt";
+///     for _ in 1..100000{
+///         let bs = vec![0; 64 * 1024 * 1024];
+///         op.write(path, bs).await?;
+///         op.read(path).await?;
+///     }
+///     Ok(())
+/// }
+/// ```
+///
+/// Then you can use `readelf -n target/debug/examples/dtrace` to see the 
probes:
+///
+/// ```text
+/// Displaying notes found in: .note.stapsdt
+///   Owner                Data size        Description
+///   stapsdt              0x00000039       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: create_dir_start
+///     Location: 0x00000000000f8f05, Base: 0x0000000000000000, Semaphore: 
0x00000000003649f8
+///     Arguments: -8@%rax
+///   stapsdt              0x00000037       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: create_dir_end
+///     Location: 0x00000000000f9284, Base: 0x0000000000000000, Semaphore: 
0x00000000003649fa
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003c       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: blocking_list_start
+///     Location: 0x00000000000f9487, Base: 0x0000000000000000, Semaphore: 
0x0000000000364a28
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003a       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: blocking_list_end
+///     Location: 0x00000000000f9546, Base: 0x0000000000000000, Semaphore: 
0x0000000000364a2a
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003c       NT_STAPSDT (SystemTap probe 
descriptors)
+/// ```
+#[derive(Default, Debug, Clone)]
+pub struct DTraceLayer {}
+
+impl<A: Accessor> Layer<A> for DTraceLayer {
+    type LayeredAccessor = DTraceAccessor<A>;
+    fn layer(&self, inner: A) -> Self::LayeredAccessor {
+        DTraceAccessor { inner }
+    }
+}
+
+#[derive(Clone)]
+pub struct DTraceAccessor<A: Accessor> {
+    inner: A,
+}
+
+impl<A: Accessor> Debug for DTraceAccessor<A> {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("DTraceAccessor")
+            .field("inner", &self.inner)
+            .finish_non_exhaustive()
+    }
+}
+
+#[async_trait]
+impl<A: Accessor> LayeredAccessor for DTraceAccessor<A> {
+    type Inner = A;
+    type Reader = A::Reader;
+    type BlockingReader = A::BlockingReader;
+    type Writer = A::Writer;
+    type BlockingWriter = A::BlockingWriter;
+    type Lister = A::Lister;
+    type BlockingLister = A::BlockingLister;
+    fn inner(&self) -> &Self::Inner {
+        &self.inner
+    }
+
+    async fn create_dir(&self, path: &str, args: OpCreateDir) -> 
Result<RpCreateDir> {
+        let c_path = CString::new(path).unwrap();
+        probe::probe_lazy!(opendal, create_dir_start, c_path.as_ptr());
+        let create_res = self.inner.create_dir(path, args).await;

Review Comment:
   We can use `res` instead of `create_res` to avoid extra maintainance.



##########
core/src/layers/dtrace.rs:
##########
@@ -0,0 +1,227 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use async_trait::async_trait;
+use std::fmt::Debug;
+use std::fmt::Formatter;
+
+use crate::raw::*;
+use crate::*;
+use std::ffi::CString;
+
+/// Support User Statically-Defined Tracing(aka USDT) on Linux
+///
+/// This layer is an experimental feature, it will be enabled by `features = 
["layers-dtrace"]` in Cargo.toml.
+///
+/// Example:
+/// ```
+///
+/// use anyhow::Result;
+/// use opendal::services::Fs;
+/// use opendal::Operator;
+/// use opendal::layers::DTraceLayer;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = Fs::default();
+///
+///     builder.root("/tmp");
+///
+///     // `Accessor` provides the low level APIs, we will use `Operator` 
normally.
+///     let op: Operator = 
Operator::new(builder)?.layer(DTraceLayer{}).finish();
+///     
+///     let path="/tmp/test.txt";
+///     for _ in 1..100000{
+///         let bs = vec![0; 64 * 1024 * 1024];
+///         op.write(path, bs).await?;
+///         op.read(path).await?;
+///     }
+///     Ok(())
+/// }
+/// ```
+///
+/// Then you can use `readelf -n target/debug/examples/dtrace` to see the 
probes:
+///
+/// ```text
+/// Displaying notes found in: .note.stapsdt
+///   Owner                Data size        Description
+///   stapsdt              0x00000039       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: create_dir_start
+///     Location: 0x00000000000f8f05, Base: 0x0000000000000000, Semaphore: 
0x00000000003649f8
+///     Arguments: -8@%rax
+///   stapsdt              0x00000037       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: create_dir_end
+///     Location: 0x00000000000f9284, Base: 0x0000000000000000, Semaphore: 
0x00000000003649fa
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003c       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: blocking_list_start
+///     Location: 0x00000000000f9487, Base: 0x0000000000000000, Semaphore: 
0x0000000000364a28
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003a       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: blocking_list_end
+///     Location: 0x00000000000f9546, Base: 0x0000000000000000, Semaphore: 
0x0000000000364a2a
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003c       NT_STAPSDT (SystemTap probe 
descriptors)
+/// ```
+#[derive(Default, Debug, Clone)]
+pub struct DTraceLayer {}

Review Comment:
   Please use `DtraceLayer` instead to keep the same naming style.



##########
core/src/layers/dtrace.rs:
##########
@@ -0,0 +1,227 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use async_trait::async_trait;
+use std::fmt::Debug;
+use std::fmt::Formatter;
+
+use crate::raw::*;
+use crate::*;
+use std::ffi::CString;
+
+/// Support User Statically-Defined Tracing(aka USDT) on Linux
+///
+/// This layer is an experimental feature, it will be enabled by `features = 
["layers-dtrace"]` in Cargo.toml.
+///
+/// Example:
+/// ```
+///
+/// use anyhow::Result;
+/// use opendal::services::Fs;
+/// use opendal::Operator;
+/// use opendal::layers::DTraceLayer;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = Fs::default();
+///
+///     builder.root("/tmp");
+///
+///     // `Accessor` provides the low level APIs, we will use `Operator` 
normally.
+///     let op: Operator = 
Operator::new(builder)?.layer(DTraceLayer{}).finish();
+///     
+///     let path="/tmp/test.txt";
+///     for _ in 1..100000{
+///         let bs = vec![0; 64 * 1024 * 1024];
+///         op.write(path, bs).await?;
+///         op.read(path).await?;
+///     }
+///     Ok(())
+/// }
+/// ```
+///
+/// Then you can use `readelf -n target/debug/examples/dtrace` to see the 
probes:
+///
+/// ```text
+/// Displaying notes found in: .note.stapsdt
+///   Owner                Data size        Description
+///   stapsdt              0x00000039       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: create_dir_start
+///     Location: 0x00000000000f8f05, Base: 0x0000000000000000, Semaphore: 
0x00000000003649f8
+///     Arguments: -8@%rax
+///   stapsdt              0x00000037       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: create_dir_end
+///     Location: 0x00000000000f9284, Base: 0x0000000000000000, Semaphore: 
0x00000000003649fa
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003c       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: blocking_list_start
+///     Location: 0x00000000000f9487, Base: 0x0000000000000000, Semaphore: 
0x0000000000364a28
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003a       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: blocking_list_end
+///     Location: 0x00000000000f9546, Base: 0x0000000000000000, Semaphore: 
0x0000000000364a2a
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003c       NT_STAPSDT (SystemTap probe 
descriptors)
+/// ```
+#[derive(Default, Debug, Clone)]
+pub struct DTraceLayer {}
+
+impl<A: Accessor> Layer<A> for DTraceLayer {
+    type LayeredAccessor = DTraceAccessor<A>;
+    fn layer(&self, inner: A) -> Self::LayeredAccessor {
+        DTraceAccessor { inner }
+    }
+}
+
+#[derive(Clone)]
+pub struct DTraceAccessor<A: Accessor> {
+    inner: A,
+}
+
+impl<A: Accessor> Debug for DTraceAccessor<A> {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("DTraceAccessor")
+            .field("inner", &self.inner)
+            .finish_non_exhaustive()
+    }
+}
+
+#[async_trait]
+impl<A: Accessor> LayeredAccessor for DTraceAccessor<A> {
+    type Inner = A;
+    type Reader = A::Reader;
+    type BlockingReader = A::BlockingReader;
+    type Writer = A::Writer;
+    type BlockingWriter = A::BlockingWriter;
+    type Lister = A::Lister;
+    type BlockingLister = A::BlockingLister;
+    fn inner(&self) -> &Self::Inner {
+        &self.inner
+    }
+
+    async fn create_dir(&self, path: &str, args: OpCreateDir) -> 
Result<RpCreateDir> {
+        let c_path = CString::new(path).unwrap();
+        probe::probe_lazy!(opendal, create_dir_start, c_path.as_ptr());
+        let create_res = self.inner.create_dir(path, args).await;
+        probe::probe_lazy!(opendal, create_dir_end, c_path.as_ptr());
+        create_res
+    }
+
+    async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
+        let c_path = CString::new(path).unwrap();
+        probe::probe_lazy!(opendal, read_start, c_path.as_ptr());
+        let read_res = self.inner.read(path, args).await;

Review Comment:
   It's better for use to provide `Reader`/`Writer`/`Lister` support. Please 
note that `read` just return a `Reader` to user, real IO doesn't happen here.



##########
core/src/layers/dtrace.rs:
##########
@@ -0,0 +1,227 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use async_trait::async_trait;
+use std::fmt::Debug;
+use std::fmt::Formatter;
+
+use crate::raw::*;
+use crate::*;
+use std::ffi::CString;
+
+/// Support User Statically-Defined Tracing(aka USDT) on Linux
+///
+/// This layer is an experimental feature, it will be enabled by `features = 
["layers-dtrace"]` in Cargo.toml.
+///
+/// Example:
+/// ```
+///
+/// use anyhow::Result;
+/// use opendal::services::Fs;
+/// use opendal::Operator;
+/// use opendal::layers::DTraceLayer;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = Fs::default();
+///
+///     builder.root("/tmp");
+///
+///     // `Accessor` provides the low level APIs, we will use `Operator` 
normally.
+///     let op: Operator = 
Operator::new(builder)?.layer(DTraceLayer{}).finish();
+///     
+///     let path="/tmp/test.txt";
+///     for _ in 1..100000{
+///         let bs = vec![0; 64 * 1024 * 1024];
+///         op.write(path, bs).await?;
+///         op.read(path).await?;
+///     }
+///     Ok(())
+/// }
+/// ```
+///
+/// Then you can use `readelf -n target/debug/examples/dtrace` to see the 
probes:
+///
+/// ```text
+/// Displaying notes found in: .note.stapsdt
+///   Owner                Data size        Description
+///   stapsdt              0x00000039       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: create_dir_start
+///     Location: 0x00000000000f8f05, Base: 0x0000000000000000, Semaphore: 
0x00000000003649f8
+///     Arguments: -8@%rax
+///   stapsdt              0x00000037       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: create_dir_end
+///     Location: 0x00000000000f9284, Base: 0x0000000000000000, Semaphore: 
0x00000000003649fa
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003c       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: blocking_list_start
+///     Location: 0x00000000000f9487, Base: 0x0000000000000000, Semaphore: 
0x0000000000364a28
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003a       NT_STAPSDT (SystemTap probe 
descriptors)
+///     Provider: opendal
+///     Name: blocking_list_end
+///     Location: 0x00000000000f9546, Base: 0x0000000000000000, Semaphore: 
0x0000000000364a2a
+///     Arguments: -8@%rax
+///   stapsdt              0x0000003c       NT_STAPSDT (SystemTap probe 
descriptors)
+/// ```
+#[derive(Default, Debug, Clone)]
+pub struct DTraceLayer {}
+
+impl<A: Accessor> Layer<A> for DTraceLayer {
+    type LayeredAccessor = DTraceAccessor<A>;
+    fn layer(&self, inner: A) -> Self::LayeredAccessor {
+        DTraceAccessor { inner }
+    }
+}
+
+#[derive(Clone)]
+pub struct DTraceAccessor<A: Accessor> {
+    inner: A,
+}
+
+impl<A: Accessor> Debug for DTraceAccessor<A> {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("DTraceAccessor")
+            .field("inner", &self.inner)
+            .finish_non_exhaustive()
+    }
+}
+
+#[async_trait]
+impl<A: Accessor> LayeredAccessor for DTraceAccessor<A> {
+    type Inner = A;
+    type Reader = A::Reader;
+    type BlockingReader = A::BlockingReader;
+    type Writer = A::Writer;
+    type BlockingWriter = A::BlockingWriter;
+    type Lister = A::Lister;
+    type BlockingLister = A::BlockingLister;
+    fn inner(&self) -> &Self::Inner {
+        &self.inner
+    }
+
+    async fn create_dir(&self, path: &str, args: OpCreateDir) -> 
Result<RpCreateDir> {
+        let c_path = CString::new(path).unwrap();
+        probe::probe_lazy!(opendal, create_dir_start, c_path.as_ptr());

Review Comment:
   Please use `probe_lazy!` directly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to