MallTimes.py 6.12 KB
Newer Older
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import sys
import glob
import numpy as np
import pandas as pd
from enum import Enum

class G_enum(Enum):
    TOTAL_RESIZES = 0
    TOTAL_GROUPS = 1
    SDR = 2
    ADR = 3
    DR = 4
    RED_METHOD = 5
    RED_STRATEGY = 6
    SPAWN_METHOD = 7
    SPAWN_STRATEGY = 8
    GROUPS = 9
    ITERS = 10
    T_SPAWN = 11
    T_SR = 12
    T_AR = 13
    T_MALLEABILITY = 14
    T_TOTAL = 15
    #Malleability specific
    NP = 0
    NC = 1


columnsG = ["Total_Resizes", "Total_Groups", "SDR", "ADR", "DR", "Redistribution_Method", \
            "Redistribution_Strategy", "Spawn_Method", "Spawn_Strategy", "Groups", \
            "Iters", "T_spawn", "T_SR", "T_AR", "T_Malleability", "T_total"] #16

#-----------------------------------------------
# Obtains the value of a given index in a splited line
# and returns it as a float values if possible, string otherwise
def get_value(line, index, separator=True):
  if separator:
    value = line[index].split('=')[1].split(',')[0]
  else:
    value = line[index]

  try:
    value = float(value)
    if value.is_integer():
      value = int(value)
  except ValueError:
    return value
  return value

#-----------------------------------------------
def record_config_line(lineS, aux_data):
  aux_data[0] = int(lineS[1].split("=")[1])
  aux_data[1] = int(lineS[2].split("=")[1])
  aux_data[2] = int(lineS[3].split("=")[1])
  aux_data[3] = int(lineS[4])
  aux_data[4] = int(lineS[5])
  aux_data[5] = int(lineS[7].split("=")[1])
#                           SM RM SS
#          0        1         2 3 4             5
#Test numP=160 numC=120 Meths=0 0 1 -- Is_synch=1 qty=5
#  0      1        2         3  4 5 6  7          8


#-----------------------------------------------
# Obtains the general parameters of an execution and
# stores them for creating a global dataframe
def record_new_line(lineS, dataG_it, data_aux):
  offset_line = 2
  sdr = 3947883504
  adr = sdr * 0.966

  dataG_it[G_enum.TOTAL_RESIZES.value] = 1
  dataG_it[G_enum.TOTAL_GROUPS.value] = dataG_it[G_enum.TOTAL_RESIZES.value]+1

  # Init lists for each column
  array_groups = [G_enum.GROUPS.value, G_enum.ITERS.value, G_enum.RED_METHOD.value, \
          G_enum.RED_STRATEGY.value, G_enum.SPAWN_METHOD.value, G_enum.SPAWN_STRATEGY.value]

  array_resizes = [ G_enum.T_SPAWN.value, G_enum.T_SR.value, G_enum.T_AR.value, G_enum.T_MALLEABILITY.value]

  for index in array_groups:
    dataG_it[index] = [None]*dataG_it[G_enum.TOTAL_GROUPS.value]
  for index in array_resizes:
    dataG_it[index] = [None]*dataG_it[G_enum.TOTAL_RESIZES.value]

  dataG_it[G_enum.GROUPS.value][0] = data_aux[0]
  dataG_it[G_enum.GROUPS.value][1] = data_aux[1] 
  dataG_it[G_enum.ITERS.value][0] = dataG_it[G_enum.ITERS.value][1] = 500

  dataG_it[G_enum.SPAWN_METHOD.value][0] = dataG_it[G_enum.RED_METHOD.value][0] = 0
  dataG_it[G_enum.SPAWN_METHOD.value][1] = data_aux[2]
  dataG_it[G_enum.RED_METHOD.value][1] = data_aux[3]
  dataG_it[G_enum.SPAWN_STRATEGY.value][0] = dataG_it[G_enum.RED_STRATEGY.value][0] = 1
  dataG_it[G_enum.SPAWN_STRATEGY.value][1] = dataG_it[G_enum.RED_STRATEGY.value][1] = data_aux[4]

  dataG_it[G_enum.SDR.value] = sdr
  dataG_it[G_enum.ADR.value] = 0
  if data_aux[5] == 0: #Is asynch send
    dataG_it[G_enum.ADR.value] = adr
    dataG_it[G_enum.SDR.value] -= adr
  dataG_it[G_enum.DR.value] = dataG_it[G_enum.SDR.value] + dataG_it[G_enum.ADR.value]

#-----------------------------------------------
def record_time_line(lineS, dataG_it):
  T_names = ["T_spawn:", "T_SR:", "T_AR:", "T_Malleability:", "T_total:"]
  T_values = [G_enum.T_SPAWN.value, G_enum.T_SR.value, G_enum.T_AR.value, G_enum.T_MALLEABILITY.value, G_enum.T_TOTAL.value]
  if not (lineS[0] in T_names): # Execute only if line represents a Time
      return

  index = T_names.index(lineS[0])
  index = T_values[index]
  offset_lines = 1

  len_index = 1
  if dataG_it[index] != None:
    len_index = len(dataG_it[index])
    for i in range(len_index):
      dataG_it[index][i] = get_value(lineS, i+offset_lines, False)
  else:
      dataG_it[index] = get_value(lineS, offset_lines, False)

#-----------------------------------------------
def read_global_file(f, dataG, it):
  runs_in_file=0
  aux_data = [0,0,0,0,0,0]
  for line in f: 
    lineS = line.split()

    if len(lineS) > 0:
      if lineS[0] == "Test": # CONFIG LINE
        record_config_line(lineS, aux_data)
      elif lineS[0] == "Start":
        it += 1
        runs_in_file += 1
        group = 0

        dataG.append([None]*len(columnsG))
        record_new_line(lineS, dataG[it], aux_data)
      elif it>-1:
        record_time_line(lineS, dataG[it])

  return it,runs_in_file

#-----------------------------------------------
def convert_to_tuples(dfG):
  array_list_items = [G_enum.GROUPS.value, G_enum.ITERS.value, \
          G_enum.RED_METHOD.value, G_enum.RED_STRATEGY.value, G_enum.SPAWN_METHOD.value, \
          G_enum.SPAWN_STRATEGY.value, G_enum.T_SPAWN.value, G_enum.T_SR.value, \
          G_enum.T_AR.value, G_enum.T_MALLEABILITY.value]

  for item in array_list_items:
    name = columnsG[item]
    values = dfG[name].copy()
    for index in range(len(values)):
      values[index] = tuple(values[index])
    dfG[name] = values

#-----------------------------------------------

if len(sys.argv) < 2:
    print("The files name is missing\nUsage: python3 MallTimes.py commonName directory OutName")
    exit(1)

common_name = sys.argv[1]
if len(sys.argv) >= 3:
    BaseDir = sys.argv[2]
    print("Searching in directory: "+ BaseDir)
else:
    BaseDir = "./"

if len(sys.argv) >= 4:
  name = sys.argv[3]
else:
  name = "data"
print("File name will be: " + name + "G.pkl")

lista = (glob.glob(BaseDir + common_name + "*.out")) # Se utiliza cuando solo hay un nivel de directorios
print("Number of files found: "+ str(len(lista)));

it = -1
dataG = []

for elem in lista:
  f = open(elem, "r")
  it,runs_in_file = read_global_file(f, dataG, it)
  f.close()

dfG = pd.DataFrame(dataG, columns=columnsG)
convert_to_tuples(dfG)
print(dfG)
dfG.to_pickle(name + 'G.pkl')

#dfM = pd.DataFrame(dataM, columns=columnsM)

#Poner en TC el valor real y en TH el necesario para la app
#cond = dfM.TH != 0
#dfM.loc[cond, ['TC', 'TH']] = dfM.loc[cond, ['TH', 'TC']].values
#dfM.to_csv(name + 'M.csv')