0

I wrote a direct-mapping cache simulator that takes the following parameters: cache size, line size, memory write cycles, memory read cycles, cache read cycles, cache write cycles.

Now I want to run this program multiple times and plot the output on graphs. This is to help me find or simulate the best parameters for a real cache.

I heard that matplotlib is a great tool to plot graphs. So I wrote this script to run my c++ executable, but How do I plot the output?

import os
import sys
import matplotlib as plt 
argc = len(sys.argv)
argv =  sys.argv



cmd = './Desktop/assignment6/cache_sim/bin/cache_sim ' +  'wb ' + './Desktop/assignment6/cache_sim/ls.out ' + '1024 ' + '2048 ' + '2 ' +'4 ' + '8 ' + '16 '


os.system(cmd)

I am not familiar with python, so I don't know how to parse the output and then plot it using numpy and matplotlib. if you can sugegst a way I can also change my parameters in a loop and pass run the executable again it would be great.

the output of my code looks like this:

Total misses: 756
Total hits: 170245
Total Memory Read Access Attempts: 127892
Total Memory write Access Attempts: 42353
Total Memory Access Attempts: 170245
Total Memory read Access : 756
Total Memory write Access : 42353
Total # of cycles for cache reads: 255784
Total # of cycles for cache writes: 169412
Total # of cycles for cache access: 425196
Total # of cycles for memory reads: 6048
Total # of cycles for memory writes: 677648
Total # of cycles for memory access: 683696
Mina Ashraf
  • 353
  • 1
  • 12
  • The solution might depend on your OS, I would recommend that you specify which OS you are running in.. In case you are running on linux, adding the following: os.system(cmd + ">> /home//my_log_file.log" Should redirect the output of the cmd to "my_log_file.log" ..And then you should be able to tail it using [the answer from this question](https://stackoverflow.com/questions/12523044/how-can-i-tail-a-log-file-in-python). – Vinzent Apr 14 '20 at 14:22
  • @Vinzent what does tailing mean? I just want to plot the output on a graph – Mina Ashraf Apr 14 '20 at 14:26
  • tailing is a linux feature that allows you to "spy" on what is being written to any file-like object, in this case just a file. Tailing the file in this case would give you the output of the executable. That is IF you instructed the shell to redirect the output of the executable into the file using the cmd >> filename syntax. You would then still need to extract the data from the lines being written to the file and to plot that data somehow.. But most importantly; are you using Linux? because if not this wont work. – Vinzent Apr 14 '20 at 14:29

0 Answers0