Skip to content

Commit

Permalink
Add evalScriptsDictSize function
Browse files Browse the repository at this point in the history
The expression `dictSize(evalScriptsDict())` is used
a couple times for memory reporting.  `dictSize` is a macro
without NULL checking and used within a `FMTARG` macro in `server.c`.  Overall, this makes it challenging to stub out when
building without the Lua engine.

This change lifts that expression up to its own function `evalScriptsDictSize`.

Signed-off-by: Evan Wies <[email protected]>
  • Loading branch information
neomantra committed Nov 1, 2024
1 parent e985ead commit 60c6906
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,10 @@ dict *evalScriptsDict(void) {
return lctx.lua_scripts;
}

unsigned long evalScriptsDictSize(void) {
return dictSize(evalScriptsDict());
}

unsigned long evalScriptsMemory(void) {
return lctx.lua_scripts_mem + dictMemUsage(lctx.lua_scripts) + dictSize(lctx.lua_scripts) * sizeof(luaScript) +
listLength(lctx.lua_scripts_lru_list) * sizeof(listNode);
Expand Down
2 changes: 1 addition & 1 deletion src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ sds getMemoryDoctorReport(void) {
}

/* Too many scripts are cached? */
if (dictSize(evalScriptsDict()) > 1000) {
if (evalScriptsDictSize() > 1000) {
many_scripts = 1;
num_reports++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -5669,7 +5669,7 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) {
"used_memory_vm_eval:%lld\r\n", memory_lua,
"used_memory_lua_human:%s\r\n", used_memory_lua_hmem, /* deprecated */
"used_memory_scripts_eval:%lld\r\n", (long long)mh->lua_caches,
"number_of_cached_scripts:%lu\r\n", dictSize(evalScriptsDict()),
"number_of_cached_scripts:%lu\r\n", evalScriptsDictSize(),
"number_of_functions:%lu\r\n", functionsNum(),
"number_of_libraries:%lu\r\n", functionsLibNum(),
"used_memory_vm_functions:%lld\r\n", memory_functions,
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3649,6 +3649,7 @@ void ldbLogRespReply(char *reply);
void sha1hex(char *digest, char *script, size_t len);
unsigned long evalMemory(void);
dict *evalScriptsDict(void);
unsigned long evalScriptsDictSize(void);
unsigned long evalScriptsMemory(void);
uint64_t evalGetCommandFlags(client *c, uint64_t orig_flags);
uint64_t fcallGetCommandFlags(client *c, uint64_t orig_flags);
Expand Down

0 comments on commit 60c6906

Please sign in to comment.