weixin_39789979
weixin_39789979
2021-01-09 11:48

Add optional tracing to sleep manager lock/unlock

Description

Add tracing output to console to track when drivers lock and unlock deep sleep. Tracing output is enabled by configuring the 'MBED_SLEEP_TRACING_ENABLED ' at compile time.

  • Wrapped sleep_manager_lock/sleep_manager_unlock in a macro to conditionally call tracing functions when 'MBED_SLEEP_TRACING_ENABLED' is set.
  • Define a global structure to track driver names and how many locks they hold in the sleep manager.

Status

IN DEVELOPMENT

Todos

  • [ ] Tests
  • [ ] Documentation

Steps to test or reproduce

Define the SLEEP_PROFILING_ENABLED macro in an application, eg:

json
{
  "config": {
    "sleep_profiling_enabled": {
      "value": 1,
      "macro_name": "SLEEP_PROFILING_ENABLED"
    }
  }
}

cause deep sleep to be locked/unlock by calling a driver that locks it:

c++
void trigger(){}
int main()
{
  Timer* timer = new Timer();
  timer->start();

  Ticker* ticker = new Ticker();
  ticker->attach(&trigger, 500);

  sleep();
}

output should show:


LOCK: Timer.cpp, ln: 50, lock count: 1
LOCK: Ticker.h, ln: 120, lock count: 2
LOCK: mbed_rtx_idle.cpp, ln: 227, lock count: 3
UNLOCK: mbed_rtx_idle.cpp, ln: 229, lock count: 2
[id: Timer., count: 1]
[id: Ticker, count: 1]

该提问来源于开源项目:ARMmbed/mbed-os

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

31条回答

  • weixin_39734048 weixin_39734048 4月前

    Test : SUCCESS

    Build number : 1104 Test logs :http://mbed-os-logs.s3-website-us-west-1.amazonaws.com/?prefix=logs/6142/1104

    点赞 评论 复制链接分享
  • weixin_39734048 weixin_39734048 4月前

    Exporter Build : FAILURE

    Build number : 2363 Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/exporter/6142/

    点赞 评论 复制链接分享
  • weixin_39768371 weixin_39768371 4月前

    Building on comment, it'd be useful to have the MBED_SLEEP_STATS_ENABLED side as well. If you're interested this would require adding a mbed_stats_deep_sleep_get sort of function that fills out a struct with relevant data. Here's the heap/stack stats for example: https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_stats.h

    This would be useful for tools that report stats on their own tick and profiling tests in the CI.

    cc ,

    We are dangerously close to the code freeze, lets park this one for now.

    点赞 评论 复制链接分享
  • weixin_39768371 weixin_39768371 4月前

    Guys the code freeze is coming please rereview:

    点赞 评论 复制链接分享
  • weixin_39789979 weixin_39789979 4月前

    /morph build

    点赞 评论 复制链接分享
  • weixin_39734048 weixin_39734048 4月前

    Build : SUCCESS

    Build number : 1295 Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6142/ ## Triggering tests /morph test /morph uvisor-test /morph export-build /morph mbed2-build

    点赞 评论 复制链接分享
  • weixin_39734048 weixin_39734048 4月前

    Exporter Build : SUCCESS

    Build number : 956 Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/exporter/6142/

    点赞 评论 复制链接分享
  • weixin_39734048 weixin_39734048 4月前

    Test : FAILURE

    Build number : 1081 Test logs :http://mbed-os-logs.s3-website-us-west-1.amazonaws.com/?prefix=logs/6142/1081

    点赞 评论 复制链接分享
  • weixin_39768371 weixin_39768371 4月前

    please re-re-review :)

    点赞 评论 复制链接分享
  • weixin_39789979 weixin_39789979 4月前

    Urgh, why did mbed_sleep header get moved again.

    点赞 评论 复制链接分享
  • weixin_39768371 weixin_39768371 4月前

    Urgh, why did mbed_sleep header get moved again.

    Ups, sorry! That would be me...

    点赞 评论 复制链接分享
  • weixin_39789979 weixin_39789979 4月前

    Heh, should all be sorted now, as indicated fixing merge conflicts is not my forte.

    点赞 评论 复制链接分享
  • weixin_39789979 weixin_39789979 4月前

    /morph build

    点赞 评论 复制链接分享
  • weixin_39734048 weixin_39734048 4月前

    Build : SUCCESS

    Build number : 1316 Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6142/ ## Triggering tests /morph test /morph uvisor-test /morph export-build /morph mbed2-build

    点赞 评论 复制链接分享
  • weixin_39824898 weixin_39824898 4月前

    Is the intention for this to make it into 5.8-rc1? I'm reading conflicting message from you: https://github.com/ARMmbed/mbed-os/pull/6142#issuecomment-369229241 vs https://github.com/ARMmbed/mbed-os/pull/6142#issuecomment-368811886 Marking this as 5.8 for now.

    -arm A friendly reminder that only maintainers should be triggering builds, especially this close to generating a release PR.

    点赞 评论 复制链接分享
  • weixin_39824898 weixin_39824898 4月前

    -arm Do you run tests or at least do a sanity compilation in between commits? I'm wondering how those merge errors got into the history in the first place, especially since they're so far apart from each other (2 days vs 6 days).

    点赞 评论 复制链接分享
  • weixin_39789979 weixin_39789979 4月前

    No, I rebased all seven commits about 1-2 hours ago, the merge conflict happened in one of the earlier ones and I forgot to commit the manual merge before continuing. The conflict only happened ~3 hours ago when https://github.com/ARMmbed/mbed-os/pull/6230 got merged and the file I was committing to got moved around.

    点赞 评论 复制链接分享
  • weixin_39734048 weixin_39734048 4月前

    Exporter Build : SUCCESS

    Build number : 976 Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/exporter/6142/

    点赞 评论 复制链接分享
  • weixin_39768371 weixin_39768371 4月前

    Yes, it's 5.8 the https://github.com/ARMmbed/mbed-os/pull/6142#issuecomment-368811886 was about Chrises comment and adding extra features.

    点赞 评论 复制链接分享
  • weixin_39824898 weixin_39824898 4月前
    • Any final words on this PR while there's still a chance?
    点赞 评论 复制链接分享
  • weixin_39734048 weixin_39734048 4月前

    Test : FAILURE

    Build number : 1100 Test logs :http://mbed-os-logs.s3-website-us-west-1.amazonaws.com/?prefix=logs/6142/1100

    点赞 评论 复制链接分享
  • weixin_39768371 weixin_39768371 4月前

    /morph build

    点赞 评论 复制链接分享
  • weixin_39734048 weixin_39734048 4月前

    Build : SUCCESS

    Build number : 1319 Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6142/ ## Triggering tests /morph test /morph uvisor-test /morph export-build /morph mbed2-build

    点赞 评论 复制链接分享
  • weixin_39734048 weixin_39734048 4月前

    Exporter Build : SUCCESS

    Build number : 980 Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/exporter/6142/

    点赞 评论 复制链接分享
  • weixin_39600837 weixin_39600837 4月前

    It would be nice if the print function was configurable, so that e.g. tr_info() could be used instead of printf()

    点赞 评论 复制链接分享
  • weixin_39946355 tomorrow-77 4月前

    It would be nice if the print function was configurable, so that e.g. tr_info() could be used instead of printf()

    Had the same comment to be added here. is working on tracing lib, but that might take a while. we have some logs in this codebase in some parts (not yet unified), but rather than own config would be easier to align this on something that it's been already used, then the new tracing lib would come and refactor this? -arm please chat with

    点赞 评论 复制链接分享
  • weixin_39789979 weixin_39789979 4月前

    Yes, the intention was to use the tracing library with this, which as far as I can tell should just require replacing the printfs with the trace macros/functions that get added.

    点赞 评论 复制链接分享
  • weixin_39614146 weixin_39614146 4月前

    Printing filename and line number was part of the logging implementation and was removed recently for string based implementation, will that be required here?

    点赞 评论 复制链接分享
  • weixin_39789979 weixin_39789979 4月前

    The line number isn't important and the filename output isn't required as part of the interface. The FILE macro is used as an identifier to track which drivers have called the lock/unlock functions, so it isn't required as part of the interface as it's already accessible when printing the lock statistics.

    点赞 评论 复制链接分享
  • weixin_39600837 weixin_39600837 4月前

    For consistency across mbed-os, the macro could be named MBED_SLEEP_STATS_ENABLED, similarly to:

    
    MBED_TRAP_ERRORS_ENABLED
    MBED_HEAP_STATS_ENABLED
    MBED_STACK_STATS_ENABLED
    

    It would be also helpful if sleep_tracker_print_stats() could be used manually, otherwise there often may be an unmanagable stream of

    
    LOCK: mbed_wait_api_rtos.cpp, ln: 42, lock count: 3
    UNLOCK: mbed_wait_api_rtos.cpp, ln: 44, lock count: 2
    [id: Timer., count: 1]
    [id: Ticker, count: 1]
    
    点赞 评论 复制链接分享
  • weixin_39866774 weixin_39866774 4月前

    We currently have a distinction between "tracing" and "stats". "Tracing" utilities continuously log data on relevant events, whereas "stats" utilities allow you to manually grab snapshots about the current state.

    Looking at this pr, MBED_SLEEP_TRACING_ENABLED would probably be a better config name.

    Building on comment, it'd be useful to have the MBED_SLEEP_STATS_ENABLED side as well. If you're interested this would require adding a mbed_stats_deep_sleep_get sort of function that fills out a struct with relevant data. Here's the heap/stack stats for example: https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_stats.h

    This would be useful for tools that report stats on their own tick and profiling tests in the CI.

    cc ,

    点赞 评论 复制链接分享

相关推荐