mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
#487 added microsecond support to format_timestamp and used in FlowDetailView. Still WIP.
This commit is contained in:
parent
8008a4336d
commit
91e5a4a4b5
@ -40,8 +40,8 @@ class FlowDetailsView(urwid.ListBox):
|
||||
sc = self.flow.server_conn
|
||||
parts = [
|
||||
["Address", "%s:%s" % sc.address()],
|
||||
["Start time", utils.format_timestamp(sc.timestamp_start)],
|
||||
["End time", utils.format_timestamp(sc.timestamp_end) if sc.timestamp_end else "active"],
|
||||
["Start time", utils.format_timestamp(sc.timestamp_start, True)],
|
||||
["End time", utils.format_timestamp(sc.timestamp_end, True) if sc.timestamp_end else "active"],
|
||||
]
|
||||
text.extend(common.format_keyvals(parts, key="key", val="text", indent=4))
|
||||
|
||||
@ -84,10 +84,10 @@ class FlowDetailsView(urwid.ListBox):
|
||||
cc = self.flow.client_conn
|
||||
parts = [
|
||||
["Address", "%s:%s" % cc.address()],
|
||||
["Start time", utils.format_timestamp(cc.timestamp_start)],
|
||||
["Start time", utils.format_timestamp(cc.timestamp_start, True)],
|
||||
# ["Requests", "%s"%cc.requestcount],
|
||||
["End time", utils.format_timestamp(cc.timestamp_end) if cc.timestamp_end else "active"],
|
||||
["End time", utils.format_timestamp(cc.timestamp_end, True) if cc.timestamp_end else "active"],
|
||||
]
|
||||
text.extend(common.format_keyvals(parts, key="key", val="text", indent=4))
|
||||
|
||||
|
||||
return text
|
||||
|
@ -10,11 +10,20 @@ def timestamp():
|
||||
return time.time()
|
||||
|
||||
|
||||
def format_timestamp(s):
|
||||
s = time.localtime(s)
|
||||
d = datetime.datetime.fromtimestamp(time.mktime(s))
|
||||
return d.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
def format_timestamp(s, include_fractions = False):
|
||||
if type(s) is not float:
|
||||
s = time.localtime(s)
|
||||
d = datetime.datetime.fromtimestamp(time.mktime(s))
|
||||
else:
|
||||
# s is a timestamp(float) can be converted to a datetime without lossing microsecs
|
||||
d = datetime.datetime.fromtimestamp(s)
|
||||
if not include_fractions:
|
||||
format = "%Y-%m-%d %H:%M:%S"
|
||||
else:
|
||||
# this will show 3 miliseconds digits (but will truncate and not round the 4th significant digit
|
||||
# so 600999 microseconds will be 600ms and not 601ms)
|
||||
format = "%Y-%m-%d %H:%M:%S."+str(d.microsecond/1000)
|
||||
return d.strftime(format)
|
||||
|
||||
def isBin(s):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user