From b03a52e65aa9ab063e24432339bee19b5cdad409 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Sat, 17 Jun 2023 10:48:01 +0800 Subject: [PATCH] fix: Failed to store the data collected on loop mode --- DSView/pv/data/logicsnapshot.cpp | 31 ++++++++++--------------------- DSView/pv/data/logicsnapshot.h | 2 +- DSView/pv/storesession.cpp | 6 ++---- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/DSView/pv/data/logicsnapshot.cpp b/DSView/pv/data/logicsnapshot.cpp index 47ac32e7..12912ca9 100644 --- a/DSView/pv/data/logicsnapshot.cpp +++ b/DSView/pv/data/logicsnapshot.cpp @@ -1333,23 +1333,15 @@ bool LogicSnapshot::has_data(int sig_index) int LogicSnapshot::get_block_num() { - // return (_ring_sample_count >> LeafBlockPower) + - // ((_ring_sample_count & LeafMask) != 0); - - int block = _ring_sample_count / LeafBlockSamples; - if (_ring_sample_count % LeafBlockSamples != 0){ - block++; - } - if (_loop_offset % LeafBlockSamples != 0){ - block++; - } - - return block; + int block = ceil((_ring_sample_count+_loop_offset) * 1.0 / LeafBlockSamples) + - floor(_loop_offset * 1.0 / LeafBlockSamples); + return block; } uint64_t LogicSnapshot::get_block_size(int block_index) { int block_num = get_block_num(); + uint64_t samples = 0; assert(block_index < block_num); @@ -1359,17 +1351,14 @@ uint64_t LogicSnapshot::get_block_size(int block_index) return LeafBlockSamples / 8; } else if (block_index == 0){ - if (_loop_offset % LeafBlockSamples == 0) - return LeafBlockSamples / 8; - else - return (LeafBlockSamples - _loop_offset % LeafBlockSamples) / 8; + samples = min(_ring_sample_count+_loop_offset, + (uint64_t)LeafBlockSamples) - (_loop_offset % (uint64_t)LeafBlockSamples); + return samples/8; } else{ - uint64_t ring_sample_count = _ring_sample_count + _loop_offset; - if (ring_sample_count % LeafBlockSamples == 0) - return LeafBlockSamples / 8; - else - return (ring_sample_count % LeafBlockSamples) / 8; + samples = (_ring_sample_count + _loop_offset) - (_ring_sample_count + _loop_offset - 1) + / LeafBlockSamples * LeafBlockSamples; + return samples/8; } } else{ diff --git a/DSView/pv/data/logicsnapshot.h b/DSView/pv/data/logicsnapshot.h index 591f5ee5..6804bf2e 100644 --- a/DSView/pv/data/logicsnapshot.h +++ b/DSView/pv/data/logicsnapshot.h @@ -144,7 +144,7 @@ public: inline bool is_able_free(){ return _able_free; - } + } private: bool get_sample_unlock(uint64_t index, int sig_index); diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index 16fa4b55..79e9197d 100644 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -223,9 +223,8 @@ void StoreSession::save_logic(pv::data::LogicSnapshot *logic_snapshot) to_save_probes++; } - _unit_count = logic_snapshot->get_sample_count() / 8 * to_save_probes; + _unit_count = logic_snapshot->get_ring_sample_count() / 8 * to_save_probes; num = logic_snapshot->get_block_num(); - dsv_info("total bytes:%llu", _unit_count); for(auto s : _session->get_signals()) { @@ -265,8 +264,7 @@ void StoreSession::save_logic(pv::data::LogicSnapshot *logic_snapshot) QFile::remove(_file_name); return; } - _units_stored += size; - dsv_info("read bytes:%llu, size:%llu,block:%d", _units_stored, size, i); + _units_stored += size; if (need_malloc) free(buf);