diff --git a/ML/eval_proc.py b/ML/eval_proc.py index 10fbe00..c859e66 100644 --- a/ML/eval_proc.py +++ b/ML/eval_proc.py @@ -5,6 +5,8 @@ import sys import torch.nn as nn import numpy as np +from sklearn.preprocessing import StandardScaler + PATH= "/home/sgundo/Desktop/Tesi/OS_FaultMonitor/ML/" len_index = 20 @@ -34,18 +36,21 @@ def forward(self, x): def eval(feat): X = np.array(feat) + X= scaler.transform(X) X = torch.from_numpy(X).float() X = X.unsqueeze(0) y = model(X) y = torch.log_softmax(y, dim=1) _, y = torch.max(y, dim = 1) - return y.item() f_s = True # read metrics from file or receive it from socket flip = 0 cmd = sys.argv[1] bi = sys.argv[2] +scaler = StandardScaler() # standard scaler as in the train set +# scaler.mean_ = +# scaler.var_ = model = BinaryClassification() model.load_state_dict(torch.load(PATH+bi+".pth", map_location=torch.device('cpu'))) model.eval() @@ -59,13 +64,15 @@ def eval(feat): first_line = file.readline() for last_line in file: pass - print (last_line) + #print (last_line) attr = last_line.split() attr = attr[3:] - print(attr) + #print(attr) attr_int = [int(i) for i in attr] if len(attr_int) == 7: - eval(attr_int) + #response = eval(attr_int) + response = 1 + print("Evaluation: "+str(response)) else: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: diff --git a/ML/model_NN50_20.pth b/ML/model_NN50_20.pth deleted file mode 100644 index 15d381f..0000000 Binary files a/ML/model_NN50_20.pth and /dev/null differ diff --git a/cmd/monitor b/cmd/monitor index 41af10e..176b886 100755 --- a/cmd/monitor +++ b/cmd/monitor @@ -39,9 +39,8 @@ do done echo "comando lanciato $cmd" - conf="instr_retired,unhalted_ref_cycles_fixed,cycles,instr,llc_references,llc_misses,branch_instr_retired" -nohup pmctrack -T 1 -c $conf $cmd > $cmd.out +pmctrack -o $cmd.out -T 1 -c $conf $cmd python3 /home/sgundo/Desktop/Tesi/OS_FaultMonitor/ML/eval_proc.py $cmd $target # pid=$! # echo $pid diff --git a/cmd/prova.c b/cmd/prova.c new file mode 100644 index 0000000..c8d8eed --- /dev/null +++ b/cmd/prova.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +/* +Simple program to simulate a fault with a 50% chance +*/ + +int main(int argc, char* argv[]){ + int i = 0; + int *ptr1, *ptr2=NULL; + for(i=0;i<10000000;i++); + + srand(time(0)); + ptr1 = &i; + //printf("Pointer value before %p\n", ptr1); + ptr2 = (int *) ((uintptr_t) ptr1 | (uintptr_t) 0xFFF000); //simulate a fault by changing a pointer + //printf("Pointer value after %p\n", ptr2); + if((rand()%2)==0) + i = *ptr2; + else + i = *ptr1; + + //printf("Intero %d\n", i); +}