Provide a snapshot report on all active mutexes. This will be the total time the mutex was locked and the total time spent by threads waiting for the lock to become available. Please note that the values are first copied from the mutex internals and then converted to strings and used to agregate to the output. This extra step is needed because the string manipulations affect the mutex that controls string memory allocation! This does not invalidate the report though as it is intended as a snapshot of mutexs at the point it is called. Returns: None
| Return Type | Function name | Arguments |
|---|---|---|
| void | ReportMutexContention | (hzChain&,bool,) |
Declared in file: hzProcess.h
Defined in file : hzLock.cpp
Function Logic:
Function body:
void ReportMutexContention (hzChain& Z)bool bHtml,
{
// Category: Diagnostics
//
// Provide a snapshot report on all active mutexes. This will be the total time the mutex was locked and the total time spent by threads waiting
// for the lock to become available.
//
// Please note that the values are first copied from the mutex internals and then converted to strings and used to agregate to the output. This
// extra step is needed because the string manipulations affect the mutex that controls string memory allocation! This does not invalidate the
// report though as it is intended as a snapshot of mutexs at the point it is called.
//
// Arguments: 1) Z Reference to chain populated by the report
// 2) bHtml True if the report is to be fashioned as a web page
//
// Returns: None
_hzfunc(__func__) ;
static hzString S = "Untitled" ;
hzXDate now ; // Time now
hzLockRWD* pMtx ; // The lock
double fWait ; // Total nanoseconds wait time
double fInuse ; // Total nanoseconds in-use
double ratio ; // Ratio of in-use time to wait + inuse time
hzString vals[9]; // Lock activity report fields
uint64_t nWaitTotal ; // Total nanoseconds wait time
uint64_t nInuse ; // Total nanoseconds in-use
uint64_t nSpinsTotal ; // Total spins
uint32_t nTriesTotal ; // Total compare and swaps
uint32_t nLockOpsW ; // Total calls to LockWrite
uint32_t nLockOpsR ; // Total calls to LockRead
uint32_t nUnlocks ; // Total Unlocks
char buf[24]; // Mutex name buffer
now.SysDateTime() ;
if (bHtml)
{
Z.Printf("<p><center>Mutex Contention Report at %s</center></p>\n", *now) ;
Z <<
"<div align=\"right\">\n<table width=\"90%\" align=\"center\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" style=\"text-decoration:none; font-family:verdana; font-size:11px; font-weight:normal; color:#000000;\">\n\t<tr>\n\t\t<th>Mutex ID</th>\n\t\t<th>Wr Locks</th>\n\t\t<th>Rd Locks</th>\n\t\t<th>Unlocks</th>\n\t\t<th>Status</th>\n\t\t<th>Spins</th>\n\t\t<th>Tries</th>\n\t\t<th>Wait/Overhead</th>\n\t\t<th>Lock Duration</th>\n\t\t<th>Ratio</th>\n\t\t<th>Name</th>\n\t</tr>\n"
;
}
else
{
Z.Printf("Mutex Contention Report at %s\n", *now) ;
Z.Printf("Mutex ID Wr Locks Rd Locks Unlocks Status Spins Tries Wait/Overhead Lock Duration Ratio Name\n") ;
}
for (pMtx = s_allMtx ; pMtx ; pMtx = pMtx->next)
{
fWait = pMtx->m_WaitTotal ;
fInuse = pMtx->m_Inuse ;
if (fInuse)
ratio = fInuse/(fWait + fInuse) ;
else
ratio = 0.0;
sprintf(buf, "%f", ratio) ;
nLockOpsW = pMtx->m_LockOpsW ;
nLockOpsR = pMtx->m_LockOpsR ;
nUnlocks = pMtx->m_Unlocks ;
nSpinsTotal = pMtx->m_SpinsTotal ;
nTriesTotal = pMtx->m_TriesTotal ;
nWaitTotal = pMtx->m_WaitTotal ;
nInuse = pMtx->m_Inuse ;
vals[0]= FormalNumber(nLockOpsW, 12);
vals[1]= FormalNumber(nLockOpsR, 12);
vals[2]= FormalNumber(nUnlocks, 12);
vals[3]= FormalNumber(nSpinsTotal, 15);
vals[4]= FormalNumber(nTriesTotal, 15);
vals[5]= FormalNumber(nWaitTotal, 15);
vals[6]= FormalNumber(nInuse, 15);
if (bHtml)
{
Z << "\t<tr align=\"right\">\n" ;
Z.Printf("<td>%03d</td>", pMtx->m_Id) ;
Z.Printf("<td>%s</td>", *vals[0]);
Z.Printf("<td>%s</td>", *vals[1]);
Z.Printf("<td>%s</td>", *vals[2]);
Z.Printf("<td>%11u</td>", pMtx->m_lockval) ;
Z.Printf("<td>%s</td>", *vals[3]);
Z.Printf("<td>%s</td>", *vals[4]);
Z.Printf("<td>%s</td>", *vals[5]);
Z.Printf("<td>%s</td>", *vals[6]);
Z.Printf("<td>%s</td>", buf) ;
Z.Printf("<td align=\"left\">%s</td>", *S) ;
Z << "\t</tr>\n" ;
}
else
{
Z.Printf("%03d %s %s %s %llu %s %s %s %s %s %s\n",
pMtx->m_Id, *vals[0],*vals[1],*vals[2],pMtx->m_lockval, *vals[3],*vals[4],*vals[5],*vals[6],buf, *S) ;
}
}
if (bHtml)
Z << "</table>\n" ;
}