首页 > 解决方案 > 使用 python matplotlib 绘制 c++ 可执行输出

问题描述

我写了一个直接映射缓存模拟器,它采用以下参数:缓存大小、行大小、内存写周期、内存读周期、缓存读周期、缓存写周期。

现在我想多次运行这个程序并将输出绘制在图表上。这是为了帮助我找到或模拟真实缓存的最佳参数。

我听说 matplotlib 是一个很棒的绘图工具。所以我写了这个脚本来运行我的 c++ 可执行文件,但是如何绘制输出?

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)

我不熟悉python,所以我不知道如何解析输出然后使用numpy和matplotlib绘制它。如果您可以提出一种方法,我还可以在循环中更改我的参数并再次运行可执行文件,那就太好了。

我的代码输出如下所示:

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

标签: pythonc++matplotlib

解决方案


推荐阅读