/******************************************************************************* Arquivo: loggers.c Autor: Gustavo Aschwanden Soviersovski Função: Contém todas as funções de log do sistema Última Edição em: 31/05/2019 *******************************************************************************/ #include #include "loggers.h" #include "smpl.h" #include "nodo.h" #include "constants.h" extern tnodo *nodo; extern int evtTestCounter, evtHappened, latency; //Faz o log dos testes executados por um nodo void logTest(int token, int numTests, int *toTests) { int i; printf("[%4.1f] O nodo %d testa os nodos (", time(), token); for (i = 0; i < numTests - 1; i++) printf("%d, ", toTests[i]); printf("%d) \n", toTests[i]); } //Faz o log de uma falha descoberta por um nodo void logFalhaDescoberta(int falho) { printf("\tDescobriu que %d falhou\n", falho); } //Faz o log de uma recuperação descoberta por um nodo void logRepairDescoberto(int recup) { printf("\tDescobriu que %d recuperou\n", recup); } //Faz o log de uma novidade recebida a partir de outro nodo void logNovidade(int informante, int changedNode, int newState) { printf("\tInfo de %d: %d %s\n", informante, changedNode, newState % 2 ? "falhou" : newState ? "recuperou" : "inicializou"); } //Imprime uma lista de nodos void printNodes(int *array, int n) { int i, j; int toPrint[n]; printf ("("); for (i = 0, j = 0; i < n; i++) if (array[i]) { toPrint[j] = i; j++; } for (i = 0; i < j - 1; i++) printf("%d, ", toPrint[i]); printf("%d)\n", toPrint[i]); } //Faz o log de um evento void logLastEvent(int *failed, int *repaired, int n, double lastTime) { int i, loggable = 0; for (i = 0; i < n; i++) { if (failed[i] || repaired[i]) loggable = 1; } if (loggable) { printf(RED); printf("[%4.1f] EVENTO: ", lastTime); for (i = 0, loggable = 0; i < n; i++) { if (failed[i]) loggable = 1; } if (loggable) { printf("Os seguintes nodos falharam "); printNodes(failed, n); } for (i = 0, loggable = 0; i < n; i++) { if (repaired[i]) loggable = 1; } if (loggable) { printf("Os seguintes nodos recuperaram "); printNodes(repaired, n); } printf(RESET); } //Limpa os vetores para uso futuro for (i = 0; i < n; i++) failed[i] = repaired[i] = 0; } //Verifica se o diagnostico está completo e caso esteja faz o log do resultado void logIfCompleteDiagnosis(int n, int rodadaAcabou) { int i; for (i = 0; i < n; i++) { if (nodo[i].notified == UNNOTIFIED) return; } printf(YELLOW); printf("DIAGNOSTICO COMPLETO: Nº Testes Realizados: %d, Latencia: %d\n", evtTestCounter, rodadaAcabou ? latency : latency + 1); printf(RESET); evtHappened = 0; } void sendBroadcastMsg(int src, int dst) { printf("[%4.1f] O nodo %d enviou uma mensagem para o nodo %d\n", time(), src, dst); } void logBroadcast(int src) { printf("[%4.1f] BROADCAST - Origem %d\n", time(), src); }