Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/log delay #421

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/radical/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def __init__(self, target):
except:
pass # exists

logging.FileHandler.__init__(self, target)
logging.FileHandler.__init__(self, target, delay=True)


# ------------------------------------------------------------------------------
Expand Down
59 changes: 34 additions & 25 deletions src/radical/utils/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,26 @@ def __init__(self, name, ns=None, path=None):

ru_def = DefaultConfig()


if not ns:
ns = name

# check if this profile is enabled via an env variable
self._enabled = ru_get_env_ns('profile', ns)

if self._enabled is None:
self._enabled = ru_def.get('profile')

if self._enabled is None:
self._enabled = 'False'
self._enabled = ru_def.get('profile', 'False')

if self._enabled.lower() in ['0', 'false', 'off']:
self._enabled = False

# don't open the file on disabled profilers
if not self._enabled:
self._handle = None
return

# profiler is enabled - set properties, sync time, open handle
self._enabled = True
self._handle = None
self._path = path
self._name = name

Expand All @@ -212,9 +210,21 @@ def __init__(self, name, ns=None, path=None):

try:
os.makedirs(self._path)

except OSError:
pass # already exists


# --------------------------------------------------------------------------
#
def _open(self):

if not self._enabled:
return

if self._handle:
return

# we set `buffering` to `1` to force line buffering. That is not idea
# performance wise - but will not do an `fsync()` after writes, so OS
# level buffering should still apply. This is supposed to shield
Expand All @@ -225,18 +235,16 @@ def __init__(self, name, ns=None, path=None):
# register for cleanup after fork
_profilers.append([self, fname])


# write header and time normalization info
if self._handle:
self._handle.write('#%s\n' % (','.join(Profiler.fields)))
self._handle.write('%.7f,%s,%s,%s,%s,%s,%s\n' %
(self.timestamp(), 'sync_abs', self._name,
ru_get_thread_name(), '', '',
'%s:%s:%s:%s:%s' % (ru_get_hostname(),
ru_get_hostip(),
self._ts_zero,
self._ts_abs,
self._ts_mode)))
self._handle.write('#%s\n' % (','.join(Profiler.fields)))
self._handle.write('%.7f,%s,%s,%s,%s,%s,%s\n' %
(self.timestamp(), 'sync_abs', self._name,
ru_get_thread_name(), '', '',
'%s:%s:%s:%s:%s' % (ru_get_hostname(),
ru_get_hostip(),
self._ts_zero,
self._ts_abs,
self._ts_mode)))


# --------------------------------------------------------------------------
Expand Down Expand Up @@ -275,11 +283,12 @@ def close(self):
if not self._enabled:
return

if self._enabled and self._handle:
if self._enabled:
self.prof('END')
self.flush()
self._handle.close()
self._handle = None
self._handle = None
self._enabled = False

except:
pass
Expand All @@ -289,11 +298,8 @@ def close(self):
#
def flush(self, verbose=False):

if not self._enabled: return
if not self._handle : return

if verbose:
self.prof('flush')
if not self._enabled:
return

# see https://docs.python.org/2/library/stdtypes.html#file.flush
self._handle.flush()
Expand All @@ -307,8 +313,11 @@ def flush(self, verbose=False):
def prof(self, event, uid=None, state=None, msg=None, ts=None, comp=None,
tid=None):

if not self._enabled: return
if not self._handle : return

if not self._enabled:
return

self._open()

if ts is None: ts = self.timestamp()
if comp is None: comp = self._name
Expand Down
Loading