#include "postgres.h"
#include "funcapi.h"
+#include "libpq/auth.h"
#include "miscadmin.h"
#include "portability/instr_time.h"
#include "storage/ipc.h"
Datum chash_delete_test(PG_FUNCTION_ARGS);
Datum chash_concurrent_test(PG_FUNCTION_ARGS);
Datum chash_collision_test(PG_FUNCTION_ARGS);
-Datum chash_write_stats_to_log(PG_FUNCTION_ARGS);
Datum dynahash_insert_test(PG_FUNCTION_ARGS);
Datum dynahash_search_test(PG_FUNCTION_ARGS);
Datum dynahash_delete_test(PG_FUNCTION_ARGS);
static CHashTable chash;
static HTAB *dynahash;
static LWLockId dynahash_lock[DYNAHASH_PARTITIONS];
+static ClientAuthentication_hook_type original_client_auth_hook = NULL;
+
+static void hashtest_client_auth_hook(Port *port, int status);
+static void chash_write_stats_to_log(int code, Datum dummy);
#define dynahash_get_lock(hashcode) \
(dynahash_lock[(hashcode) % DYNAHASH_PARTITIONS])
elog(LOG, "chash: %u bytes; dynahash: %u bytes", (unsigned) cs,
(unsigned) ds);
RequestAddinLWLocks(DYNAHASH_PARTITIONS);
+ original_client_auth_hook = ClientAuthentication_hook;
+ ClientAuthentication_hook = hashtest_client_auth_hook;
+
+}
+
+static void
+hashtest_client_auth_hook(Port *port, int status)
+{
+ if (original_client_auth_hook)
+ original_client_auth_hook(port, status);
+ on_proc_exit(chash_write_stats_to_log, (Datum) 0);
+}
+
+static void
+chash_write_stats_to_log(int code, Datum dummy)
+{
+ uint64 stats[CHS_NumberOfStatistics];
+ CHashStatisticsType i;
+ StringInfoData buf;
+
+ CHashStatistics(chash, stats);
+ initStringInfo(&buf);
+
+ for (i = 0; i < CHS_NumberOfStatistics; ++i)
+ {
+ if (stats[i] == 0)
+ continue;
+ appendStringInfo(&buf, UINT64_FORMAT " %s; ", stats[i],
+ CHashStatisticsNames[i]);
+ }
+
+ if (buf.len > 1)
+ {
+ buf.data[buf.len-2] = '\0';
+ elog(LOG, "chash statistics: %s", buf.data);
+ }
}
static void
PG_RETURN_VOID();
}
-Datum
-chash_write_stats_to_log(PG_FUNCTION_ARGS)
-{
- uint64 stats[CHS_NumberOfStatistics];
- CHashStatisticsType i;
- StringInfoData buf;
-
- CHashStatistics(chash, stats);
- initStringInfo(&buf);
-
- for (i = 0; i < CHS_NumberOfStatistics; ++i)
- {
- if (stats[i] == 0)
- continue;
- appendStringInfo(&buf, UINT64_FORMAT " %s; ", stats[i],
- CHashStatisticsNames[i]);
- }
-
- if (buf.len > 1)
- {
- buf.data[buf.len-2] = '\0';
- elog(LOG, "chash statistics: %s", buf.data);
- }
- else
- elog(LOG, "chash statistics: nothing to report");
-
- PG_RETURN_VOID();
-}
-
static bool
dynahash_insert(uint32 key, uint32 val)
{