Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8032473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:23:53+00:00 2026-06-05T01:23:53+00:00

I would like to know how to profile a pthread mutex to see if

  • 0

I would like to know how to profile a pthread mutex to see if there are any locking contention points in my code. (who likes contentious code, right? 🙂 I know how to do a more general profiling of the code, as I mention here. But I would like to know if there are any tools or options available to be able to profile mutex locking that would provide metrics/stats about mutex locking contentions to see if I have any problem areas.

Here’s some background and context:

Recently I worked on an embedded C++ project using a Cavium Octeon CPU. The Octeon SDK implements mutex style synchronization using spinlocks. Looking through the Octeon documentation, I came across a way to profile the spinlocks to be able to see how many times each spinlock had to spin while waiting for the lock to become available. To use this I had to do a conditional compile and then it would increment a counter each time the spinlock spun, then I could query the spinner wait value. So, what I did was to encapsulate the spinlock and added the ability to dump the spinlock spinner wait value for all of the spinlocks used in the system. The actual value didnt mean much, but there were a few that had really high values compared to the rest, and I focused on reducing the contention for those.

I know this is probably quite easy for spinlocks, since its just a counter per spin, but reading through the related pthread man pages and header files I havent found anything similar, is there something available for pthread mutex?

I would really like to avoid having to do something hacky like taking the time before and after each lock.

PS: What’s the plural of mutex? mutexes, muteces, mutexi, muti??? Mutexes never sounded right to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:23:56+00:00Added an answer on June 5, 2026 at 1:23 am

    The valgrind tool drd lets you specify a limit on how long a lock should be waited on before reporting an error.

    This site mentions drd and also mentions their own tool called mutrace which looks like the kind of tool you’re after. It tells you:

    • how many times a mutex was locked
    • how many times the mutex owning thread changed
    • how many times a mutex was contended (already locked when a lock request was made)
    • various stats on the duration a mutex was locked for

    e.g.

    mutrace: 10 most contended mutexes:
    
     Mutex #   Locked  Changed    Cont. tot.Time[ms] avg.Time[ms] max.Time[ms]       Type
          35   368268      407      275      120,822        0,000        0,894     normal
           5   234645      100       21       86,855        0,000        0,494     normal
          26   177324       47        4       98,610        0,001        0,150     normal
          19    55758       53        2       23,931        0,000        0,092     normal
          53      106       73        1        0,769        0,007        0,160     normal
          25    15156       70        1        6,633        0,000        0,019     normal
           4      973       10        1        4,376        0,004        0,174     normal
          75       68       62        0        0,038        0,001        0,004     normal
           9     1663       52        0        1,068        0,001        0,412     normal
           3   136553       41        0       61,408        0,000        0,281     normal
         ...      ...      ...      ...          ...          ...          ...        ...
    
    mutrace: Total runtime 9678,142 ms.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know the best way to profile app code on OS
I would just like to know if there is any advantage to having a
Would like to know the c# code to actually retrieve the IP type: Static
I would like to know if there's an efficient algorithm to find the greatest
I would like to know how I can add the following code to my
I am using the entity framework (code first). I would like to know if
Hi everyone i would like to know that how to make the provisioning profile
i would like know some reference. I know i can googling it. but prefer
Would like to know what a programmer should know to become a good at
Would like to know how to integarate cruise control with maven? Cruise Control comes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.