3
3
import argparse
4
4
from functools import partial
5
5
import pathlib
6
+ import psutil
6
7
import random
7
8
import re
9
+ import socket
8
10
import string
9
11
import sys
10
12
import time
@@ -25,6 +27,10 @@ def __exit__(self, exc_type, exc_value, exc_tb):
25
27
pass
26
28
27
29
30
+ def get_location ():
31
+ return f'{ socket .gethostname ()} ,{ psutil .Process ().cpu_num ()} '
32
+
33
+
28
34
def compute_size (size_str ):
29
35
if (match := re .match (r'\s*(\d+)\s*([a-z]+)?' , size_str , re .IGNORECASE )) is not None :
30
36
size = int (match .group (1 ))
@@ -59,7 +65,7 @@ def create_file(args):
59
65
total_time += end - start
60
66
buffer = '' .join (random .choices (string .ascii_lowercase , k = (size % buffer_size )))
61
67
file .write (buffer )
62
- return total_time
68
+ return get_location (), total_time
63
69
64
70
65
71
def read_file (args ):
@@ -70,15 +76,15 @@ def read_file(args):
70
76
while (buffer := file .read (buffer_size )):
71
77
count += len (buffer )
72
78
end = time .time ()
73
- return count , end - start
79
+ return count , get_location (), end - start
74
80
75
81
76
82
def remove_file (file_name ):
77
83
file = pathlib .Path (file_name )
78
84
start = time .time ()
79
85
file .unlink ()
80
86
end = time .time ()
81
- return end - start
87
+ return get_location (), end - start
82
88
83
89
84
90
def main ():
@@ -130,8 +136,8 @@ def main():
130
136
if options .verbose :
131
137
print (f'creating { len (files )} files' , file = sys .stderr )
132
138
with executor_cls () as executor :
133
- times = executor .map (create_file , ((file_name , file_size , buffer_size ) for file_name in files ))
134
- print ('\n ' .join (f'write,{ time } ,{ file_size / time } ' for time in times ))
139
+ results = executor .map (create_file , ((file_name , file_size , buffer_size ) for file_name in files ))
140
+ print ('\n ' .join (f'write,{ location } , { time } ,{ file_size / time } ' for location , time in results ))
135
141
136
142
# if requested, shuffle files so that they are handled by a different thread/process
137
143
if options .shuffle :
@@ -142,8 +148,8 @@ def main():
142
148
print (f'reading { len (files )} files' , file = sys .stderr )
143
149
with executor_cls () as executor :
144
150
results = executor .map (read_file , ((file_name , buffer_size ) for file_name in files ))
145
- for size , time in results :
146
- print (f'read,{ time } ,{ file_size / time } ' )
151
+ for size , location , time in results :
152
+ print (f'read,{ location } , { time } ,{ file_size / time } ' )
147
153
if size != file_size :
148
154
print (f"problem for file '{ file_name } ': { size } bytes read, { file_size } expected" ,
149
155
file = sys .stderr )
@@ -157,8 +163,8 @@ def main():
157
163
if options .verbose :
158
164
print (f'reading { len (files )} files' , file = sys .stderr )
159
165
with executor_cls () as executor :
160
- times = executor .map (remove_file , files )
161
- print ('\n ' .join (f'unlink,{ time } ' for time in times ))
166
+ results = executor .map (remove_file , files )
167
+ print ('\n ' .join (f'unlink,{ location } , { time } ' for localtion , time in results ))
162
168
163
169
if options .verbose :
164
170
print ('completed succesfully' , file = sys .stderr )
0 commit comments