python - 使用 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
解决方案
推荐阅读
- ruby-on-rails - Rails 不允许在没有 user_id 参数的情况下执行 after_create。为什么?
- r - R4.0 性能:数据帧 vs 列表,循环 vs 向量化 - 常量向量减法示例
- unity3d - GameObject 不包含 AddForce 的定义
- python - 使用 Docker 在 AWS Lambda 中运行 Selenium webscraper
- javascript - 如何根据角度 8 中的哪个组件重定向显示弹出窗口?
- macos - FileVault登录的MacOS授权插件奇怪行为
- python - 如何在 Python 的 matplotlib 中将多条 2D 线连接/组合到表面
- python - 从频繁写入的数学函数读取到换行文件
- c# - apns 推送通知和更新未到达
- arrays - 在 Python 中查找 4D 数组中的对角线索引