Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added tracking when was the histogram reset.

  • Loading branch information...
commit 5d6ab3e88bea87d7c7d4f8a067376815e7b09548 1 parent 3ca572d
@tvondra authored
View
5 query_histogram--1.0.sql
@@ -9,4 +9,9 @@ CREATE OR REPLACE FUNCTION query_histogram_reset()
AS 'MODULE_PATHNAME', 'query_histogram_reset'
LANGUAGE C IMMUTABLE;
+CREATE OR REPLACE FUNCTION query_histogram_get_reset()
+ RETURNS timestamp
+ AS 'MODULE_PATHNAME', 'query_histogram_get_reset'
+ LANGUAGE C IMMUTABLE;
+
CREATE OR REPLACE VIEW query_histogram AS SELECT * FROM query_histogram(true);
View
8 query_histogram.c
@@ -16,9 +16,11 @@ PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(query_histogram);
PG_FUNCTION_INFO_V1(query_histogram_reset);
+PG_FUNCTION_INFO_V1(query_histogram_get_reset);
Datum query_histogram(PG_FUNCTION_ARGS);
Datum query_histogram_reset(PG_FUNCTION_ARGS);
+Datum query_histogram_get_reset(PG_FUNCTION_ARGS);
Datum
query_histogram(PG_FUNCTION_ARGS)
@@ -153,3 +155,9 @@ query_histogram_reset(PG_FUNCTION_ARGS)
query_hist_reset(false);
PG_RETURN_VOID();
}
+
+Datum
+query_histogram_get_reset(PG_FUNCTION_ARGS)
+{
+ PG_RETURN_TIMESTAMP(get_hist_last_reset());
+}
View
21 queryhist.c
@@ -369,6 +369,7 @@ void histogram_shmem_startup() {
shared_histogram_info->bins = default_histogram_bins;
shared_histogram_info->step = default_histogram_step;
shared_histogram_info->sample_pct = default_histogram_sample_pct;
+ shared_histogram_info->last_reset = GetCurrentTimestamp();
memset(shared_histogram_info->count_bins, 0, (HIST_BINS_MAX+1)*sizeof(count_bin_t));
memset(shared_histogram_info->time_bins, 0, (HIST_BINS_MAX+1)*sizeof(time_bin_t));
@@ -534,6 +535,8 @@ void query_hist_reset(bool locked) {
memset(shared_histogram_info->count_bins, 0, (HIST_BINS_MAX+1)*sizeof(count_bin_t));
memset(shared_histogram_info->time_bins, 0, (HIST_BINS_MAX+1)*sizeof(time_bin_t));
+ shared_histogram_info->last_reset = GetCurrentTimestamp();
+
/* if it was not locked before, we can release the lock now */
if (! locked) {
LWLockRelease(shared_histogram_info->lock);
@@ -568,6 +571,24 @@ static int get_hist_bin(int bins, int step, time_bin_t duration) {
}
+TimestampTz get_hist_last_reset() {
+
+ TimestampTz timestamp;
+
+ if (! shared_histogram_info) {
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("query_histogram must be loaded via shared_preload_libraries")));
+ }
+
+ LWLockAcquire(shared_histogram_info->lock, LW_SHARED);
+ timestamp = shared_histogram_info->last_reset;
+ LWLockRelease(shared_histogram_info->lock);
+
+ return timestamp;
+
+}
+
histogram_data * query_hist_get_data(bool scale) {
int i = 0;
View
5 queryhist.h
@@ -1,5 +1,6 @@
#include "postgres.h"
#include "tcop/utility.h"
+#include "utils/timestamp.h"
/* TODO When the histogram is static (dynamic=0), we may actually
* use less memory because the use can't resize it (so the
@@ -42,6 +43,9 @@ typedef struct histogram_info_t {
/* lock guarding the histogram */
LWLockId lock;
+ /* last histogram reset time */
+ TimestampTz last_reset;
+
/* basic info (number of bins, step (bin width),
* number of bins, sampling rate */
int type;
@@ -57,3 +61,4 @@ typedef struct histogram_info_t {
histogram_data * query_hist_get_data(bool scale);
void query_hist_reset(bool locked);
+TimestampTz get_hist_last_reset(void);
Please sign in to comment.
Something went wrong with that request. Please try again.