Skip to content

Commit

Permalink
loader: Add a readtest command
Browse files Browse the repository at this point in the history
readtest will simply load the file in memory, useful for timing
loading on some filesystems.

Reviewed by:	tsoome
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33411

(cherry picked from commit 70661ea)
  • Loading branch information
evadot committed Jan 13, 2022
1 parent 62c7a77 commit 0078d54
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions stand/common/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,34 @@ command_lsdev(int argc, char *argv[])
pager_close();
return (CMD_OK);
}

static int
command_readtest(int argc, char *argv[])
{
int fd;
time_t start, end;
char buf[512];
ssize_t rv, count = 0;

if (argc != 2) {
snprintf(command_errbuf, sizeof(command_errbuf),
"Usage: readtest <filename>");
return (CMD_ERROR);
}

start = getsecs();
if ((fd = open(argv[1], O_RDONLY)) < 0) {
snprintf(command_errbuf, sizeof(command_errbuf),
"can't open '%s'", argv[1]);
return (CMD_ERROR);
}
while ((rv = read(fd, buf, sizeof(buf))) > 0)
count += rv;
end = getsecs();

printf("Received %zd bytes during %jd seconds\n", count, (intmax_t)end - start);
close(fd);
return (CMD_OK);
}

COMMAND_SET(readtest, "readtest", "Time a file read", command_readtest);
1 change: 1 addition & 0 deletions stand/libsa/tftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");

#include <string.h>

#include <bootstrap.h>
#include "stand.h"
#include "net.h"
#include "netif.h"
Expand Down

0 comments on commit 0078d54

Please sign in to comment.