ProfilingBlockDevice
ProfilingBlockDevice 类层次结构
ProfilingBlockDevice 类为现有块设备对象提供装饰器,以记录读取,写入和擦除。
ProfilingBlockDevices 接收指向被分析的块设备的指针,作为唯一可配置的参数。如果要计算存储操作(如编程,读取或写入块设备),则应使用 ProfilingBlockDevice 对象作为存储块的接口而不是底层设备。以下示例突出显示了此用例。
ProfilingBlockDevice 类参考
公共成员函数 | |
ProfilingBlockDevice (BlockDevice *bd) | |
virtual | ~ProfilingBlockDevice () |
virtual int | init () |
virtual int | deinit () |
virtual int | sync () |
virtual int | read (void *buffer, bd_addr_t addr, bd_size_t size) |
virtual int | program (const void *buffer, bd_addr_t addr, bd_size_t size) |
virtual int | erase (bd_addr_t addr, bd_size_t size) |
virtual bd_size_t | get_read_size () const |
virtual bd_size_t | get_program_size () const |
virtual bd_size_t | get_erase_size () const |
virtual bd_size_t | get_erase_size (bd_addr_t addr) const |
virtual int | get_erase_value () const |
virtual bd_size_t | size () const |
void | reset () |
bd_size_t | get_read_count () const |
bd_size_t | get_program_count () const |
bd_size_t | get_erase_count () const |
公共成员函数继承自 BlockDevice | |
virtual | ~BlockDevice () |
virtual int | trim (bd_addr_t addr, bd_size_t size) |
bool | is_valid_read (bd_addr_t addr, bd_size_t size) const |
bool | is_valid_program (bd_addr_t addr, bd_size_t size) const |
bool | is_valid_erase (bd_addr_t addr, bd_size_t size) const |
ProfilingBlockDevice 示例
创建 ProfilingBlockDevice,执行存储操作并报告读取,写入和擦除计数。
#include "mbed.h"
#include "HeapBlockDevice.h"
#include "ProfilingBlockDevice.h"
#define BLOCK_SIZE 512
HeapBlockDevice bd(2048, BLOCK_SIZE); // 2048 bytes with a block size of 512 bytes
uint8_t block[BLOCK_SIZE] = "Hello World!\n";
int main() {
ProfilingBlockDevice profiler(&bd);
profiler.init();
profiler.erase(0, BLOCK_SIZE);
profiler.program(block, 0, BLOCK_SIZE);
profiler.read(block, 0, BLOCK_SIZE);
printf("%s", block);
printf("read count: %lld\n", profiler.get_read_count());
printf("program count: %lld\n", profiler.get_program_count());
printf("erase count: %lld\n", profiler.get_erase_count());
}