Memory: JSON format support

This commit is contained in:
李通洲
2023-09-06 15:58:43 +08:00
parent 849ff95116
commit 8bb88d1806
2 changed files with 18 additions and 1 deletions
+17 -1
View File
@@ -68,7 +68,7 @@ void ffPrintMemory(FFMemoryOptions* options)
void ffInitMemoryOptions(FFMemoryOptions* options)
{
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEMORY_MODULE_NAME, ffParseMemoryCommandOptions, ffParseMemoryJsonObject, ffPrintMemory, NULL);
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEMORY_MODULE_NAME, ffParseMemoryCommandOptions, ffParseMemoryJsonObject, ffPrintMemory, ffGenerateMemoryJson);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -103,3 +103,19 @@ void ffParseMemoryJsonObject(FFMemoryOptions* options, yyjson_val* module)
ffPrintError(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
void ffGenerateMemoryJson(FF_MAYBE_UNUSED FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFMemoryResult storage;
const char* error = ffDetectMemory(&storage);
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_uint(doc, obj, "total", storage.bytesTotal);
yyjson_mut_obj_add_uint(doc, obj, "used", storage.bytesUsed);
}
+1
View File
@@ -9,3 +9,4 @@ void ffInitMemoryOptions(FFMemoryOptions* options);
bool ffParseMemoryCommandOptions(FFMemoryOptions* options, const char* key, const char* value);
void ffDestroyMemoryOptions(FFMemoryOptions* options);
void ffParseMemoryJsonObject(FFMemoryOptions* options, yyjson_val* module);
void ffGenerateMemoryJson(FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);