Skip to content
Browse files

Refreshing sample_pct (copy from the segment to local memory) wheneve…

…r adding a new query (once we actually lock the segment).
  • Loading branch information...
1 parent 8f218fe commit f2983b6389d0186a4c87e6cfbc5478e0cac7ef6c @tvondra committed
Showing with 36 additions and 2 deletions.
  1. +5 −0 query_histogram--1.0.sql
  2. +7 −0 query_histogram.c
  3. +21 −1 queryhist.c
  4. +3 −1 queryhist.h
View
5 query_histogram--1.0.sql
@@ -8,3 +8,8 @@ CREATE OR REPLACE FUNCTION query_histogram_reset()
RETURNS void
AS 'MODULE_PATHNAME', 'query_histogram_reset'
LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION query_histogram_refresh()
+ RETURNS void
+ AS 'MODULE_PATHNAME', 'query_histogram_refresh'
+ LANGUAGE C IMMUTABLE;
View
7 query_histogram.c
@@ -135,3 +135,10 @@ query_histogram_reset(PG_FUNCTION_ARGS)
query_hist_reset(false);
PG_RETURN_VOID();
}
+
+Datum
+query_histogram_refresh(PG_FUNCTION_ARGS)
+{
+ query_hist_refresh();
+ PG_RETURN_VOID();
+}
View
22 queryhist.c
@@ -395,6 +395,7 @@ void query_hist_reset(bool locked) {
(*histogram_bins) = default_histogram_bins;
(*histogram_step) = default_histogram_step;
(*histogram_sample_pct) = default_histogram_sample_pct;
+ (*histogram_type) = default_histogram_type;
memset(histogram_count_bins, 0, (HIST_BINS_MAX+1)*sizeof(hist_bin_t));
memset(histogram_time_bins, 0, (HIST_BINS_MAX+1)*sizeof(hist_bin_t));
@@ -405,11 +406,30 @@ void query_hist_reset(bool locked) {
}
+void query_hist_refresh() {
+
+ if (histogram_initialized) {
+
+ semaphore_lock();
+
+ default_histogram_bins = (*histogram_bins);
+ default_histogram_step = (*histogram_step);
+ default_histogram_sample_pct = (*histogram_sample_pct);
+ default_histogram_type = (*histogram_type);
+
+ semaphore_unlock();
+
+ }
+
+}
+
void query_hist_add_query(int duration) {
+ int bin;
+
semaphore_lock();
- int bin = duration / (*histogram_step);
+ bin = duration / (*histogram_step);
/* queries that take longer than the last bin should go to
* the (HIST_BINS_MAX+1) bin */
View
4 queryhist.h
@@ -1,3 +1,4 @@
+#include "postgres.h"
typedef struct histogram_data {
@@ -19,4 +20,5 @@ typedef enum {
} histogram_type_t;
histogram_data * query_hist_get_data();
-void query_hist_reset(bool);
+void query_hist_reset(bool locked);
+void query_hist_refresh();

0 comments on commit f2983b6

Please sign in to comment.
Something went wrong with that request. Please try again.