📄 print.c
字号:
if (!LOCK_header)
{
FPRINTF (outfile, "Unable to access lock table.\n%s\n",
expanded_lock_filename);
gds__print_status (status_vector);
exit (FINI_OK);
}
LOCK_size_mapped = shmem_data.sh_mem_length_mapped;
/* if we can't read this version - admit there's nothing to say and return. */
if ((LOCK_header->lhb_version != SS_LHB_VERSION) &&
(LOCK_header->lhb_version != CLASSIC_LHB_VERSION))
{
FPRINTF (outfile, "\tUnable to read lock table version %d.\n",
LOCK_header->lhb_version);
exit (FINI_OK);
}
/* Print lock activity report */
if (sw_interactive)
{
prt_lock_activity (outfile, LOCK_header, sw_interactive, sw_seconds, sw_intervals);
exit (FINI_OK);
}
#ifdef NETWARE_386
/* For Netware SuperServer - we will have other threads munging the
* lock table while we are trying to print it over the slow remote
* link. Therefore, ALWAYS insist on a consistent copy before doing
* the dump.
*/
sw_consistency = TRUE;
#endif
if (sw_consistency)
{
/* To avoid changes in the lock file while we are dumping it - make
* a local buffer, lock the lock file, copy it, then unlock the
* lock file to let processing continue. Printing of the lock file
* will continue from the in-memory copy.
*/
header = (LHB) gds__alloc (LOCK_header->lhb_length);
if (!header)
{
FPRINTF (outfile, "Insufficient memory for consistent lock statistics.\n");
#ifndef NETWARE_386
FPRINTF (outfile, "Try omitting the -c switch.\n");
#endif
exit (FINI_OK);
}
ISC_mutex_lock (LOCK_header->lhb_mutex);
memcpy (header, LOCK_header, LOCK_header->lhb_length);
ISC_mutex_unlock (LOCK_header->lhb_mutex);
LOCK_header = header;
}
/* Print lock header block */
FPRINTF (outfile, "LOCK_HEADER BLOCK\n");
FPRINTF (outfile, "\tVersion: %d, Active owner: %6d, Length: %6d, Used: %6d\n",
LOCK_header->lhb_version, LOCK_header->lhb_active_owner,
LOCK_header->lhb_length, LOCK_header->lhb_used);
#ifdef MANAGER_PROCESS
manager_pid = 0;
if (LOCK_header->lhb_manager)
{
manager = (OWN) ABS_PTR (LOCK_header->lhb_manager);
manager_pid = manager->own_process_id;
}
FPRINTF (outfile, "\tLock manager pid: %6d\n", manager_pid);
#endif
FPRINTF (outfile, "\tSemmask: 0x%X, Flags: 0x%04X\n",
LOCK_header->lhb_mask, LOCK_header->lhb_flags);
FPRINTF (outfile, "\tEnqs: %6d, Converts: %6d, Rejects: %6d, Blocks: %6d\n",
LOCK_header->lhb_enqs, LOCK_header->lhb_converts,
LOCK_header->lhb_denies, LOCK_header->lhb_blocks);
FPRINTF (outfile, "\tDeadlock scans: %6d, Deadlocks: %6d, Scan interval: %3d\n",
LOCK_header->lhb_scans, LOCK_header->lhb_deadlocks, LOCK_header->lhb_scan_interval);
FPRINTF (outfile, "\tAcquires: %6d, Acquire blocks: %6d, Spin count: %3d\n",
LOCK_header->lhb_acquires, LOCK_header->lhb_acquire_blocks, LOCK_header->lhb_acquire_spins);
if (LOCK_header->lhb_acquire_blocks)
{
bottleneck = (float) ((100. * LOCK_header->lhb_acquire_blocks) / LOCK_header->lhb_acquires);
FPRINTF (outfile, "\tMutex wait: %3.1f%%\n", bottleneck);
}
else
FPRINTF (outfile, "\tMutex wait: 0.0%%\n");
hash_total_count = hash_max_count = 0;
hash_min_count = 10000000;
for (slot = LOCK_header->lhb_hash, i = 0; i < LOCK_header->lhb_hash_slots; slot++, i++)
{
hash_lock_count = 0;
for (que = (SRQ) ABS_PTR (slot->srq_forward); que != slot;
que = (SRQ) ABS_PTR (que->srq_forward))
{
++hash_total_count;
++hash_lock_count;
}
if (hash_lock_count < hash_min_count)
hash_min_count = hash_lock_count;
if (hash_lock_count > hash_max_count)
hash_max_count = hash_lock_count;
}
FPRINTF (outfile, "\tHash slots: %4d, ", LOCK_header->lhb_hash_slots);
FPRINTF (outfile, "Hash lengths (min/avg/max): %4d/%4d/%4d\n",
hash_min_count, (hash_total_count / LOCK_header->lhb_hash_slots), hash_max_count);
if (LOCK_header->lhb_secondary != LHB_PATTERN)
{
shb = (SHB) ABS_PTR (LOCK_header->lhb_secondary);
FPRINTF (outfile, "\tRemove node: %6d, Insert queue: %6d, Insert prior: %6d\n",
shb->shb_remove_node, shb->shb_insert_que, shb->shb_insert_prior);
}
prt_que (outfile, LOCK_header, "\tOwners", &LOCK_header->lhb_owners,
OFFSET (OWN, own_lhb_owners));
prt_que (outfile, LOCK_header, "\tFree owners", &LOCK_header->lhb_free_owners,
OFFSET (OWN, own_lhb_owners));
prt_que (outfile, LOCK_header, "\tFree locks", &LOCK_header->lhb_free_locks,
OFFSET (LBL, lbl_lhb_hash));
prt_que (outfile, LOCK_header, "\tFree requests", &LOCK_header->lhb_free_requests,
OFFSET (LRQ, lrq_lbl_requests));
/* Print lock ordering option */
FPRINTF (outfile, "\tLock Ordering: %s\n",
(LOCK_header->lhb_flags & LHB_lock_ordering) ? "Enabled" : "Disabled");
FPRINTF (outfile, "\n");
/* Print known owners */
if (sw_owners)
{
#ifdef SOLARIS_MT
/* The Lock Starvation recovery code on Solaris rotates the owner
queue once per acquire. This makes it difficult to read the
printouts when multiple runs are made. So we scan the list
of owners once to find the lowest owner_id, and start the printout
from there. */
PTR least_owner_id = 0x7FFFFFFF;
SRQ least_owner_ptr = &LOCK_header->lhb_owners;
QUE_LOOP (LOCK_header->lhb_owners, que)
{
OWN this_owner;
this_owner = (OWN)((UCHAR*) que - OFFSET (OWN, own_lhb_owners));
if (REL_PTR (this_owner) < least_owner_id)
{
least_owner_id = REL_PTR (this_owner);
least_owner_ptr = que;
}
}
que = least_owner_ptr;
do
{
if (que != &LOCK_header->lhb_owners)
prt_owner (outfile, LOCK_header,
(OWN)((UCHAR*) que - OFFSET (OWN, own_lhb_owners)),
sw_requests, sw_waitlist);
que = QUE_NEXT ((*que));
}
while (que != least_owner_ptr);
#else
QUE_LOOP (LOCK_header->lhb_owners, que)
{
prt_owner (outfile, LOCK_header,
(OWN)((UCHAR*) que - OFFSET (OWN, own_lhb_owners)),
sw_requests, sw_waitlist);
}
#endif /* SOLARIS_MT */
}
/* Print known locks */
if (sw_locks || sw_series)
for (slot = LOCK_header->lhb_hash, i = 0; i < LOCK_header->lhb_hash_slots;
slot++, i++)
for (que = (SRQ) ABS_PTR (slot->srq_forward); que != slot;
que = (SRQ) ABS_PTR (que->srq_forward))
prt_lock (outfile, LOCK_header,
(LBL)((UCHAR*) que - OFFSET (LBL, lbl_lhb_hash)),
sw_series);
if (sw_history)
prt_history (outfile, LOCK_header, LOCK_header->lhb_history, "History");
if (LOCK_header->lhb_secondary != LHB_PATTERN)
prt_history (outfile, LOCK_header, shb->shb_history, "Event log");
#if !(defined WIN_NT || defined OS2_ONLY || defined NETWARE_386)
if (!sw_nobridge)
{
FPRINTF (outfile, "\nBRIDGE RESOURCES\n\n");
V3_lock_print (orig_argc, orig_argv);
}
#endif
if (header)
gds__free (header);
exit (FINI_OK);
}
static void prt_lock_activity (
OUTFILE outfile,
LHB header,
USHORT flag,
USHORT seconds,
USHORT intervals)
{
/**************************************
*
* p r t _ l o c k _ a c t i v i t y
*
**************************************
*
* Functional description
* Print a time-series lock activity report
*
**************************************/
struct tm d;
ULONG clock, i;
struct lhb base, prior;
ULONG factor;
clock = time (NULL);
d = *localtime (&clock);
FPRINTF (outfile, "%02d:%02d:%02d ", d.tm_hour, d.tm_min, d.tm_sec);
if (flag & SW_I_ACQUIRE)
FPRINTF (outfile, "acquire/s acqwait/s %%acqwait acqrtry/s rtrysuc/s ");
if (flag & SW_I_OPERATION)
FPRINTF (outfile, "enqueue/s convert/s downgrd/s dequeue/s readata/s wrtdata/s qrydata/s ");
if (flag & SW_I_TYPE)
FPRINTF (outfile, " dblop/s rellop/s pagelop/s tranlop/s relxlop/s idxxlop/s misclop/s ");
if (flag & SW_I_WAIT)
{
FPRINTF (outfile, " wait/s reject/s timeout/s blckast/s dirsig/s indsig/s ");
FPRINTF (outfile, " wakeup/s dlkscan/s deadlck/s avlckwait(msec)");
}
FPRINTF (outfile, "\n");
base = *header;
prior = *header;
if (intervals == 0)
memset (&base, 0, sizeof (base));
for (i = 0; i < intervals; i++)
{
#ifdef WIN_NT
Sleep ((DWORD) seconds * 1000);
#else
#ifdef NETWARE_386
delay (seconds * 1000);
#else
sleep (seconds);
#endif
#endif
clock = time (NULL);
d = *localtime (&clock);
FPRINTF (outfile, "%02d:%02d:%02d ", d.tm_hour, d.tm_min, d.tm_sec);
if (flag & SW_I_ACQUIRE)
{
FPRINTF (outfile, "%9d %9d %9d %9d %9d ",
(header->lhb_acquires - prior.lhb_acquires) / seconds,
(header->lhb_acquire_blocks - prior.lhb_acquire_blocks) / seconds,
(header->lhb_acquires - prior.lhb_acquires) ?
(100 * (header->lhb_acquire_blocks - prior.lhb_acquire_blocks)) /
(header->lhb_acquires - prior.lhb_acquires) : 0,
(header->lhb_acquire_retries - prior.lhb_acquire_retries) / seconds,
(header->lhb_retry_success - prior.lhb_retry_success) / seconds);
prior.lhb_acquires = header->lhb_acquires;
prior.lhb_acquire_blocks = header->lhb_acquire_blocks;
prior.lhb_acquire_retries = header->lhb_acquire_retries;
prior.lhb_retry_success = header->lhb_retry_success;
}
if (flag & SW_I_OPERATION)
{
FPRINTF (outfile, "%9d %9d %9d %9d %9d %9d %9d ",
(header->lhb_enqs - prior.lhb_enqs) / seconds,
(header->lhb_converts - prior.lhb_converts) / seconds,
(header->lhb_downgrades - prior.lhb_downgrades) / seconds,
(header->lhb_deqs - prior.lhb_deqs) / seconds,
(header->lhb_read_data - prior.lhb_read_data) / seconds,
(header->lhb_write_data - prior.lhb_write_data) / seconds,
(header->lhb_query_data - prior.lhb_query_data) / seconds);
prior.lhb_enqs = header->lhb_enqs;
prior.lhb_converts = header->lhb_converts;
prior.lhb_downgrades = header->lhb_downgrades;
prior.lhb_deqs = header->lhb_deqs;
prior.lhb_read_data = header->lhb_read_data;
prior.lhb_write_data = header->lhb_write_data;
prior.lhb_query_data = header->lhb_query_data;
}
if (flag & SW_I_TYPE)
{
FPRINTF (outfile, "%9d %9d %9d %9d %9d %9d %9d ",
(header->lhb_operations [LCK_database] - prior.lhb_operations [LCK_database]) / seconds,
(header->lhb_operations [LCK_relation] - prior.lhb_operations [LCK_relation]) / seconds,
(header->lhb_operations [LCK_bdb] - prior.lhb_operations [LCK_bdb]) / seconds,
(header->lhb_operations [LCK_tra] - prior.lhb_operations [LCK_tra]) / seconds,
(header->lhb_operations [LCK_rel_exist] - prior.lhb_operations [LCK_rel_exist]) / seconds,
(header->lhb_operations [LCK_idx_exist] - prior.lhb_operations [LCK_idx_exist]) / seconds,
(header->lhb_operations [0] - prior.lhb_operations [0]) / seconds);
prior.lhb_operations [LCK_database] = header->lhb_operations [LCK_database];
prior.lhb_operations [LCK_relation] = header->lhb_operations [LCK_relation];
prior.lhb_operations [LCK_bdb] = header->lhb_operations [LCK_bdb];
prior.lhb_operations [LCK_tra] = header->lhb_operations [LCK_tra];
prior.lhb_operations [LCK_rel_exist] = header->lhb_operations [LCK_rel_exist];
prior.lhb_operations [LCK_idx_exist] = header->lhb_operations [LCK_idx_exist];
prior.lhb_operations [0] = header->lhb_operations [0];
}
if (flag & SW_I_WAIT)
{
FPRINTF (outfile, "%9d %9d %9d %9d %9d %9d %9d %9d %9d %9d ",
(header->lhb_waits - prior.lhb_waits) / seconds,
(header->lhb_denies - prior.lhb_denies) / seconds,
(header->lhb_timeouts - prior.lhb_timeouts) / seconds,
(header->lhb_blocks - prior.lhb_blocks) / seconds,
(header->lhb_direct_sigs - prior.lhb_direct_sigs) / seconds,
(header->lhb_indirect_sigs - prior.lhb_indirect_sigs) / seconds,
(header->lhb_wakeups - prior.lhb_wakeups) / seconds,
(header->lhb_scans - prior.lhb_scans) / seconds,
(header->lhb_deadlocks - prior.lhb_deadlocks) / seconds,
(header->lhb_waits - prior.lhb_waits) ?
(header->lhb_wait_time - prior.lhb_wait_time) / (header->lhb_waits - prior.lhb_waits) : 0);
prior.lhb_waits = header->lhb_waits;
prior.lhb_denies = header->lhb_denies;
prior.lhb_timeouts = header->lhb_timeouts;
prior.lhb_blocks = header->lhb_blocks;
prior.lhb_direct_sigs = header->lhb_direct_sigs;
prior.lhb_indirect_sigs = header->lhb_indirect_sigs;
prior.lhb_wakeups = header->lhb_wakeups;
prior.lhb_scans = header->lhb_scans;
prior.lhb_deadlocks = header->lhb_deadlocks;
prior.lhb_wait_time = header->lhb_wait_time;
}
FPRINTF (outfile, "\n");
}
factor = seconds * intervals;
if (factor < 1)
factor = 1;
FPRINTF (outfile, "\nAverage: ");
if (flag & SW_I_ACQUIRE)
{
FPRINTF (outfile, "%9d %9d %9d %9d %9d ",
(header->lhb_acquires - base.lhb_acquires) / (factor),
(header->lhb_acquire_blocks - base.lhb_acquire_blocks) / (factor),
(header->lhb_acquires - base.lhb_acquires) ?
(100 * (header->lhb_acquire_blocks - base.lhb_acquire_blocks)) /
(header->lhb_acquires - base.lhb_acquires) : 0,
(header->lhb_acquire_retries - base.lhb_acquire_retries) / (factor),
(header->lhb_retry_success - base.lhb_retry_success) / (factor));
}
if (flag & SW_I_OPERATION)
{
FPRINTF (outfile, "%9d %9d %9d %9d %9d %9d %9d ",
(header->lhb_enqs - base.lhb_enqs) / (factor),
(header->lhb_converts - base.lhb_converts) / (factor),
(header->lhb_downgrades - base.lhb_downgrades) / (factor),
(header->lhb_deqs - base.lhb_deqs) / (factor),
(header->lhb_read_data - base.lhb_read_data) / (factor),
(header->lhb_write_data - base.lhb_write_data) / (factor),
(header->lhb_query_data - base.lhb_query_data) / (factor));
}
if (flag & SW_I_TYPE)
{
FPRINTF (outfile, "%9d %9d %9d %9d %9d %9d %9d ",
(header->lhb_operations [LCK_database] - base.lhb_operations [LCK_database]) / (factor),
(header->lhb_operations [LCK_relation] - base.lhb_operations [LCK_relation]) / (factor),
(header->lhb_operations [LCK_bdb] - base.lhb_operations [LCK_bdb]) / (factor),
(header->lhb_operations [LCK_tra] - base.lhb_operations [LCK_tra]) / (factor),
(header->lhb_operations [LCK_rel_exist] - base.lhb_operations [LCK_rel_exist]) / (factor),
(header->lhb_operations [LCK_idx_exist] - base.lhb_operations [LCK_idx_exist]) / (factor),
(header->lhb_operations [0] - base.lhb_operations [0]) / (factor));
}
if (flag & SW_I_WAIT)
{
FPRINTF (outfile, "%9d %9d %9d %9d %9d %9d %9d %9d %9d %9d ",
(header->lhb_waits - base.lhb_waits) / (factor),
(header->lhb_denies - base.lhb_denies) / (factor),
(header->lhb_timeouts - base.lhb_timeouts) / (factor),
(header->lhb_blocks - base.lhb_blocks) / (factor),
(header->lhb_direct_sigs - base.lhb_direct_sigs) / (factor),
(header->lhb_indirect_sigs - base.lhb_indirect_sigs) / (factor),
(header->lhb_wakeups - base.lhb_wakeups) / (factor),
(header->lhb_scans - base.lhb_scans) / (factor),
(header->lhb_deadlocks - base.lhb_deadlocks) / (factor),
(header->lhb_waits - base.lhb_waits) ?
(header->lhb_wait_time - base.lhb_wait_time) / (header->lhb_waits - base.lhb_waits) : 0);
}
FPRINTF (outfile, "\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -