Skip to content

Commit 4eb25eb

Browse files
committed
Add execution location information
1 parent 40f5eb2 commit 4eb25eb

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

source-code/mpi4py/file_trafficker.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import argparse
44
from functools import partial
55
import pathlib
6+
import psutil
67
import random
78
import re
9+
import socket
810
import string
911
import sys
1012
import time
@@ -25,6 +27,10 @@ def __exit__(self, exc_type, exc_value, exc_tb):
2527
pass
2628

2729

30+
def get_location():
31+
return f'{socket.gethostname()},{psutil.Process().cpu_num()}'
32+
33+
2834
def compute_size(size_str):
2935
if (match := re.match(r'\s*(\d+)\s*([a-z]+)?', size_str, re.IGNORECASE)) is not None:
3036
size = int(match.group(1))
@@ -59,7 +65,7 @@ def create_file(args):
5965
total_time += end - start
6066
buffer = ''.join(random.choices(string.ascii_lowercase, k=(size % buffer_size)))
6167
file.write(buffer)
62-
return total_time
68+
return get_location(), total_time
6369

6470

6571
def read_file(args):
@@ -70,15 +76,15 @@ def read_file(args):
7076
while (buffer := file.read(buffer_size)):
7177
count += len(buffer)
7278
end = time.time()
73-
return count, end - start
79+
return count, get_location(), end - start
7480

7581

7682
def remove_file(file_name):
7783
file = pathlib.Path(file_name)
7884
start = time.time()
7985
file.unlink()
8086
end = time.time()
81-
return end - start
87+
return get_location(), end - start
8288

8389

8490
def main():
@@ -130,8 +136,8 @@ def main():
130136
if options.verbose:
131137
print(f'creating {len(files)} files', file=sys.stderr)
132138
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))
135141

136142
# if requested, shuffle files so that they are handled by a different thread/process
137143
if options.shuffle:
@@ -142,8 +148,8 @@ def main():
142148
print(f'reading {len(files)} files', file=sys.stderr)
143149
with executor_cls() as executor:
144150
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}')
147153
if size != file_size:
148154
print(f"problem for file '{file_name}': {size} bytes read, {file_size} expected",
149155
file=sys.stderr)
@@ -157,8 +163,8 @@ def main():
157163
if options.verbose:
158164
print(f'reading {len(files)} files', file=sys.stderr)
159165
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))
162168

163169
if options.verbose:
164170
print('completed succesfully', file=sys.stderr)

0 commit comments

Comments
 (0)