Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qim3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Commits
b11a08b5
Commit
b11a08b5
authored
1 year ago
by
s212246
Committed by
fima
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Disk speed
parent
5fe14216
No related branches found
No related tags found
1 merge request
!84
Disk speed
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
qim3d/utils/system.py
+89
-0
89 additions, 0 deletions
qim3d/utils/system.py
with
89 additions
and
0 deletions
qim3d/utils/system.py
+
89
−
0
View file @
b11a08b5
"""
Provides tools for obtaining information about the system.
"""
import
os
import
time
import
psutil
from
qim3d.utils.internal_tools
import
sizeof
from
qim3d.io.logger
import
log
import
numpy
as
np
class
Memory
:
...
...
@@ -32,3 +35,89 @@ class Memory:
sizeof
(
self
.
free
),
round
(
self
.
free_pct
,
1
),
)
def
_test_disk_speed
(
file_size_bytes
=
1024
,
ntimes
=
10
):
'''
Test the write and read speed of the disk by writing a file of a given size
and then reading it back.
Args:
file_size_bytes (int): Size of the file to write in bytes
Returns:
write_speed (float): Write speed in GB/s
read_speed (float): Read speed in GB/s
Example:
```python
import qim3d
file_size = 1024 * 1024 * 5000 # 5 GB
write_speed, read_speed = qim3d.utils.system.test_disk_speed(file_size)
print(f
"
Write speed: {write_speed:.2f} GB/s
"
)
print(f
"
Read speed: {read_speed:.2f} GB/s
"
)
```
'''
write_speeds
=
[]
read_speeds
=
[]
for
_
in
range
(
ntimes
):
# Generate random data for the file
data
=
os
.
urandom
(
file_size_bytes
)
# Write data to a temporary file
with
open
(
'
temp_file.bin
'
,
'
wb
'
)
as
f
:
start_write
=
time
.
time
()
f
.
write
(
data
)
end_write
=
time
.
time
()
# Read data from the temporary file
with
open
(
'
temp_file.bin
'
,
'
rb
'
)
as
f
:
start_read
=
time
.
time
()
f
.
read
()
end_read
=
time
.
time
()
# Calculate read and write speed (GB/s)
write_speed
=
file_size_bytes
/
(
end_write
-
start_write
)
/
(
1024
**
3
)
read_speed
=
file_size_bytes
/
(
end_read
-
start_read
)
/
(
1024
**
3
)
write_speeds
.
append
(
write_speed
)
read_speeds
.
append
(
read_speed
)
# Clean up temporary file
os
.
remove
(
'
temp_file.bin
'
)
avg_write_speed
=
np
.
mean
(
write_speeds
)
write_speed_std
=
np
.
std
(
write_speeds
)
avg_read_speed
=
np
.
mean
(
read_speeds
)
read_speed_std
=
np
.
std
(
read_speeds
)
return
avg_write_speed
,
write_speed_std
,
avg_read_speed
,
read_speed_std
def
disk_report
(
file_size
=
1024
*
1024
*
100
,
ntimes
=
10
):
'''
Report the average write and read speed of the disk.
Args:
file_size (int): Size of the file to write in bytes
Example:
```python
import qim3d
qim3d.io.logger.level(
"
info
"
)
qim3d.utils.system.disk_report()
```
'''
# Test disk speed
avg_write_speed
,
write_speed_std
,
avg_read_speed
,
read_speed_std
=
_test_disk_speed
(
file_size_bytes
=
file_size
,
ntimes
=
ntimes
)
# Print disk information
log
.
info
(
"
Disk:
\n
• Write speed..: %.2f GB/s (± %.2f GB/s)
\n
• Read speed...: %.2f GB/s (± %.2f GB/s)
"
,
avg_write_speed
,
write_speed_std
,
avg_read_speed
,
read_speed_std
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment