-
Notifications
You must be signed in to change notification settings - Fork 195
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
yarp::os::ThreadStats #1230
yarp::os::ThreadStats #1230
Conversation
// Advanced statistics: histogram | ||
// ============================== | ||
unsigned bins_pitch_ms; | ||
std::map<unsigned, unsigned> jitter_pdf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure this list is allocated before the thread starts running and deallocated after the thread stopped. If you modify the size of the list dynamically during the thread execution there may be a performance hit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jitter_pdf
entries are correctly allocated (twice, I just noticed) in _initializeJitterPDF()
and _resetStats()
. The dynamic allocation happens inside the map
class, and since I didn't use any pointers, all the resources should be correctly deallocated when the thread is stopped.
e3ac81e
to
48b9b85
Compare
@diegoferigo Is this PR finished or abandoned? If it is finished, can you rebase it and remove the WIP from the title? |
If I remember corectly, @diegoferigo was waiting for the clock refactoring to be completed before merging this PR to avoid too many comflicts. The refactored clock is in devel from a couple of months now, so I think now is a good time to add this feature. |
@drdanz |
Should we defer it to the next release then? We are releasing on the 23rd... |
I thought I had already replied to this message. Yes, I need further testing before hitting |
8e5e6ba
to
9c24bc1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a quick glance it seems a nice patch!
I would add some doxygen documentation for the public API and a ThreadStatsTest
to harness_os
for testing the basic functionalities.
BTW nice work @diegoferigo 👍
|
||
/* | ||
Consider: | ||
* |---------| Thread's or DUT's period |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Device Under Testing (DUT)
|
||
// Constant values | ||
// =============== | ||
double m_window_length; // Lenght of the window for calculating statistic features |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Length
cd7f875
to
78cd958
Compare
@drdanz Ready to go as soon as all checks succeed. |
78cd958
to
96bba7a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few other comments:
- Each class should be in its own .h/.cpp file
- You should be using the PIMPL idiom for the private members, see for example https://github.com/robotology/yarp/blob/c6cfb77a0c22ddd09add5a87f136ddddce1783af/src/libYARP_OS/include/yarp/os/Contact.h#L475:L479
- I cannot really understand how to use the classes, can you replace them to the thread implementation? A couple of examples would be nice
- Unit tests would be very appreciated
namespace os { | ||
class ThreadStats; | ||
class MultipleThreadStats; | ||
const unsigned WINDOW_LENGTH_DEFAULT = 60; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These constants should not pollute the yarp::os
namespace, perhaps they should be class members?
Also will it work with constexpr
instead of const
?
*/ | ||
|
||
#include <yarp/os/LockGuard.h> | ||
#include <yarp/os/ThreadStats.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ThreadStats.h should be the first include in the file ThreadStats.cpp. In this way you implicitly test that your .h
file contains all includes and the definitions required
@@ -62,6 +62,11 @@ Important Changes | |||
New Features | |||
------------ | |||
|
|||
#### `YARP OS` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The YARP_OS section should be under the Libraries section
* BSD-3-Clause license. See the accompanying LICENSE file for details. | ||
*/ | ||
|
||
#ifndef YARP_THREAD_STATS_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be YARP_OS_THREADSTATS_H
This class implements and extends the statistics used by RateThreadCallbackAdapter
@diegoferigo we should decide what to do with this PR. Honestly I haven't merged it yet because I cannot figure out how to use it, it would be great if you could rebase the PR and add at least some example... |
Closing for now, please reopen if you would like to add some docs or example. |
@drdanz Yes sorry but I didn't find enough time to clean this up. Anyway, if we ever want to add profiling support to YARP, I would go towards solutions like Celtoys/Remotery. It is way more complete than what I implemented in this PR and it allows visualizing the report in the browser 😍 It is used under the hood by Ignition Gazebo. I really like how they implemented because is very compact and uses RAII to scope the profiled section. Resources: |
Referring to #1207, these
ThreadStats
andMultipleThreadStats
classes allow the computation of statistics on threads / periodic functions.ThreadStats
is API compatible with the currentyarp::os::RateThreadCallbackAdapter
class. I successfully validated and compared the methods. The main difference is the function I use to calculate the variance, but no significative differences emerged.Beyond the possible usage inside
RateThread
, these classes might be very useful to debug issues like #1229, especially theMultipleThreadStats
. I developed this class having in mind a clean and easy setup of many profiling points in a whole class codebase.[WIP] I still have minor edits I'd like the last version will implements. For the time being, please let me know if you have any feedback about the current status.
(I'd prefer keeping this out of the next yarp master freeze for the time being)