forked from h2oai/h2o-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractGLRMRuntimeJavaLog.py
executable file
·136 lines (106 loc) · 4.78 KB
/
extractGLRMRuntimeJavaLog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/python
import sys
import os
import json
import subprocess
import time
import numpy as np
"""
This script is written to extract the the time (ms) taken to perform the various operations in GLRM
model iteration. You should not use this for anything else. Provide the absolute path to the data
file if it is not in the same directory as this script.
"""
# --------------------------------------------------------------------
# Main program
# --------------------------------------------------------------------
g_test_root_dir = os.path.dirname(os.path.realpath(__file__)) # directory where we are running out code from
g_initialXY = "Time taken (ms) to initializeXY with" # text of interest
g_reguarlize_Y = "Time taken (ms) to calculate regularize_y"
g_regularize_X_objective = "Time taken (ms) to calculate regularize_x and calculate"
g_updateX = "Time taken (ms) to updateX"
g_updateY = "Time taken (ms) to updateY"
g_objective = "Time taken (ms) to calculate new objective function value"
g_stepsize = "Time taken (ms) to set the step size"
g_history = "Time taken (ms) to history of run"
def extractRunInto(javaLogText):
"""
This function will extract the various operation time for GLRM model building iterations.
:param javaLogText:
:return:
"""
global g_initialXY
global g_reguarlize_Y
global g_regularize_X_objective
global g_updateX
global g_updateY
global g_objective
global g_stepsize
global g_history
if os.path.isfile(javaLogText):
run_result = dict()
run_result["total time (ms)"] = []
run_result["initialXY (ms)"] = []
run_result["regularize Y (ms)"] = []
run_result["regularize X and objective (ms)"] = []
run_result["update X (ms)"] = []
run_result["update Y (ms)"] = []
run_result["objective (ms)"] = []
run_result["step size (ms)"] = []
run_result["update history (ms)"] = []
total_run_time = -1
val = 0.0
with open(javaLogText, 'r') as thefile: # go into tempfile and grab test run info
for each_line in thefile:
temp_string = each_line.split()
if len(temp_string) > 0:
val = temp_string[-1].replace('\\','')
if g_initialXY in each_line: # start of a new file
if total_run_time > 0: # update total run time
run_result["total time (ms)"].append(total_run_time)
total_run_time = 0.0
else:
total_run_time = 0.0
run_result["initialXY (ms)"].append(float(val))
total_run_time = total_run_time+float(val)
if g_reguarlize_Y in each_line:
run_result["regularize Y (ms)"].append(float(val))
total_run_time = total_run_time+float(val)
if g_regularize_X_objective in each_line:
run_result["regularize X and objective (ms)"].append(float(val))
total_run_time = total_run_time+float(val)
if g_updateX in each_line:
run_result["update X (ms)"].append(float(val))
total_run_time = total_run_time+float(val)
if g_updateY in each_line:
run_result["update Y (ms)"].append(float(val))
total_run_time = total_run_time+float(val)
if g_objective in each_line:
run_result["objective (ms)"].append(float(val))
total_run_time = total_run_time+float(val)
if g_stepsize in each_line:
run_result["step size (ms)"].append(float(val))
total_run_time = total_run_time+float(val)
if g_history in each_line:
run_result["update history (ms)"].append(float(val))
total_run_time = total_run_time+float(val)
run_result["total time (ms)"].append(total_run_time) # save the last one
print("Run result summary: \n {0}".format(run_result))
else:
print("Cannot find your java log file. Nothing is done.\n")
def main(argv):
"""
Main program. Take user input, parse it and call other functions to execute the commands
and extract run summary and store run result in json file
@return: none
"""
global g_test_root_dir
global g_temp_filename
if len(argv) < 2:
print("invoke this script as python extractGLRMRuntimeJavaLog.py javatextlog.\n")
sys.exit(1)
else: # we may be in business
javaLogText = argv[1] # filename while java log is stored
print("your java text is {0}".format(javaLogText))
extractRunInto(javaLogText)
if __name__ == "__main__":
main(sys.argv)