Skip to content

Commit 07791e2

Browse files
committed
Bug fixes and performance improvements to PacketManager and HistoryManager. Switched to lazy refreshes when a render occurs rather than doing it in the processing path. Fixed crash in StreamBrowserDialog during startup. Fixes #835.
1 parent e8bf968 commit 07791e2

File tree

7 files changed

+42
-18
lines changed

7 files changed

+42
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ analysis-build
55
asan-build
66
release-nodebug-build
77
debug-noopt-build
8+
release-asan-build

src/ngscopeclient/HistoryManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ void HistoryManager::AddHistory(
319319
LogTrace("Removing un-pinned waveform at t=%s (now have %zu points of %d allowed)\n",
320320
point->m_time.PrettyPrint().c_str(), m_history.size(), m_maxDepth);
321321
m_session.RemoveMarkers(point->m_time);
322-
m_session.RemovePackets(point->m_time, false);
322+
m_session.RemovePackets(point->m_time);
323323
m_history.erase(it);
324324
deletedSomething = true;
325325
break;

src/ngscopeclient/PacketManager.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ using namespace std;
4444
PacketManager::PacketManager(PacketDecoder* pd, Session& session)
4545
: m_session(session)
4646
, m_filter(pd)
47+
, m_refreshPending(false)
4748
{
4849

4950
}
@@ -72,6 +73,7 @@ void PacketManager::RefreshRows()
7273
lock_guard<recursive_mutex> lock(m_mutex);
7374

7475
//Clear all existing row state
76+
m_refreshPending = false;
7577
m_rows.clear();
7678

7779
//Make a list of waveform timestamps and make sure we display them in order
@@ -185,7 +187,7 @@ void PacketManager::Update()
185187
m_cachekey = key;
186188

187189
//Remove any old history we might have had from this timestamp
188-
RemoveHistoryFrom(time, false);
190+
RemoveHistoryFrom(time);
189191

190192
//Copy the new packets and detach them so the filter doesn't delete them.
191193
//Do the merging now
@@ -259,8 +261,7 @@ void PacketManager::FilterPackets()
259261
m_filteredChildPackets = m_childPackets;
260262

261263
//but still refresh the set of rows being displayed
262-
RefreshRows();
263-
264+
m_refreshPending = true;
264265
return;
265266
}
266267

@@ -301,18 +302,15 @@ void PacketManager::FilterPackets()
301302
}
302303
}
303304

304-
//Refresh the set of rows being displayed
305-
RefreshRows();
305+
m_refreshPending = true;
306306
}
307307

308308
/**
309309
@brief Removes all history from the specified timestamp
310310
311311
@param timestamp Time to remove the history from
312-
@param refreshAfter True if we should refresh the list of displayed rows, false to not refresh
313-
(should only be set false in Update())
314312
*/
315-
void PacketManager::RemoveHistoryFrom(TimePoint timestamp, bool refreshAfter)
313+
void PacketManager::RemoveHistoryFrom(TimePoint timestamp)
316314
{
317315
lock_guard<recursive_mutex> lock(m_mutex);
318316

@@ -329,8 +327,7 @@ void PacketManager::RemoveHistoryFrom(TimePoint timestamp, bool refreshAfter)
329327
m_filteredPackets.erase(timestamp);
330328

331329
//update the list of displayed rows so we don't have anything left pointing to stale packets
332-
if(refreshAfter)
333-
RefreshRows();
330+
m_refreshPending = true;
334331
}
335332

336333
void PacketManager::RemoveChildHistoryFrom(Packet* pack)

src/ngscopeclient/PacketManager.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class PacketManager
156156
virtual ~PacketManager();
157157

158158
void Update();
159-
void RemoveHistoryFrom(TimePoint timestamp, bool refreshAfter = true);
159+
void RemoveHistoryFrom(TimePoint timestamp);
160160

161161
std::recursive_mutex& GetMutex()
162162
{ return m_mutex; }
@@ -191,10 +191,26 @@ class PacketManager
191191
{ m_lastChildOpen[pack] = open; }
192192

193193
std::vector<RowData>& GetRows()
194-
{ return m_rows; }
194+
{
195+
RefreshIfPending();
196+
return m_rows;
197+
}
195198

196199
void OnMarkerChanged();
197200

201+
/**
202+
@brief Refresh the list of pending packets
203+
*/
204+
void RefreshIfPending()
205+
{
206+
std::lock_guard<std::recursive_mutex> lock(m_mutex);
207+
if(m_refreshPending)
208+
{
209+
LogTrace("Refreshing rows for %s due to pending changes\n", m_filter->GetDisplayName().c_str());
210+
RefreshRows();
211+
}
212+
}
213+
198214
protected:
199215
void RemoveChildHistoryFrom(Packet* pack);
200216

@@ -233,6 +249,9 @@ class PacketManager
233249

234250
///@brief Map of packets to child-open flags from last frame
235251
std::map<Packet*, bool> m_lastChildOpen;
252+
253+
///@brief True if we have a refresh pending before we can render (i.e. pending deletion or similar)
254+
bool m_refreshPending;
236255
};
237256

238257
#endif

src/ngscopeclient/Session.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void Session::ClearBackgroundThreads()
140140
}
141141

142142
//Clear our trigger state
143-
//Important to signal the WaveformProcessingThread so it doesn't block waiting on response that's not going to come
143+
//Important to signal the WaveformThread so it doesn't block waiting on response that's not going to come
144144
g_waveformReadyEvent.Clear();
145145
g_rerenderDoneEvent.Clear();
146146
g_waveformProcessedEvent.Signal();
@@ -153,6 +153,9 @@ void Session::ClearBackgroundThreads()
153153

154154
//Clear shutdown flag in case we're reusing the session object
155155
m_shuttingDown = false;
156+
157+
//Clear the WaveformThread signal if it's not already cleared
158+
g_waveformProcessedEvent.Clear();
156159
}
157160

158161
void Session::FlushConfigCache()
@@ -3473,10 +3476,10 @@ shared_ptr<PacketManager> Session::AddPacketFilter(PacketDecoder* filter)
34733476
/**
34743477
@brief Deletes packets from our packet managers for a waveform timestamp
34753478
*/
3476-
void Session::RemovePackets(TimePoint t, bool immediateRefresh)
3479+
void Session::RemovePackets(TimePoint t)
34773480
{
34783481
for(auto it : m_packetmgrs)
3479-
it.second->RemoveHistoryFrom(t, immediateRefresh);
3482+
it.second->RemoveHistoryFrom(t);
34803483
}
34813484

34823485
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

src/ngscopeclient/Session.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class Session
535535
void RemoveMarkers(TimePoint t)
536536
{ m_markers.erase(t); }
537537

538-
void RemovePackets(TimePoint t, bool immediateRefresh = true);
538+
void RemovePackets(TimePoint t);
539539

540540
std::set<FlowGraphNode*> GetAllGraphNodes();
541541

src/ngscopeclient/StreamBrowserDialog.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ class StreamBrowserTimebaseInfo
5555
int m_rate;
5656

5757
uint64_t GetRate()
58-
{ return m_rates[m_rate]; }
58+
{
59+
if(m_rates.empty())
60+
return 0;
61+
return m_rates[m_rate];
62+
}
5963

6064
//Memory depth
6165
std::vector<uint64_t> m_depths;

0 commit comments

Comments
 (0)