Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nDK2S-0008K8-68 for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jan 2022 05:43:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nDK2Q-0002k3-Mq for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jan 2022 05:43:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nDK2Q-0002jt-Ar for pgsql-hackers@lists.postgresql.org; Fri, 28 Jan 2022 05:43:10 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nDK2N-00030L-Ic for pgsql-hackers@lists.postgresql.org; Fri, 28 Jan 2022 05:43:09 +0000 Received: by mail-pj1-x102c.google.com with SMTP id h12so5509196pjq.3 for ; Thu, 27 Jan 2022 21:43:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=WlHbuUFpweQtxYOg3YoLEiHLamW8AB4U2PJcSAUURMY=; b=WaXFdCt+3PgHifRDsBolEz3U/xQl7stbt8c2JS08okiesdhonjEjQEZYgPSZSpRbJh GdcpQjppiWaGnNPGgPjU+SK+t1A2uzr1+Vel/5rN2JuVrrvJ7ISk+3l5kZ5wCZRy90oy +0i+08dV9p36QaHYPE+XGPcZLVBFbns5P4B1b8zhAk1Va8ZJ4xmPNVOioGIwHXC/Pnhn 8QifsTFZ/w7ZH9NbCgzWSOQBRhR4L4z95XMXpVH6Ac0sOd6S2AnlpQcmqayfbpy2MROq 9tpm3SnsFHR5EMys2DiX9A58QbuTyaJnLisXVwyLqejXIamlPhrVbRcNByh5QvUQifLY fqOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=WlHbuUFpweQtxYOg3YoLEiHLamW8AB4U2PJcSAUURMY=; b=R2OCMNhga7UOS3FrZxcKom2Fdv10M/ywJlDjT7KvByXyuxF5Rw7hi6eM0A+niRdimQ aGYRVZjm8pR7u1JRahnAc/wKXRq0eggH5kb5z2VNkXGbvUA7F0ivcnZ9vW+k74B8/evb eCpI4SVXUAOovBz1QneBWADEMlPn6CuK7fILtdpecpSq/L3+oeHinzCFs3P+qnWM5MOh p0Oq2ZHjMX4vu8LN3dO3dppnpv5T4ptJC6/kO732bbZDVTQw3KGtrdEg3nP8WUqlDsjC UF65wQzcfUGbsLlbqFxB+3tBhQVvmHRgyMQI5Vmx2IqWRiaIaxG21C5Sq/lW6ymgnv91 XVSw== X-Gm-Message-State: AOAM533YpKSS6OVfOIqR+ekkmMyRzByoip/PAf5RbuhfLMwtVQDYZnqR EqB6kPDtyBg5b5PLVRwUSVnlG81Etw4= X-Google-Smtp-Source: ABdhPJwwaO2FfsYtYdTwcJ10CDg5ALCOWTBryJyF7w6CtFtnRkAdu7z6Y6AeFBKjew2vbGU7F/uAbg== X-Received: by 2002:a17:90b:4f4c:: with SMTP id pj12mr17926383pjb.102.1643348586532; Thu, 27 Jan 2022 21:43:06 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id m21sm7914652pfk.26.2022.01.27.21.43.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jan 2022 21:43:05 -0800 (PST) Date: Fri, 28 Jan 2022 14:43:03 +0900 (JST) Message-Id: <20220128.144303.648220302965090533.horikyota.ntt@gmail.com> To: rjuju123@gmail.com Cc: sergey.dudoladov@gmail.com, pgsql-hackers@lists.postgresql.org, kuntalghosh.2007@gmail.com, rafia.pghackers@gmail.com Subject: Re: Add connection active, idle time to pg_stat_activity From: Kyotaro Horiguchi In-Reply-To: <20220128.143631.654438319295147801.horikyota.ntt@gmail.com> References: <20220127123656.etovnhimr5sgp37f@jrouhaud> <20220128.143631.654438319295147801.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk At Fri, 28 Jan 2022 14:36:31 +0900 (JST), Kyotaro Horiguchi wrote in > Hi. > > At Thu, 27 Jan 2022 20:36:56 +0800, Julien Rouhaud wrote in > > On Thu, Jan 27, 2022 at 11:43:26AM +0100, Sergey Dudoladov wrote: > > > > > > Per agreement with Rafia I have reworked the patch in the past days. > > > The new version 6 is now ready for review. > > > > Great, thanks a lot Sergey! > > > > The cfbot is happy with this new version: > > https://cirrus-ci.com/github/postgresql-cfbot/postgresql/commitfest/36/3405 > > I think we can easily add the duration of the current state to the two > in pg_stat_get_activity and it would offer better information. > > > if (beentry->st_state == STATE_RUNNING || > beentry->st_state == STATE_FASTPATH) > - pgstat_count_conn_active_time((PgStat_Counter) secs * 1000000 + usecs); > + { > + pgstat_count_conn_active_time((PgStat_Counter) usecs_diff); > + beentry->st_total_active_time += usecs_diff; > + } > > The two lines operates exactly the same way on variables with slightly > different behavior. pgStatActiveTime is reported at transaction end > and reset at every tabstat reporting. st_total_active_time is reported > immediately and reset at session end. Since we do the latter, the > first can be omitted by remembering the last values for the local > variables at every reporting. This needs additional two exporting Of course it's typo(?) of "values of the shared variables". Sorry for the mistake. > function in pgstatfuncs like pgstat_get_my_queryid so others might > think differently. > > The write operation to beentry needs to be enclosed by > PGSTAT_BEGIN/END_WRITE_ACTIVITY(). In that perspective, it would be > better to move that writes to the PGSTAT_WRITE_ACTIVITY section just > below. regards. -- Kyotaro Horiguchi NTT Open Source Software Center