Mistake on this page?
Report an issue in GitHub or email us

ProfilingBlockDevice

ProfilingBlockDevice class hierarchy

The ProfilingBlockDevice class provides a decorator for an existing block device object to log reads, writes and erases.

ProfilingBlockDevices take in a pointer to the block device being profiled as the only configurable parameter. If you want to count a storage operation such as programming, reading or writing to a block device, you should use the ProfilingBlockDevice object as the interface to the storage block rather than the underlying device. The below example highlights this use case.

To configure this class, please see our BlockDevice configuration documentation.

ProfilingBlockDevice class reference

Public Member Functions
 ProfilingBlockDevice (BlockDevice *bd)
 Lifetime of the memory block device. More...
virtual ~ProfilingBlockDevice ()
 Lifetime of a block device. More...
virtual int init ()
 Initialize a block device. More...
virtual int deinit ()
 Deinitialize a block device. More...
virtual int sync ()
 Ensure data on storage is in sync with the driver. More...
virtual int read (void *buffer, bd_addr_t addr, bd_size_t size)
 Read blocks from a block device. More...
virtual int program (const void *buffer, bd_addr_t addr, bd_size_t size)
 Program blocks to a block device. More...
virtual int erase (bd_addr_t addr, bd_size_t size)
 Erase blocks on a block device. More...
virtual bd_size_t get_read_size () const
 Get the size of a readable block. More...
virtual bd_size_t get_program_size () const
 Get the size of a programmable block. More...
virtual bd_size_t get_erase_size () const
 Get the size of an erasable block. More...
virtual bd_size_t get_erase_size (bd_addr_t addr) const
 Get the size of an erasable block given address. More...
virtual int get_erase_value () const
 Get the value of storage when erased. More...
virtual bd_size_t size () const
 Get the total size of the underlying device. More...
void reset ()
 Reset the current profile counts to zero. More...
bd_size_t get_read_count () const
 Get number of bytes that have been read from the block device. More...
bd_size_t get_program_count () const
 Get number of bytes that have been programed to the block device. More...
bd_size_t get_erase_count () const
 Get number of bytes that have been erased from the block device. More...
virtual const char * get_type () const
 Get the BlockDevice class type. More...
virtual int trim (bd_addr_t addr, bd_size_t size)
 Mark blocks as no longer in use. More...
virtual bool is_valid_read (bd_addr_t addr, bd_size_t size) const
 Convenience function for checking block read validity. More...
virtual bool is_valid_program (bd_addr_t addr, bd_size_t size) const
 Convenience function for checking block program validity. More...
virtual bool is_valid_erase (bd_addr_t addr, bd_size_t size) const
 Convenience function for checking block erase validity. More...
Static Public Member Functions
static BlockDeviceget_default_instance ()
 Return the default block device. More...

ProfilingBlockDevice example

Create a ProfilingBlockDevice, perform storage operations and report back the read, write and erase counts.

/*
 * Copyright (c) 2017-2020 Arm Limited and affiliates.
 * SPDX-License-Identifier: Apache-2.0
 */

#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());
}

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.