15
15
from lib .utils import safe_makedirs
16
16
from lib .utils import print_tail_n
17
17
from lib .utils import print_unidiff
18
+ from lib .utils import get_mem_stat_rss
18
19
19
20
20
21
class BaseWatcher (object ):
@@ -126,6 +127,7 @@ def save_artifacts(self):
126
127
class LogOutputWatcher (BaseWatcher ):
127
128
def __init__ (self ):
128
129
self .fds = dict ()
130
+ self .fds_stat = dict ()
129
131
self .logdir = os .path .join (Options ().args .vardir , 'log' )
130
132
try :
131
133
os .makedirs (self .logdir )
@@ -137,14 +139,26 @@ def get_logfile(self, worker_name):
137
139
filepath = os .path .join (self .logdir , filename )
138
140
return os .path .realpath (filepath )
139
141
142
+ def get_statfile (self , worker_name ):
143
+ filename = '%s.mem_stat.log' % worker_name
144
+ filepath = os .path .join (self .logdir , filename )
145
+ return os .path .realpath (filepath )
146
+
140
147
def process_result (self , obj ):
141
148
if isinstance (obj , WorkerDone ):
142
149
self .fds [obj .worker_id ].close ()
143
150
del self .fds [obj .worker_id ]
151
+ self .fds_stat [obj .worker_id ].close ()
152
+ del self .fds_stat [obj .worker_id ]
144
153
145
154
if not isinstance (obj , WorkerOutput ):
146
155
return
147
156
157
+ if obj .worker_id not in self .fds_stat .keys ():
158
+ filepath = self .get_statfile (obj .worker_name )
159
+ self .fds_stat [obj .worker_id ] = open (filepath , 'w' )
160
+ fd_stat = self .fds_stat [obj .worker_id ]
161
+
148
162
if obj .worker_id not in self .fds .keys ():
149
163
filepath = self .get_logfile (obj .worker_name )
150
164
self .fds [obj .worker_id ] = open (filepath , 'w' )
@@ -169,6 +183,9 @@ def process_result(self, obj):
169
183
170
184
fd .write (output )
171
185
fd .flush ()
186
+ if (Options ().args .collect_statistics ):
187
+ fd_stat .write (get_mem_stat_rss ())
188
+ fd_stat .flush ()
172
189
173
190
def __del__ (self ):
174
191
for fd in self .fds .values ():
0 commit comments