MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / readspeed

Function readspeed

examples/file/readspeed.c:19–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17#include <sys/statfs.h>
18
19void readspeed(const char* filename, int block_size)
20{
21 int fd;
22 char *buff_ptr;
23 rt_size_t total_length;
24 rt_tick_t tick;
25
26 fd = open(filename, 0, O_RDONLY);
27 if (fd < 0)
28 {
29 rt_kprintf("open file:%s failed\n", filename);
30 return;
31 }
32
33 buff_ptr = rt_malloc(block_size);
34 if (buff_ptr == RT_NULL)
35 {
36 rt_kprintf("no memory\n");
37 close(fd);
38 return;
39 }
40
41 tick = rt_tick_get();
42 total_length = 0;
43 while (1)
44 {
45 int length;
46 length = read(fd, buff_ptr, block_size);
47
48 if (length <= 0) break;
49 total_length += length;
50 }
51 tick = rt_tick_get() - tick;
52
53 /* close file and release memory */
54 close(fd);
55 rt_free(buff_ptr);
56
57 /* calculate read speed */
58 rt_kprintf("File read speed: %d byte/s\n", total_length /tick * RT_TICK_PER_SECOND);
59}
60
61#ifdef RT_USING_FINSH
62#include <finsh.h>

Callers 1

cmd_readspeedFunction · 0.85

Calls 7

rt_kprintfFunction · 0.85
rt_mallocFunction · 0.85
rt_tick_getFunction · 0.85
rt_freeFunction · 0.85
openFunction · 0.50
closeFunction · 0.50
readFunction · 0.50

Tested by

no test coverage detected