PhysicalMemory: improve default output format; detect part number

This commit is contained in:
李通洲
2024-05-12 19:13:21 +08:00
parent 82d848727c
commit df6ab6427e
4 changed files with 32 additions and 23 deletions
@@ -10,6 +10,7 @@ typedef struct FFPhysicalMemoryResult
FFstrbuf type;
FFstrbuf formFactor;
FFstrbuf deviceLocator;
FFstrbuf partNumber;
FFstrbuf vendor;
FFstrbuf serial;
} FFPhysicalMemoryResult;
@@ -14,6 +14,7 @@ static void appendDevice(
// Intel only
NSString* deviceLocator,
NSString* serial,
NSString* partNumber,
NSString* speed)
{
FFPhysicalMemoryResult* device = ffListAdd(result);
@@ -24,6 +25,8 @@ static void appendDevice(
ffCleanUpSmbiosValue(&device->vendor);
ffStrbufInitS(&device->serial, serial.UTF8String);
ffCleanUpSmbiosValue(&device->serial);
ffStrbufInitS(&device->partNumber, partNumber.UTF8String);
ffCleanUpSmbiosValue(&device->partNumber);
device->size = 0;
device->maxSpeed = 0;
device->runningSpeed = 0;
@@ -92,6 +95,7 @@ const char* ffDetectPhysicalMemory(FFlist* result)
item[@"dimm_size"],
item[@"_name"],
item[@"dimm_serial_number"],
item[@"dimm_part_number"],
item[@"dimm_speed"]);
}
}
@@ -104,6 +108,7 @@ const char* ffDetectPhysicalMemory(FFlist* result)
data[@"SPMemoryDataType"],
nil,
nil,
nil,
nil);
}
}
@@ -88,6 +88,7 @@ const char* ffDetectPhysicalMemory(FFlist* result)
ffStrbufInit(&device->deviceLocator);
ffStrbufInit(&device->vendor);
ffStrbufInit(&device->serial);
ffStrbufInit(&device->partNumber);
device->size = 0;
device->maxSpeed = 0;
device->runningSpeed = 0;
@@ -183,6 +184,9 @@ const char* ffDetectPhysicalMemory(FFlist* result)
ffStrbufSetStatic(&device->serial, ffSmbiosLocateString(strings, data->SerialNumber));
ffCleanUpSmbiosValue(&device->serial);
ffStrbufSetStatic(&device->partNumber, ffSmbiosLocateString(strings, data->PartNumber));
ffCleanUpSmbiosValue(&device->partNumber);
}
if (data->Header.Length > offsetof(FFSmbiosMemoryDevice, ConfiguredMemorySpeed)) // 2.7+
+22 -23
View File
@@ -6,7 +6,7 @@
#include "modules/physicalmemory/physicalmemory.h"
#include "util/stringUtils.h"
#define FF_PHYSICALMEMORY_NUM_FORMAT_ARGS 9
#define FF_PHYSICALMEMORY_NUM_FORMAT_ARGS 10
#define FF_PHYSICALMEMORY_DISPLAY_NAME "Physical Memory"
void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
@@ -30,31 +30,25 @@ void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
ffStrbufClear(&prettySize);
ffParseSize(device->size, &prettySize);
if(options->moduleArgs.key.length == 0)
{
if (device->maxSpeed)
ffStrbufSetF(&key, "%s (%s %s-%u)", FF_PHYSICALMEMORY_DISPLAY_NAME, device->vendor.chars, device->type.chars, device->maxSpeed);
else
ffStrbufSetF(&key, "%s (%s %s)", FF_PHYSICALMEMORY_DISPLAY_NAME, device->vendor.chars, device->type.chars);
}
else
{
FF_PARSE_FORMAT_STRING_CHECKED(&key, &options->moduleArgs.key, 5, ((FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT, &i},
{FF_FORMAT_ARG_TYPE_STRBUF, &device->vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &device->type},
{FF_FORMAT_ARG_TYPE_UINT, &device->maxSpeed},
{FF_FORMAT_ARG_TYPE_STRBUF, &device->deviceLocator},
}));
}
if (options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffPrintLogoAndKey(
FF_PHYSICALMEMORY_DISPLAY_NAME,
result.length == 1 ? 0 : (uint8_t) i,
&options->moduleArgs,
FF_PRINT_TYPE_DEFAULT);
fputs(prettySize.chars, stdout);
fputs(" - ", stdout);
ffStrbufWriteTo(&device->type, stdout);
if (device->maxSpeed > 0)
printf("-%u", device->maxSpeed);
if (device->runningSpeed > 0 && device->runningSpeed != device->maxSpeed)
printf("%s, running at %u MT/s\n", prettySize.chars, device->runningSpeed);
else
puts(prettySize.chars);
printf(" at %u MT/s\n", device->runningSpeed);
if (device->vendor.length > 0)
printf(" (%s)", device->vendor.chars);
putchar('\n');
}
else
{
@@ -68,6 +62,7 @@ void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
{FF_FORMAT_ARG_TYPE_DOUBLE, &device->deviceLocator},
{FF_FORMAT_ARG_TYPE_STRBUF, &device->vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &device->serial},
{FF_FORMAT_ARG_TYPE_STRBUF, &device->partNumber},
}));
}
}
@@ -78,6 +73,7 @@ void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
ffStrbufDestroy(&device->formFactor);
ffStrbufDestroy(&device->vendor);
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->partNumber);
}
}
@@ -138,6 +134,7 @@ void ffGeneratePhysicalMemoryJsonResult(FF_MAYBE_UNUSED FFPhysicalMemoryOptions*
yyjson_mut_obj_add_strbuf(doc, obj, "formFactor", &device->formFactor);
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &device->vendor);
yyjson_mut_obj_add_strbuf(doc, obj, "serial", &device->serial);
yyjson_mut_obj_add_strbuf(doc, obj, "partNumber", &device->partNumber);
}
FF_LIST_FOR_EACH(FFPhysicalMemoryResult, device, result)
@@ -146,6 +143,7 @@ void ffGeneratePhysicalMemoryJsonResult(FF_MAYBE_UNUSED FFPhysicalMemoryOptions*
ffStrbufDestroy(&device->formFactor);
ffStrbufDestroy(&device->vendor);
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->partNumber);
}
}
@@ -161,6 +159,7 @@ void ffPrintPhysicalMemoryHelpFormat(void)
"Device locator (SIMM1, SIMM2, etc.)",
"Vendor",
"Serial number",
"Part number",
}));
}