rhd-debugtimer 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,247 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "RHD-debugtimer"
7
+ version = "1.0.0"
8
+ dependencies = [
9
+ "once_cell",
10
+ "parking_lot",
11
+ "pyo3",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "autocfg"
16
+ version = "1.5.0"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
19
+
20
+ [[package]]
21
+ name = "bitflags"
22
+ version = "2.11.0"
23
+ source = "registry+https://github.com/rust-lang/crates.io-index"
24
+ checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
25
+
26
+ [[package]]
27
+ name = "cfg-if"
28
+ version = "1.0.4"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
31
+
32
+ [[package]]
33
+ name = "heck"
34
+ version = "0.4.1"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
37
+
38
+ [[package]]
39
+ name = "indoc"
40
+ version = "2.0.7"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
43
+ dependencies = [
44
+ "rustversion",
45
+ ]
46
+
47
+ [[package]]
48
+ name = "libc"
49
+ version = "0.2.182"
50
+ source = "registry+https://github.com/rust-lang/crates.io-index"
51
+ checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
52
+
53
+ [[package]]
54
+ name = "lock_api"
55
+ version = "0.4.14"
56
+ source = "registry+https://github.com/rust-lang/crates.io-index"
57
+ checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
58
+ dependencies = [
59
+ "scopeguard",
60
+ ]
61
+
62
+ [[package]]
63
+ name = "memoffset"
64
+ version = "0.9.1"
65
+ source = "registry+https://github.com/rust-lang/crates.io-index"
66
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
67
+ dependencies = [
68
+ "autocfg",
69
+ ]
70
+
71
+ [[package]]
72
+ name = "once_cell"
73
+ version = "1.21.3"
74
+ source = "registry+https://github.com/rust-lang/crates.io-index"
75
+ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
76
+
77
+ [[package]]
78
+ name = "parking_lot"
79
+ version = "0.12.5"
80
+ source = "registry+https://github.com/rust-lang/crates.io-index"
81
+ checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
82
+ dependencies = [
83
+ "lock_api",
84
+ "parking_lot_core",
85
+ ]
86
+
87
+ [[package]]
88
+ name = "parking_lot_core"
89
+ version = "0.9.12"
90
+ source = "registry+https://github.com/rust-lang/crates.io-index"
91
+ checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
92
+ dependencies = [
93
+ "cfg-if",
94
+ "libc",
95
+ "redox_syscall",
96
+ "smallvec",
97
+ "windows-link",
98
+ ]
99
+
100
+ [[package]]
101
+ name = "portable-atomic"
102
+ version = "1.13.1"
103
+ source = "registry+https://github.com/rust-lang/crates.io-index"
104
+ checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
105
+
106
+ [[package]]
107
+ name = "proc-macro2"
108
+ version = "1.0.106"
109
+ source = "registry+https://github.com/rust-lang/crates.io-index"
110
+ checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
111
+ dependencies = [
112
+ "unicode-ident",
113
+ ]
114
+
115
+ [[package]]
116
+ name = "pyo3"
117
+ version = "0.21.2"
118
+ source = "registry+https://github.com/rust-lang/crates.io-index"
119
+ checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8"
120
+ dependencies = [
121
+ "cfg-if",
122
+ "indoc",
123
+ "libc",
124
+ "memoffset",
125
+ "parking_lot",
126
+ "portable-atomic",
127
+ "pyo3-build-config",
128
+ "pyo3-ffi",
129
+ "pyo3-macros",
130
+ "unindent",
131
+ ]
132
+
133
+ [[package]]
134
+ name = "pyo3-build-config"
135
+ version = "0.21.2"
136
+ source = "registry+https://github.com/rust-lang/crates.io-index"
137
+ checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50"
138
+ dependencies = [
139
+ "once_cell",
140
+ "target-lexicon",
141
+ ]
142
+
143
+ [[package]]
144
+ name = "pyo3-ffi"
145
+ version = "0.21.2"
146
+ source = "registry+https://github.com/rust-lang/crates.io-index"
147
+ checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403"
148
+ dependencies = [
149
+ "libc",
150
+ "pyo3-build-config",
151
+ ]
152
+
153
+ [[package]]
154
+ name = "pyo3-macros"
155
+ version = "0.21.2"
156
+ source = "registry+https://github.com/rust-lang/crates.io-index"
157
+ checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c"
158
+ dependencies = [
159
+ "proc-macro2",
160
+ "pyo3-macros-backend",
161
+ "quote",
162
+ "syn",
163
+ ]
164
+
165
+ [[package]]
166
+ name = "pyo3-macros-backend"
167
+ version = "0.21.2"
168
+ source = "registry+https://github.com/rust-lang/crates.io-index"
169
+ checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c"
170
+ dependencies = [
171
+ "heck",
172
+ "proc-macro2",
173
+ "pyo3-build-config",
174
+ "quote",
175
+ "syn",
176
+ ]
177
+
178
+ [[package]]
179
+ name = "quote"
180
+ version = "1.0.45"
181
+ source = "registry+https://github.com/rust-lang/crates.io-index"
182
+ checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
183
+ dependencies = [
184
+ "proc-macro2",
185
+ ]
186
+
187
+ [[package]]
188
+ name = "redox_syscall"
189
+ version = "0.5.18"
190
+ source = "registry+https://github.com/rust-lang/crates.io-index"
191
+ checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
192
+ dependencies = [
193
+ "bitflags",
194
+ ]
195
+
196
+ [[package]]
197
+ name = "rustversion"
198
+ version = "1.0.22"
199
+ source = "registry+https://github.com/rust-lang/crates.io-index"
200
+ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
201
+
202
+ [[package]]
203
+ name = "scopeguard"
204
+ version = "1.2.0"
205
+ source = "registry+https://github.com/rust-lang/crates.io-index"
206
+ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
207
+
208
+ [[package]]
209
+ name = "smallvec"
210
+ version = "1.15.1"
211
+ source = "registry+https://github.com/rust-lang/crates.io-index"
212
+ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
213
+
214
+ [[package]]
215
+ name = "syn"
216
+ version = "2.0.117"
217
+ source = "registry+https://github.com/rust-lang/crates.io-index"
218
+ checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
219
+ dependencies = [
220
+ "proc-macro2",
221
+ "quote",
222
+ "unicode-ident",
223
+ ]
224
+
225
+ [[package]]
226
+ name = "target-lexicon"
227
+ version = "0.12.16"
228
+ source = "registry+https://github.com/rust-lang/crates.io-index"
229
+ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
230
+
231
+ [[package]]
232
+ name = "unicode-ident"
233
+ version = "1.0.24"
234
+ source = "registry+https://github.com/rust-lang/crates.io-index"
235
+ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
236
+
237
+ [[package]]
238
+ name = "unindent"
239
+ version = "0.2.4"
240
+ source = "registry+https://github.com/rust-lang/crates.io-index"
241
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
242
+
243
+ [[package]]
244
+ name = "windows-link"
245
+ version = "0.2.1"
246
+ source = "registry+https://github.com/rust-lang/crates.io-index"
247
+ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "RHD-debugtimer"
3
+ version = "1.0.0"
4
+ edition = "2024"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+ [lib]
8
+ name = "rhd_debugtimer"
9
+ crate-type = ["cdylib"]
10
+
11
+ [dependencies]
12
+ pyo3 = { version = "0.21", features = ["extension-module"] }
13
+ once_cell = "1.19"
14
+ parking_lot = "0.12"
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: RHD-debugtimer
3
+ Version: 1.0.0
4
+ Summary: Ultra fast Rust profiler for Python
5
+ Author: hafiy_dev
6
+ Requires-Python: >=3.8
@@ -0,0 +1,10 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.0"]
3
+ build-backend = "maturin"
4
+
5
+ [project]
6
+ name = "RHD-debugtimer"
7
+ version = "1.0.0"
8
+ description = "Ultra fast Rust profiler for Python"
9
+ authors = [{name="hafiy_dev"}]
10
+ requires-python = ">=3.8"
@@ -0,0 +1,43 @@
1
+ use pyo3::prelude::*;
2
+ use once_cell::sync::Lazy;
3
+ use parking_lot::Mutex;
4
+
5
+ mod profiler;
6
+ mod stats;
7
+
8
+ use profiler::Profiler;
9
+
10
+ static GLOBAL_PROFILER: Lazy<Mutex<Profiler>> =
11
+ Lazy::new(|| Mutex::new(Profiler::new()));
12
+
13
+ #[pyfunction]
14
+ fn record(name: String, duration: f64) {
15
+ let mut profiler = GLOBAL_PROFILER.lock();
16
+ profiler.record(name, duration);
17
+ }
18
+
19
+ #[pyfunction]
20
+ fn results() -> Vec<(String, u64, f64, f64, f64)> {
21
+ let profiler = GLOBAL_PROFILER.lock();
22
+
23
+ profiler
24
+ .data
25
+ .iter()
26
+ .map(|(name, stat)| {
27
+ (
28
+ name.clone(),
29
+ stat.calls,
30
+ stat.total_time,
31
+ stat.min_time,
32
+ stat.max_time,
33
+ )
34
+ })
35
+ .collect()
36
+ }
37
+
38
+ #[pymodule]
39
+ fn debugtimer(_py: Python, m: &PyModule) -> PyResult<()> {
40
+ m.add_function(wrap_pyfunction!(record, m)?)?;
41
+ m.add_function(wrap_pyfunction!(results, m)?)?;
42
+ Ok(())
43
+ }
@@ -0,0 +1,20 @@
1
+ use std::collections::HashMap;
2
+
3
+ use crate::stats::FunctionStats;
4
+
5
+ pub struct Profiler {
6
+ pub data: HashMap<String, FunctionStats>,
7
+ }
8
+
9
+ impl Profiler {
10
+ pub fn new() -> Self {
11
+ Self {
12
+ data: HashMap::new(),
13
+ }
14
+ }
15
+
16
+ pub fn record(&mut self, name: String, duration: f64) {
17
+ let entry = self.data.entry(name).or_insert(FunctionStats::new());
18
+ entry.update(duration);
19
+ }
20
+ }
@@ -0,0 +1,55 @@
1
+ use std::fmt;
2
+
3
+ #[derive(Clone)]
4
+ pub struct FunctionStats {
5
+ pub calls: u64,
6
+ pub total_time: f64,
7
+ pub min_time: f64,
8
+ pub max_time: f64,
9
+ }
10
+
11
+ impl FunctionStats {
12
+ pub fn new() -> Self {
13
+ Self {
14
+ calls: 0,
15
+ total_time: 0.0,
16
+ min_time: f64::MAX,
17
+ max_time: 0.0,
18
+ }
19
+ }
20
+
21
+ pub fn update(&mut self, duration: f64) {
22
+ self.calls += 1;
23
+ self.total_time += duration;
24
+
25
+ if duration < self.min_time {
26
+ self.min_time = duration;
27
+ }
28
+
29
+ if duration > self.max_time {
30
+ self.max_time = duration;
31
+ }
32
+ }
33
+
34
+ pub fn average(&self) -> f64 {
35
+ if self.calls == 0 {
36
+ 0.0
37
+ } else {
38
+ self.total_time / self.calls as f64
39
+ }
40
+ }
41
+ }
42
+
43
+ impl fmt::Display for FunctionStats {
44
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45
+ write!(
46
+ f,
47
+ "calls: {}, total: {:.6}, avg: {:.6}, min: {:.6}, max: {:.6}",
48
+ self.calls,
49
+ self.total_time,
50
+ self.average(),
51
+ self.min_time,
52
+ self.max_time
53
+ )
54
+ }
55
+ }