Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce CPU usage of data display. #34

Merged
merged 4 commits into from
Jan 24, 2017

Conversation

mastykin
Copy link
Contributor

Hi.
My sensor is providing many data on 100Hz,
and I see significant CPU usage compared to old CuteCom.
I think the problem is in QPlainTextEdit.
This PR is only a suggestion.
It does batch insertText() operations on timer.
CPU usage is reduced from 40% to 10%.
Dmitry

My sensor is providing many data on 100Hz,
and I see significant CPU usage compared to old CuteCom.
I think the problem is in QPlainTextEdit.
This PR is only a suggestion.
It does batch insertText() operations on timer.
CPU usage is reduced from 40% to 10%.
Now incomplete line is being removed correctly
before displaying block of hex data.
@mastykin mastykin changed the title faster data display Reduce CPU usage of data display. Jan 19, 2017
@mastykin
Copy link
Contributor Author

I see that easier solution could be just:
void DataDisplay::timerEvent(QTimerEvent *event) {
setUpdatesEnabled(true);
setUpdatesEnabled(false);
}

But with massive output in hex mode master version (and this easier solution also doesn't help) make CueCom quickly hang when I click output text with mouse. But foregoing commits are free of this hanging.
Dmitry

Copy link
Contributor

@slapab slapab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this PR and I wrote my thoughts in the first commit. I explained why is better to use the single shot timer instead of the repetitive one, so if we agree then the last commit (b7c5e73) should be reverted.

I'm not quite sure for what the second commit (4c56d91) is for. It seems that it fixes something that I'm not aware of, so can you write some detailed information? In my opinion, if it is a bug please open new issue.

@@ -59,6 +59,9 @@ DataDisplay::DataDisplay(QWidget *parent)

connect(m_searchPanel, &SearchPanel::findNext, this, &DataDisplay::find);
connect(m_searchPanel, &SearchPanel::textEntered, m_highlighter, &DataHighlighter::setSearchString);

connect(&m_timer, SIGNAL(timeout()), this, SLOT(BlockReady()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -59,6 +59,9 @@ DataDisplay::DataDisplay(QWidget *parent)

connect(m_searchPanel, &SearchPanel::findNext, this, &DataDisplay::find);
connect(m_searchPanel, &SearchPanel::textEntered, m_highlighter, &DataHighlighter::setSearchString);

connect(&m_timer, SIGNAL(timeout()), this, SLOT(BlockReady()));
m_timer.start(100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using QTimer, in my opinion, is the best way to buffer incoming characters before printing them out. But this use case of QTimer Causes repetitive call a timeout slot even when serial device is closed. So, please change to a single shot configuration, set interval value (I think 100ms is the maximum, but I would prefer to set smaller interval, maybe value between 50ms and 75ms) and finally call the start() from the displayData() only when the timer is inactive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the comments, I will add your corrections to my branch. As I'm new to GitHub, please answer, should I do corrections as new commit, or may I make a fixup using git rebase -i and push?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you do rebase that means you are rewriting the history. If you will push that onto GitHub then all old commits and theirs inline comments will disappear, so please make an another commit.

@@ -129,6 +130,10 @@ class DataDisplay : public QWidget

QVector<QTime> *m_timestamps;
DataHighlighter *m_highlighter;
QTimer m_timer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to more descriptive name, e.g. m_BufferingIncomingDataTimer, and provide short comment which will describe what this field does.

QTimer m_timer;

private slots:
void BlockReady(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to more descriptive name and provide a short comment.

@mastykin
Copy link
Contributor Author

I agree to revert last commit (b7c5e73). The second commit (4c56d91) is just a fixup for the first one, where I had not implemented correctly the deletion of line reminder both from m_data and from the widget.

- switched to singleshot timer 70ms;
- renames;
- call displayDataFromBuffer() also on changing display mode,
for nice output when hex switches to ascii and back;
@cyc1ingsir cyc1ingsir merged commit 789ade2 into neundorf:master Jan 24, 2017
@mastykin mastykin deleted the data_display_cpu_usage branch January 25, 2017 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants