Tracking message queue length (ie. backlog)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Tracking message queue length (ie. backlog)

Kenneth Porter
I've got a long-running background process (moving a robot) that posts
status messages to the foreground GUI thread. It's been reported to me that
on a slow PC the GUI can remain unresponsive after an error in the
background thread interrupts its and displays an error message. The app
goes unresponse for about a minute. I'm trying to track down what might be
wrong and I'm thinking perhaps the message queue got flooded and takes some
time to flush out. Is there some way to measure the depth of the queue and
perhaps dump what's in it when it's unusually full?

Also, if the queue is full of messages to "change this wxTextCtrl label",
is there some way to dump all but the last, so there's no needless changing
of a label to text that will never be seen?

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Tracking message queue length (ie. backlog)

Vadim Zeitlin-4
On Mon, 03 Apr 2017 12:40:56 -0700 Kenneth Porter wrote:

KP> I've got a long-running background process (moving a robot) that posts
KP> status messages to the foreground GUI thread. It's been reported to me that
KP> on a slow PC the GUI can remain unresponsive after an error in the
KP> background thread interrupts its and displays an error message. The app
KP> goes unresponse for about a minute. I'm trying to track down what might be
KP> wrong and I'm thinking perhaps the message queue got flooded and takes some
KP> time to flush out.

 Yes, this is possible.

KP> Is there some way to measure the depth of the queue and
KP> perhaps dump what's in it when it's unusually full?

 No, but you can run a timer in the main thread polling a flag set from a
worker thread instead of posting messages periodically. Or, maybe better,
you could set a flag before posting a message in the worker thread and
clear it in the main thread when processing the last posted message and
check for this flag being cleared before posting another one.

KP> Also, if the queue is full of messages to "change this wxTextCtrl label",
KP> is there some way to dump all but the last, so there's no needless changing
KP> of a label to text that will never be seen?

 I'm afraid the answer is no again.

 Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/

attachment0 (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Tracking message queue length (ie. backlog)

Steve Barnes


On 03/04/2017 23:39, Vadim Zeitlin wrote:

> On Mon, 03 Apr 2017 12:40:56 -0700 Kenneth Porter wrote:
>
> KP> I've got a long-running background process (moving a robot) that posts
> KP> status messages to the foreground GUI thread. It's been reported to me that
> KP> on a slow PC the GUI can remain unresponsive after an error in the
> KP> background thread interrupts its and displays an error message. The app
> KP> goes unresponse for about a minute. I'm trying to track down what might be
> KP> wrong and I'm thinking perhaps the message queue got flooded and takes some
> KP> time to flush out.
>
>  Yes, this is possible.
>
> KP> Is there some way to measure the depth of the queue and
> KP> perhaps dump what's in it when it's unusually full?
>
>  No, but you can run a timer in the main thread polling a flag set from a
> worker thread instead of posting messages periodically. Or, maybe better,
> you could set a flag before posting a message in the worker thread and
> clear it in the main thread when processing the last posted message and
> check for this flag being cleared before posting another one.
>
> KP> Also, if the queue is full of messages to "change this wxTextCtrl label",
> KP> is there some way to dump all but the last, so there's no needless changing
> KP> of a label to text that will never be seen?
>
>  I'm afraid the answer is no again.
>
>  Regards,
> VZ
>
What you could possibly do is to:

  a) Avoid any wx messages in the queue by abstraction i.e. Message =
set_current_state rather than Message = "change this wxTextCtrl label",
- This should shorten your queue anyway as one state change may result
it many gui updates.
  b) Have an internal GUI representation with the current "state" of
each control, i.e. State, Label, etc. each with a Changed flag - your
queue handler could update this for all of the messages in the current
queue until it had either cleared the queue or reached a time consuming
operation that was required and then update all of the controls that
have a changed state, clearing the flags as it goes.

While b) adds some complexity updating a local data structure is a lot
quicker than an actual control - a bit like drawing to a local bitmap
and then blitting rather than performing individual draws and any
operations in the queue that change the state of an individual control
will be summarised.
--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Loading...