C
实现性能指标平台 API
继承自Qul::Platform::PerformanceMetrics 结构,并重写用于最大堆内存使用量、最大栈内存使用量和CPU负载的虚拟函数。为您的平台创建性能指标的自定义实现:
struct ExamplePerformanceMetrics : PerformanceMetrics { uint64_t maxHeapUsage() QUL_DECL_OVERRIDE { /*Custom maximum heap usage function depending on Platform and toolchains.*/ return 0; } uint64_t maxStackUsage() QUL_DECL_OVERRIDE { /*Custom maximum stack usage function depending on Platform and toolchains.*/ return 0; } #if defined(QUL_ENABLE_HARDWARE_PERFORMANCE_LOGGING) float cpuLoad() QUL_DECL_OVERRIDE { /*Custom CPU load measurement function depending on Platform and toolchains.*/ return 0.f; }; #endif };
在您的平台上下文中实现PlatformContext::performanceMetrics ,以返回这些信息,从而使ExamplePerformanceMetrics 结构能够访问Qt Quick Ultralite Core。
Platform::PerformanceMetrics *ExamplePlatform::performanceMetrics(void) { static ExamplePerformanceMetrics metrics; return &metrics; }
内存统计信息
该平台提供了用于获取内存统计信息(如堆和栈大小)的函数。
必须实现Qul::Platform::printHeapStats 和Qul::Platform::printStackStats 函数才能输出此类信息。如果您的平台上支持mallinfo() 函数,也可以使用该函数。
void printHeapStats(void) { struct mallinfo mi = mallinfo(); PlatformInterface::log("Heap: %u/%u (in-use/total)\r\n", mi.uordblks, mi.arena); } void printStackStats(void) { // Replace this with actual measuring for your platform uint32_t maxUsedStackSize = 0; PlatformInterface::log("Stack: %u (peak)\r\n", maxUsedStackSize); }
void printHeapStats(void) { struct mallinfo mi = __iar_dlmallinfo(); PlatformInterface::log("Heap: %u/%u (in-use/total)\r\n", mi.uordblks, mi.arena); } void printStackStats(void) { // Replace this with actual measuring for your platform uint32_t maxUsedStackSize = 0; PlatformInterface::log("Stack: %u (peak)\r\n", maxUsedStackSize); }
在某些 Qt 许可下可用。
了解更多。