]> granicus.if.org Git - pgbouncer/commitdiff
Add a maxwait microseconds column to SHOW POOLS.
authorTerrence Cole <terrence.cole@procore.com>
Fri, 9 Jun 2017 18:39:31 +0000 (11:39 -0700)
committerTerrence Cole <terrence.cole@procore.com>
Fri, 9 Jun 2017 19:06:59 +0000 (12:06 -0700)
src/admin.c

index cdbbaab529e84932d7e40b3c3c3ad3043b945ce9..02c7ebb338588554e5ef2977e7e66299e2008078 100644 (file)
@@ -778,6 +778,7 @@ static bool admin_show_pools(PgSocket *admin, const char *arg)
        PktBuf *buf;
        PgSocket *waiter;
        usec_t now = get_cached_time();
+       usec_t max_wait;
        struct CfValue cv;
        int pool_mode;
 
@@ -788,18 +789,19 @@ static bool admin_show_pools(PgSocket *admin, const char *arg)
                admin_error(admin, "no mem");
                return true;
        }
-       pktbuf_write_RowDescription(buf, "ssiiiiiiiis",
+       pktbuf_write_RowDescription(buf, "ssiiiiiiiiis",
                                    "database", "user",
                                    "cl_active", "cl_waiting",
                                    "sv_active", "sv_idle",
                                    "sv_used", "sv_tested",
                                    "sv_login", "maxwait",
-                                   "pool_mode");
+                                   "maxwait_us", "pool_mode");
        statlist_for_each(item, &pool_list) {
                pool = container_of(item, PgPool, head);
                waiter = first_socket(&pool->waiting_client_list);
+               max_wait = (waiter && waiter->query_start) ? now - waiter->query_start : 0;
                pool_mode = pool_pool_mode(pool);
-               pktbuf_write_DataRow(buf, "ssiiiiiiiis",
+               pktbuf_write_DataRow(buf, "ssiiiiiiiiis",
                                     pool->db->name, pool->user->name,
                                     statlist_count(&pool->active_client_list),
                                     statlist_count(&pool->waiting_client_list),
@@ -809,8 +811,8 @@ static bool admin_show_pools(PgSocket *admin, const char *arg)
                                     statlist_count(&pool->tested_server_list),
                                     statlist_count(&pool->new_server_list),
                                     /* how long is the oldest client waited */
-                                    (waiter && waiter->query_start)
-                                    ?  (int)((now - waiter->query_start) / USEC) : 0,
+                                    (int)(max_wait / USEC),
+                                    (int)(max_wait % USEC),
                                     cf_get_lookup(&cv));
        }
        admin_flush(admin, buf, "SHOW");