Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added ability to scale the histogram as if the sampling rate was 100%.

  • Loading branch information...
commit 10e7af43a61d0e71ecf658e360ba417ba37c0c05 1 parent 7c405fd
@tvondra authored
View
4 query_histogram--1.0.sql
@@ -1,4 +1,4 @@
-CREATE OR REPLACE FUNCTION query_histogram( OUT bin_from INT, OUT bin_to INT, OUT bin_count INT, OUT bin_count_pct REAL,
+CREATE OR REPLACE FUNCTION query_histogram( IN scale BOOLEAN DEFAULT TRUE, OUT bin_from INT, OUT bin_to INT, OUT bin_count INT, OUT bin_count_pct REAL,
OUT bin_time REAL, OUT bin_time_pct REAL)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'query_histogram'
@@ -13,3 +13,5 @@ CREATE OR REPLACE FUNCTION query_histogram_refresh()
RETURNS void
AS 'MODULE_PATHNAME', 'query_histogram_refresh'
LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE VIEW query_histogram AS SELECT * FROM query_histogram(true);
View
4 query_histogram.c
@@ -35,8 +35,8 @@ query_histogram(PG_FUNCTION_ARGS)
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
-
- data = query_hist_get_data();
+
+ data = query_hist_get_data(PG_GETARG_BOOL(0));
/* init (open file, etc.), maybe read all the data in memory
* so that the file is not kept open for a long time */
View
12 queryhist.c
@@ -444,9 +444,10 @@ void query_hist_add_query(hist_bin_time_t duration) {
}
-histogram_data * query_hist_get_data() {
+histogram_data * query_hist_get_data(bool scale) {
int i = 0;
+ double coeff = 0;
histogram_data * tmp = (histogram_data *)palloc(sizeof(histogram_data));
@@ -465,6 +466,15 @@ histogram_data * query_hist_get_data() {
memcpy(tmp->count_data, histogram_count_bins, sizeof(hist_bin_count_t) * ((*histogram_bins)+1));
memcpy(tmp->time_data, histogram_time_bins, sizeof(hist_bin_time_t) * ((*histogram_bins)+1));
+ /* check if we need to scale the histogram */
+ if (scale && ((*histogram_sample_pct) < 100)) {
+ coeff = (100.0 / (*histogram_sample_pct));
+ for (i = 0; i < (*histogram_bins)+1; i++) {
+ tmp->count_data[i] = tmp->count_data[i] * coeff;
+ tmp->time_data[i] = tmp->time_data[i] * coeff;
+ }
+ }
+
for (i = 0; i < (*histogram_bins)+1; i++) {
tmp->total_count += tmp->count_data[i];
tmp->total_time += tmp->time_data[i];
View
2  queryhist.h
@@ -19,6 +19,6 @@ typedef enum {
HISTOGRAM_LOG
} histogram_type_t;
-histogram_data * query_hist_get_data();
+histogram_data * query_hist_get_data(bool scale);
void query_hist_reset(bool locked);
void query_hist_refresh();
Please sign in to comment.
Something went wrong with that request. Please try again.