Skip to content

Commit 9af6fb1

Browse files
deanleetwilsonco
authored andcommitted
cabana: only update the colors of newly fetched messages in historylog (commaai#27144)
only update new msgs color
1 parent 7dab7e0 commit 9af6fb1

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

tools/cabana/historylog.cc

+19-27
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ void HistoryLogModel::updateState() {
8484
if ((has_more_data = !new_msgs.empty())) {
8585
beginInsertRows({}, 0, new_msgs.size() - 1);
8686
messages.insert(messages.begin(), std::move_iterator(new_msgs.begin()), std::move_iterator(new_msgs.end()));
87-
updateColors();
8887
endInsertRows();
8988
}
9089
last_fetch_time = current_time;
@@ -97,29 +96,11 @@ void HistoryLogModel::fetchMore(const QModelIndex &parent) {
9796
if ((has_more_data = !new_msgs.empty())) {
9897
beginInsertRows({}, messages.size(), messages.size() + new_msgs.size() - 1);
9998
messages.insert(messages.end(), std::move_iterator(new_msgs.begin()), std::move_iterator(new_msgs.end()));
100-
if (!dynamic_mode) {
101-
updateColors();
102-
}
10399
endInsertRows();
104100
}
105101
}
106102
}
107103

108-
void HistoryLogModel::updateColors() {
109-
if (!display_signals_mode || sigs.empty()) {
110-
const auto freq = can->lastMessage(msg_id).freq;
111-
if (dynamic_mode) {
112-
for (auto it = messages.rbegin(); it != messages.rend(); ++it) {
113-
it->colors = hex_colors.compute(it->data, it->mono_time / (double)1e9, freq);
114-
}
115-
} else {
116-
for (auto it = messages.begin(); it != messages.end(); ++it) {
117-
it->colors = hex_colors.compute(it->data, it->mono_time / (double)1e9, freq);
118-
}
119-
}
120-
}
121-
}
122-
123104
template <class InputIt>
124105
std::deque<HistoryLogModel::Message> HistoryLogModel::fetchData(InputIt first, InputIt last, uint64_t min_time) {
125106
std::deque<HistoryLogModel::Message> msgs;
@@ -153,17 +134,28 @@ template std::deque<HistoryLogModel::Message> HistoryLogModel::fetchData<>(std::
153134

154135
std::deque<HistoryLogModel::Message> HistoryLogModel::fetchData(uint64_t from_time, uint64_t min_time) {
155136
auto events = can->events();
137+
const auto freq = can->lastMessage(msg_id).freq;
138+
const bool update_colors = !display_signals_mode || sigs.empty();
139+
156140
if (dynamic_mode) {
157-
auto it = std::upper_bound(events->rbegin(), events->rend(), from_time, [=](uint64_t ts, auto &e) {
158-
return e->mono_time < ts;
159-
});
160-
return fetchData(it, events->rend(), min_time);
141+
auto first = std::upper_bound(events->rbegin(), events->rend(), from_time, [=](uint64_t ts, auto &e) { return e->mono_time < ts; });
142+
auto msgs = fetchData(first, events->rend(), min_time);
143+
if (update_colors && min_time > 0) {
144+
for (auto it = msgs.rbegin(); it != msgs.rend(); ++it) {
145+
it->colors = hex_colors.compute(it->data, it->mono_time / (double)1e9, freq);
146+
}
147+
}
148+
return msgs;
161149
} else {
162150
assert(min_time == 0);
163-
auto it = std::upper_bound(events->begin(), events->end(), from_time, [=](uint64_t ts, auto &e) {
164-
return ts < e->mono_time;
165-
});
166-
return fetchData(it, events->end(), 0);
151+
auto first = std::upper_bound(events->begin(), events->end(), from_time, [=](uint64_t ts, auto &e) { return ts < e->mono_time; });
152+
auto msgs = fetchData(first, events->end(), 0);
153+
if (update_colors) {
154+
for (auto it = msgs.rbegin(); it != msgs.rend(); ++it) {
155+
it->colors = hex_colors.compute(it->data, it->mono_time / (double)1e9, freq);
156+
}
157+
}
158+
return msgs;
167159
}
168160
}
169161

tools/cabana/historylog.h

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class HistoryLogModel : public QAbstractTableModel {
3333
int columnCount(const QModelIndex &parent = QModelIndex()) const override {
3434
return display_signals_mode && !sigs.empty() ? sigs.size() + 1 : 2;
3535
}
36-
void updateColors();
3736
void refresh();
3837

3938
public slots:

0 commit comments

Comments
 (0)