pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jesper Pedersen <jesper.pedersen@redhat.com>
To: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: Additional LWLOCK_STATS statistics
Date: Wed, 16 Sep 2015 10:37:43 -0400
Message-ID: <55F97EB7.8080308@redhat.com> (raw)
In-Reply-To: <55F97BF0.70503@redhat.com>
References: <55F82AE1.3010407@redhat.com>
	<CA+TgmoYvgL7rA6jBzn60FUeHhb5TH2xu2m9JKPiXFqbZ5Dyi7w@mail.gmail.com>
	<55F871BA.4060404@redhat.com>
	<CA+TgmoaXdUvA1P=-9PScZU5PMBEYeHw2XD4zF69=_LTU2zs+Wg@mail.gmail.com>
	<55F876CA.8020702@redhat.com>
	<55F97909.3010101@redhat.com>
	<55F97BF0.70503@redhat.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

On 09/16/2015 10:25 AM, Jesper Pedersen wrote:
> Likely from LWLOCK_STATS' own lwlock.c::print_lwlock_stats, which would
> make sense.
>

Version 3 attached, which ignores entries from MainLWLockArray[0].

Best regards,
  Jesper

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

lwstats_v3.patch (text/x-patch, 4.3K) download *** /tmp/NTwtmh_lwlock.c 2015-09-16 10:34:02.955957192 -0400 --- src/backend/storage/lmgr/lwlock.c 2015-09-16 10:32:18.088843413 -0400 *************** *** 163,172 **** --- 163,175 ---- { lwlock_stats_key key; int sh_acquire_count; + int sh_acquire_max; int ex_acquire_count; + int ex_acquire_max; int block_count; int dequeue_self_count; int spin_delay_count; + int max_waiters; } lwlock_stats; static HTAB *lwlock_stats_htab; *************** *** 297,308 **** while ((lwstats = (lwlock_stats *) hash_seq_search(&scan)) != NULL) { ! fprintf(stderr, ! "PID %d lwlock %s %d: shacq %u exacq %u blk %u spindelay %u dequeue self %u\n", ! MyProcPid, LWLockTrancheArray[lwstats->key.tranche]->name, ! lwstats->key.instance, lwstats->sh_acquire_count, ! lwstats->ex_acquire_count, lwstats->block_count, ! lwstats->spin_delay_count, lwstats->dequeue_self_count); } LWLockRelease(&MainLWLockArray[0].lock); --- 300,325 ---- while ((lwstats = (lwlock_stats *) hash_seq_search(&scan)) != NULL) { ! if (lwstats->key.tranche == 0 && lwstats->key.instance < NUM_INDIVIDUAL_LWLOCKS) ! { ! /* We ignore information from MainLWLockArray[0] since it isn't in real use */ ! if (lwstats->key.instance != 0) ! fprintf(stderr, ! "PID %d lwlock %s: shacq %u shmax %u exacq %u exmax %u blk %u spindelay %u dequeue self %u maxw %u\n", ! MyProcPid, MainLWLockNames[lwstats->key.instance], ! lwstats->sh_acquire_count, lwstats->sh_acquire_max, ! lwstats->ex_acquire_count, lwstats->ex_acquire_max, ! lwstats->block_count, lwstats->spin_delay_count, lwstats->dequeue_self_count, ! lwstats->max_waiters); ! } ! else ! fprintf(stderr, ! "PID %d lwlock %s %d: shacq %u shmax %u exacq %u exmax %u blk %u spindelay %u dequeue self %u maxw %u\n", ! MyProcPid, LWLockTrancheArray[lwstats->key.tranche]->name, ! lwstats->key.instance, lwstats->sh_acquire_count, lwstats->sh_acquire_max, ! lwstats->ex_acquire_count, lwstats->ex_acquire_max, ! lwstats->block_count, lwstats->spin_delay_count, lwstats->dequeue_self_count, ! lwstats->max_waiters); } LWLockRelease(&MainLWLockArray[0].lock); *************** *** 330,339 **** --- 347,359 ---- if (!found) { lwstats->sh_acquire_count = 0; + lwstats->sh_acquire_max = 0; lwstats->ex_acquire_count = 0; + lwstats->ex_acquire_max = 0; lwstats->block_count = 0; lwstats->dequeue_self_count = 0; lwstats->spin_delay_count = 0; + lwstats->max_waiters = 0; } return lwstats; } *************** *** 774,779 **** --- 794,802 ---- LWLockQueueSelf(LWLock *lock, LWLockMode mode) { #ifdef LWLOCK_STATS + bool include; + int counter, size; + dlist_iter iter; lwlock_stats *lwstats; lwstats = get_lwlock_stats_entry(lock); *************** *** 792,797 **** --- 815,860 ---- #ifdef LWLOCK_STATS lwstats->spin_delay_count += SpinLockAcquire(&lock->mutex); + + /* + * We scan the list of waiters from the back in order to find + * out how many of the same lock type are waiting for a lock. + * Similar types have the potential to be groupped together. + * + * We also count the number of waiters, including ourself. + */ + include = true; + size = 1; + counter = 1; + + dlist_reverse_foreach(iter, &lock->waiters) + { + if (include) + { + PGPROC *waiter = dlist_container(PGPROC, lwWaitLink, iter.cur); + + if (waiter->lwWaitMode == mode) + counter += 1; + else + include = false; + } + + size += 1; + } + + if (mode == LW_EXCLUSIVE || mode == LW_WAIT_UNTIL_FREE) + { + if (counter > lwstats->ex_acquire_max) + lwstats->ex_acquire_max = counter; + } + else if (mode == LW_SHARED) + { + if (counter > lwstats->sh_acquire_max) + lwstats->sh_acquire_max = counter; + } + + if (size > lwstats->max_waiters) + lwstats->max_waiters = size; #else SpinLockAcquire(&lock->mutex); #endif *************** *** 943,951 **** --- 1006,1022 ---- #ifdef LWLOCK_STATS /* Count lock acquisition attempts */ if (mode == LW_EXCLUSIVE) + { lwstats->ex_acquire_count++; + if (lwstats->ex_acquire_max == 0) + lwstats->ex_acquire_max = 1; + } else + { lwstats->sh_acquire_count++; + if (lwstats->sh_acquire_max == 0) + lwstats->sh_acquire_max = 1; + } #endif /* LWLOCK_STATS */ /*

view thread (16+ messages)  latest in thread

Message-ID: <55F97EB7.8080308@redhat.com>
Permalink:  ../55F97EB7.8080308@redhat.com/
Also on:    postgresql.org/message-id/55F97EB7.8080308@redhat.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: jesper.pedersen@redhat.com
  Subject: Re: Additional LWLOCK_STATS statistics
  In-Reply-To: <55F97EB7.8080308@redhat.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox