From 36d95fd89252f6409ac62382ea60ecd723b82760 Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Fri, 13 Aug 2021 19:23:13 -0700 Subject: [PATCH] automatic perf dump fix --- driver/opae/vortex.cpp | 25 +++++++++++++------------ driver/rtlsim/vortex.cpp | 25 +++++++++++++------------ driver/simx/vortex.cpp | 25 +++++++++++++------------ 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/driver/opae/vortex.cpp b/driver/opae/vortex.cpp index a2ff3061..2cd12516 100755 --- a/driver/opae/vortex.cpp +++ b/driver/opae/vortex.cpp @@ -79,18 +79,17 @@ inline bool is_aligned(size_t addr, size_t alignment) { /////////////////////////////////////////////////////////////////////////////// -class AutoDeviceCleanup { +#ifdef DUMP_PERF_STATS +class AutoPerfDump { private: std::list devices_; public: - AutoDeviceCleanup() {} + AutoPerfDump() {} - ~AutoDeviceCleanup() { - for (auto it = devices_.begin(), it_end = devices_.end(); it != it_end;) { - auto device = *it; - it = devices_.erase(it); - vx_dev_close(device); + ~AutoPerfDump() { + for (auto device : devices_) { + vx_dump_perf(device, stdout); } } @@ -103,7 +102,8 @@ public: } }; -AutoDeviceCleanup gAutoDeviceCleanup; +AutoPerfDump gAutoPerfDump; +#endif /////////////////////////////////////////////////////////////////////////////// @@ -252,7 +252,9 @@ extern int vx_dev_open(vx_device_h* hdevice) { *hdevice = device; - gAutoDeviceCleanup.add_device(device); +#ifdef DUMP_PERF_STATS + gAutoPerfDump.add_device(*hdevice); +#endif return 0; } @@ -261,8 +263,6 @@ extern int vx_dev_close(vx_device_h hdevice) { if (nullptr == hdevice) return -1; - gAutoDeviceCleanup.remove_device(hdevice); - vx_device_t *device = ((vx_device_t*)hdevice); #ifdef SCOPE @@ -270,7 +270,8 @@ extern int vx_dev_close(vx_device_h hdevice) { #endif #ifdef DUMP_PERF_STATS - vx_dump_perf(device, stdout); + gAutoPerfDump.remove_device(hdevice); + vx_dump_perf(hdevice, stdout); #endif fpgaClose(device->fpga); diff --git a/driver/rtlsim/vortex.cpp b/driver/rtlsim/vortex.cpp index cc4b0caa..40c80b16 100644 --- a/driver/rtlsim/vortex.cpp +++ b/driver/rtlsim/vortex.cpp @@ -154,18 +154,17 @@ private: /////////////////////////////////////////////////////////////////////////////// -class AutoDeviceCleanup { +#ifdef DUMP_PERF_STATS +class AutoPerfDump { private: std::list devices_; public: - AutoDeviceCleanup() {} + AutoPerfDump() {} - ~AutoDeviceCleanup() { - for (auto it = devices_.begin(), it_end = devices_.end(); it != it_end;) { - auto device = *it; - it = devices_.erase(it); - vx_dev_close(device); + ~AutoPerfDump() { + for (auto device : devices_) { + vx_dump_perf(device, stdout); } } @@ -178,7 +177,8 @@ public: } }; -AutoDeviceCleanup gAutoDeviceCleanup; +AutoPerfDump gAutoPerfDump; +#endif /////////////////////////////////////////////////////////////////////////////// @@ -226,7 +226,9 @@ extern int vx_dev_open(vx_device_h* hdevice) { *hdevice = new vx_device(); - gAutoDeviceCleanup.add_device(*hdevice); +#ifdef DUMP_PERF_STATS + gAutoPerfDump.add_device(*hdevice); +#endif return 0; } @@ -235,12 +237,11 @@ extern int vx_dev_close(vx_device_h hdevice) { if (nullptr == hdevice) return -1; - gAutoDeviceCleanup.remove_device(hdevice); - vx_device *device = ((vx_device*)hdevice); #ifdef DUMP_PERF_STATS - vx_dump_perf(device, stdout); + gAutoPerfDump.remove_device(hdevice); + vx_dump_perf(hdevice, stdout); #endif delete device; diff --git a/driver/simx/vortex.cpp b/driver/simx/vortex.cpp index e3db32b8..10a0143f 100644 --- a/driver/simx/vortex.cpp +++ b/driver/simx/vortex.cpp @@ -223,18 +223,17 @@ private: /////////////////////////////////////////////////////////////////////////////// -class AutoDeviceCleanup { +#ifdef DUMP_PERF_STATS +class AutoPerfDump { private: std::list devices_; public: - AutoDeviceCleanup() {} + AutoPerfDump() {} - ~AutoDeviceCleanup() { - for (auto it = devices_.begin(), it_end = devices_.end(); it != it_end;) { - auto device = *it; - it = devices_.erase(it); - vx_dev_close(device); + ~AutoPerfDump() { + for (auto device : devices_) { + vx_dump_perf(device, stdout); } } @@ -247,7 +246,8 @@ public: } }; -AutoDeviceCleanup gAutoDeviceCleanup; +AutoPerfDump gAutoPerfDump; +#endif /////////////////////////////////////////////////////////////////////////////// @@ -257,7 +257,9 @@ extern int vx_dev_open(vx_device_h* hdevice) { *hdevice = new vx_device(); - gAutoDeviceCleanup.add_device(*hdevice); +#ifdef DUMP_PERF_STATS + gAutoPerfDump.add_device(*hdevice); +#endif return 0; } @@ -266,12 +268,11 @@ extern int vx_dev_close(vx_device_h hdevice) { if (nullptr == hdevice) return -1; - gAutoDeviceCleanup.remove_device(hdevice); - vx_device *device = ((vx_device*)hdevice); #ifdef DUMP_PERF_STATS - vx_dump_perf(device, stdout); + gAutoPerfDump.remove_device(hdevice); + vx_dump_perf(hdevice, stdout); #endif delete device;