I'm trying to correlate the timing information obtain from a java job and linux performance monitoring tool perf
(specifically perf stat
).
The timing information from java is obtained using
String tstamp0 = String.valueOf(System.currentTimeMillis());
(This is essentially time in milliseconds from epoch)
whereas perf
gives the time the process has began and the subsequent recording only show the time elapsed.
What I would like to do is, convert the timing information obtained from the perf stat
to milliseconds, and here is where I'm failing. I'm approaching this problem in Python
.
This piece of code is giving me the timing information from perf
tailit = "head -n 1 " + dataset_path
process = subprocess.Popen(tailit, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
date_time = out.split("\n")[0].split(" ")[4:]
date = date_time[3] + "-" + date_time[0] + "-" + date_time[1]
time = date_time[2]
#TIMESTAMP
INIT_TIME = datetime.datetime.strptime(date + ' ' + time, "%Y-%B-%d %H:%M:%S") + datetime.timedelta(seconds=0.01)
#df is pandas data frame
df['STAMPME'] = df['TCOUNT'].apply(lambda x: foobar(datetime.timedelta(seconds=x) + INIT_TIME))
here foobar is the following to convert a string to timestamp in milliseconds, but it doesn't make sense.
def foobar(INIT_TIME):
d = datetime.datetime.strptime(str(INIT_TIME), "%Y-%m-%d %H:%M:%S.%f").strftime('%s')
d_in_ms = int(d)*1000
return (d_in_ms)
Any help will be appreciated.
EDIT: Prior questions were not addressing the problem of correlating the java timestamp (currentTimeMillis())
to the datetime with milliseconds.
For instance: with the function foobar
:
with INIT_TIME set as 2017-05-11 10:56:54.203
, the return value is 1494493014000
when it instead should be 1494500214203