Skip to content

Commit

Permalink
adding an automatic duration and make timedelta field names consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud committed Mar 18, 2016
1 parent df55bd5 commit d674c9b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lithoxyl/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ def _end_msg(e):
except Exception as e:
import pdb;pdb.post_mortem()


def duration_auto(e):
try:
duration = e.record.duration
if duration < 0.001:
return '%.3fus' % (duration * 1e6)
if duration < 1.0:
return '%.3fms' % (duration * 1e3)
return '%.4fs' % duration
except Exception:
import pdb;pdb.post_mortem()

# default, fmt_specs
_SF = SensibleField
BASIC_FIELDS = [_SF('logger_name', 's', lambda e: e.record.logger.name),
Expand All @@ -110,8 +122,10 @@ def _end_msg(e):
_SF('end_raw_message', 's', lambda e: e.record.end_event.raw_message),
_SF('begin_timestamp', '.14g', lambda e: e.record.begin_time),
_SF('end_timestamp', '.14g', lambda e: e.record.end_time),
_SF('duration_secs', '.3f', lambda e: e.record.duration),
_SF('duration_msecs', '.3f', lambda e: e.record.duration * 1000.0),
_SF('duration_s', '.3f', lambda e: e.record.duration),
_SF('duration_ms', '.3f', lambda e: e.record.duration * 1e3),
_SF('duration_us', '.3f', lambda e: e.record.duration * 1e6),
_SF('duration_auto', '>9s', duration_auto, quote=False),
_SF('module_name', 's', lambda e: e.callpoint.module_name),
_SF('module_path', 's', lambda e: e.callpoint.module_path),
_SF('func_name', 's', lambda e: e.callpoint.func_name, quote=False),
Expand Down Expand Up @@ -169,7 +183,7 @@ def _end_msg(e):


DELTA_FIELDS = [
_SF('import_delta', '0.6f', lambda e: e.etime - IMPORT_TIME),
_SF('import_delta_s', '0.6f', lambda e: e.etime - IMPORT_TIME),
_SF('import_delta_ms', '0.4f', lambda e: (e.etime - IMPORT_TIME) * 1000)]


Expand Down

0 comments on commit d674c9b

Please sign in to comment.