diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2022-09-14 19:22:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-14 19:22:25 +0300 |
commit | 466b1fcc56d3dc4787f332d76db0623f5dad9f91 (patch) | |
tree | 7f87c0ef8da991d3568d64083dccfe782de20d01 | |
parent | c93e585f38be8ca388fe7dff0cafb284ed9f831e (diff) |
Add sqlite page cache hit and miss statistics (#13665)
* Add sqlite page cache hit/ miss statistics
* Proper function definition
Co-authored-by: Vladimir Kobal <vlad@prokk.net>
* Proper function calls
Co-authored-by: Vladimir Kobal <vlad@prokk.net>
Co-authored-by: Vladimir Kobal <vlad@prokk.net>
-rw-r--r-- | daemon/global_statistics.c | 40 | ||||
-rw-r--r-- | database/sqlite/sqlite_context.c | 7 | ||||
-rw-r--r-- | database/sqlite/sqlite_context.h | 1 | ||||
-rw-r--r-- | database/sqlite/sqlite_functions.c | 7 | ||||
-rw-r--r-- | database/sqlite/sqlite_functions.h | 1 |
5 files changed, 56 insertions, 0 deletions
diff --git a/daemon/global_statistics.c b/daemon/global_statistics.c index 49c32d119d..2f0de3d9d5 100644 --- a/daemon/global_statistics.c +++ b/daemon/global_statistics.c @@ -38,6 +38,8 @@ static struct global_statistics { volatile uint64_t sqlite3_queries_failed_busy; volatile uint64_t sqlite3_queries_failed_locked; volatile uint64_t sqlite3_rows; + volatile uint64_t sqlite3_cache_hit; + volatile uint64_t sqlite3_cache_miss; } global_statistics = { .connected_clients = 0, @@ -134,6 +136,11 @@ static inline void global_statistics_copy(struct global_statistics *gs, uint8_t gs->sqlite3_queries_failed_busy = __atomic_load_n(&global_statistics.sqlite3_queries_failed_busy, __ATOMIC_RELAXED); gs->sqlite3_queries_failed_locked = __atomic_load_n(&global_statistics.sqlite3_queries_failed_locked, __ATOMIC_RELAXED); gs->sqlite3_rows = __atomic_load_n(&global_statistics.sqlite3_rows, __ATOMIC_RELAXED); + + gs->sqlite3_cache_hit = (uint64_t) sql_context_cache_stats(SQLITE_DBSTATUS_CACHE_HIT); + gs->sqlite3_cache_hit += (uint64_t) sql_metadata_cache_stats(SQLITE_DBSTATUS_CACHE_HIT); + gs->sqlite3_cache_miss = (uint64_t) sql_context_cache_stats(SQLITE_DBSTATUS_CACHE_MISS); + gs->sqlite3_cache_miss += (uint64_t) sql_metadata_cache_stats(SQLITE_DBSTATUS_CACHE_MISS); } static void global_statistics_charts(void) { @@ -581,6 +588,39 @@ static void global_statistics_charts(void) { rrdset_done(st_sqlite3_rows); } + if(gs.sqlite3_cache_hit) { + static RRDSET *st_sqlite3_cache = NULL; + static RRDDIM *rd_cache_hit = NULL; + static RRDDIM *rd_cache_miss= NULL; + + if (unlikely(!st_sqlite3_cache)) { + st_sqlite3_cache = rrdset_create_localhost( + "netdata" + , "sqlite3_cache" + , NULL + , "sqlite3" + , NULL + , "Netdata SQLite3 Cache" + , "ops/s" + , "netdata" + , "stats" + , 131103 + , localhost->rrd_update_every + , RRDSET_TYPE_LINE + ); + + rd_cache_hit = rrddim_add(st_sqlite3_cache, "cache_hit", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); + rd_cache_miss = rrddim_add(st_sqlite3_cache, "cache_miss", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); + } + else + rrdset_next(st_sqlite3_cache); + + rrddim_set_by_pointer(st_sqlite3_cache, rd_cache_hit, (collected_number)gs.sqlite3_cache_hit); + rrddim_set_by_pointer(st_sqlite3_cache, rd_cache_miss, (collected_number)gs.sqlite3_cache_miss); + + rrdset_done(st_sqlite3_cache); + } + // ---------------------------------------------------------------- } diff --git a/database/sqlite/sqlite_context.c b/database/sqlite/sqlite_context.c index 94c5919245..bd16848f97 100644 --- a/database/sqlite/sqlite_context.c +++ b/database/sqlite/sqlite_context.c @@ -444,6 +444,13 @@ skip_delete: return (rc_stored != SQLITE_DONE); } +int sql_context_cache_stats(int op) +{ + int count, dummy; + sqlite3_db_status(db_context_meta, op, &count, &dummy, 0); + return count; +} + // // TESTING FUNCTIONS // diff --git a/database/sqlite/sqlite_context.h b/database/sqlite/sqlite_context.h index 12937fffd1..3f941be802 100644 --- a/database/sqlite/sqlite_context.h +++ b/database/sqlite/sqlite_context.h @@ -6,6 +6,7 @@ #include "daemon/common.h" #include "sqlite3.h" +extern int sql_context_cache_stats(int op); typedef struct ctx_chart { uuid_t chart_id; const char *id; diff --git a/database/sqlite/sqlite_functions.c b/database/sqlite/sqlite_functions.c index c470e4c1de..6f71e3f6c3 100644 --- a/database/sqlite/sqlite_functions.c +++ b/database/sqlite/sqlite_functions.c @@ -2760,3 +2760,10 @@ int bind_text_null(sqlite3_stmt *res, int position, const char *text, bool can_b return 1; return sqlite3_bind_null(res, position); } + +int sql_metadata_cache_stats(int op) +{ + int count, dummy; + sqlite3_db_status(db_meta, op, &count, &dummy, 0); + return count; +} diff --git a/database/sqlite/sqlite_functions.h b/database/sqlite/sqlite_functions.h index 2c3f33b014..1e4ba43629 100644 --- a/database/sqlite/sqlite_functions.h +++ b/database/sqlite/sqlite_functions.h @@ -121,5 +121,6 @@ void migrate_localhost(uuid_t *host_uuid); extern void sql_store_host_system_info(uuid_t *host_id, const struct rrdhost_system_info *system_info); extern void sql_build_host_system_info(uuid_t *host_id, struct rrdhost_system_info *system_info); void sql_store_host_labels(RRDHOST *host); +extern int sql_metadata_cache_stats(int op); DICTIONARY *sql_load_host_labels(uuid_t *host_id); #endif //NETDATA_SQLITE_FUNCTIONS_H |