123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- /*
- * 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.inserirErroRedundancia(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<Erro> trataString(String erro){
- String[] erros = erro.split(" ");
-
- ArrayList<Erro> 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<Erro> red = null;
-
- ArrayList<Erro> 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(4, 0, 2);
- cache.requisicaoParaCache(20, true);
- //cache.requisicaoParaCache(20, true);
- // cache.requisicaoParaCache(4, true);
- // cache.requisicaoParaCache(512, true);
- // cache.requisicaoParaCache(512, true);
-
- System.out.println("Hit = " + cache.getHit());
- System.out.println("Miss = " + cache.getMiss());
- System.out.println("Writeback = " + cache.getWB());
- System.out.println("WriteBackForcado = " + cache.getWBForcado());
- System.out.println("LeituraEspecial = " + cache.getcontadorLeituraEspecial());
- System.out.println("LeituraCache = " + cache.getLeituraCache());
- System.out.println("EscritaCache = " + cache.getEscritaCache());
- System.out.println("LeituraCacheRedundante = " + cache.getLeituraRedundancia());
- System.out.println("EscritaCacheRedundante = " + cache.getEscritaRedundancia());
- 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());
- }
-
- //inicializa os erros da redundancia
- if(errosInit.getErroRed() != null){
- for (Erro arg : errosInit.getErroRed()) {
- cache.inserirErroRedundancia(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("WriteBackForcado = " + cache.getWBForcado());
- System.out.println("LeituraEspecial = " + cache.getcontadorLeituraEspecial());
- System.out.println("LeituraCache = " + cache.getLeituraCache());
- System.out.println("EscritaCache = " + cache.getEscritaCache());
- System.out.println("LeituraCacheRedundante = " + cache.getLeituraRedundancia());
- System.out.println("EscritaCacheRedundante = " + cache.getEscritaRedundancia());
- System.out.println("Ciclos = " + cache.getCiclos());
- System.out.println("Incachavel = " + cache.getContadorIncachavel());
- System.out.println("EscritaSDRAM = "+cache.getEscritaSDRAM());
- System.out.println("LeituraSDRAM = "+cache.getLeituraSDRAM());
- // */
- }
- }
|