/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package simuladorcache; import cache.*; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.Scanner; /** * * @author Juninho Carlos */ public class SimuladorCache { public static Cache teste1() { Cache c = new Cache(); c.inserirErro(0, 0, 0); c.inserirErro(0, 0, 5); c.inserirErro(0, 0, 12); c.inserirErro(0, 0, 15); c.requisicaoParaCache(0, false); c.requisicaoParaCache(16, true); c.requisicaoParaCache(4096, false); c.requisicaoParaCache(8192, true); c.requisicaoParaCache(12288, false); c.requisicaoParaCache(16384, true); return c; } public static Cache teste2() { Cache c = new Cache(); c.inserirErro(0, 0, 0); c.inserirErro(4, 0, 5); c.inserirErro(8, 0, 12); c.inserirErro(8, 0, 13); c.inserirErro(12, 0, 15); c.inserirErro(16, 0, 0); c.inserirErro(16, 0, 5); c.inserirErro(16, 0, 12); c.inserirErro(16, 0, 15); c.requisicaoParaCache(0, false); c.requisicaoParaCache(4, false); c.requisicaoParaCache(512, false); c.requisicaoParaCache(1024, false); c.requisicaoParaCache(1536, false); c.requisicaoParaCache(2048, true); return c; } public static Cache teste3() { Cache c = new Cache(); c.inserirErro(0, 0, 0); c.inserirErro(4, 0, 5); c.inserirErro(8, 0, 12); c.inserirErro(8, 0, 13); c.inserirErro(12, 0, 15); c.inserirErro(16, 0, 0); c.inserirErro(16, 0, 5); c.inserirErro(16, 0, 12); c.inserirErro(16, 0, 15); c.requisicaoParaCache(0, false); c.requisicaoParaCache(512, true); c.requisicaoParaCache(1024, true); c.requisicaoParaCache(1536, true); c.requisicaoParaCache(2048, true); return c; } public static Cache teste4() { Cache c = new Cache(); c.inserirErro(0, 0, 0); c.requisicaoParaCache(0, true); c.requisicaoParaCache(4096, true); c.requisicaoParaCache(8192, true); c.requisicaoParaCache(12288, true); c.requisicaoParaCache(16384, true); return c; } public static ArrayList trataString(String erro){ String[] erros = erro.split(" "); ArrayList arrayDeErros = new ArrayList<>(); for (String erro1 : erros){ String[] partes = erro1.split("/"); Integer conjunto = Integer.parseInt(partes[0]); Integer bloco = Integer.parseInt(partes[1]); Integer palavra = Integer.parseInt(partes[2]); Erro e = new Erro(conjunto, bloco, palavra); arrayDeErros.add(e); } return arrayDeErros; } /** * Retorna um array onde a posição zero tem os erros da cache o a posicao 1 tem os erros da red * @param path * @return * @throws FileNotFoundException */ public static Erros initErro(String path) throws FileNotFoundException{ Scanner in = new Scanner(new FileReader(path)); String s = in.nextLine(); String []erros = s.split(";"); String erroCache = erros[0]; String erroRed; ArrayList red = null; ArrayList cache = trataString(erroCache); if(erros.length > 1){ erroRed = erros[1]; red = trataString(erroRed); } Erros aux = new Erros(cache, red); // System.err.println(teste.toString()); return aux; } /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException { /*/Area de debug Cache cache = new Cache(); cache.inserirErro(0, 0, 5); // cache.inserirErro(0, 1, 5); // cache.inserirErro(0, 2, 5); // cache.inserirErro(0, 3, 5); cache.requisicaoParaCache(20, true); cache.requisicaoParaCache(20, false); // cache.requisicaoParaCache(4, true); // cache.requisicaoParaCache(4, true); cache.requisicaoParaCache(4096, false); cache.requisicaoParaCache(8192, true); // cache.requisicaoParaCache(1024, true); // System.out.println("LRU: "+cache.getConjuntos()[0].lru); cache.requisicaoParaCache(12288, true); // cache.requisicaoParaCache(512, true); // cache.requisicaoParaCache(512, true); // System.out.println("Cache: "+ cache); System.out.println("Hit = " + cache.getHit()); System.out.println("Miss = " + cache.getMiss()); System.out.println("Writeback = " + cache.getWB()); System.out.println("LeituraCache = " + cache.getLeituraCache()); System.out.println("EscritaCache = " + cache.getEscritaCache()); System.out.println("LeituraSDRAM = " + cache.getLeituraSDRAM()); System.out.println("EscritaSDRAM = " + cache.getEscritaSDRAM()); System.out.println("Ciclos = " + cache.getCiclos()); // */ ///* Cache cache = new Cache(); String pathErros = args[0]; String pathTrace = args[1]; Erros errosInit = initErro(pathErros); //inicializa os erros da cache for (Erro arg : errosInit.getErroCache()) { cache.inserirErro(arg.getConjunto(), arg.getBloco(), arg.getPalavra()); } //Executa as requisições do trace Arquivo trace = new Arquivo(pathTrace); while(trace.lerArquivo()){ Requisicao atual = trace.getRequisicao(); cache.requisicaoParaCache(atual.endereco, atual.read); } System.out.println("Hit = " + cache.getHit()); System.out.println("Miss = " + cache.getMiss()); System.out.println("Writeback = " + cache.getWB()); System.out.println("LeituraCache = " + cache.getLeituraCache()); System.out.println("EscritaCache = " + cache.getEscritaCache()); System.out.println("LeituraSDRAM = " + cache.getLeituraSDRAM()); System.out.println("EscritaSDRAM = " + cache.getEscritaSDRAM()); System.out.println("Ciclos = " + cache.getCiclos()); // */ } }