i tried qnx6 filesystem performance test…
the program is:
//
// app.cc
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <malloc.h>
#include <dirent.h>
#include <time.h>
#include <pthread.h>
#include <fcntl.h>
#include <errno.h>
#include <netdb.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
enum operation_t {
OP_Prompt,
OP_FileWrite,
OP_FileRead,
OP_FileReadWrite,
OP_TCP_ReadWrite,
OP_UDP_ReadWrite,
OP_Exit,
};
#define SIZE_5K 10245
#define SIZE_10K 102410
#define SIZE_30K 1024*30
#define TCP_PORT 3480
#define UDP_PORT 3481
struct test_info_t {
int op;
int size;
char filename[64];
};
#define DEF_SIZE SIZE_30K
#define DEF_COUNT 10
#define DEF_OPERATION OP_Prompt
#define DEF_TARGET “127.1”
int g_size = DEF_SIZE;
int g_count = DEF_COUNT;
int g_operation = DEF_OPERATION;
char g_target[64] = DEF_TARGET;
char* g_src_file = NULL;
char* g_dst_file = NULL;
int g_prompt = 0;
int g_remove = 0;
int g_loop = 0;
char* buffer = NULL;
FILE* log_fd = NULL;
time_t tm;
int op_file_write()
{
int fd_src = open(g_src_file, O_RDONLY);
if (fd_src < 0) { perror(“src open”); return 1; }
int size = read(fd_src, buffer, g_size);
close(fd_src);
if (size == -1) { perror(“src read”); return 1; }
long msec;
timespec start, stop;
clock_gettime(CLOCK_REALTIME, &start);
for (int i = 1; i <= g_count; i++) {
char str[256];
sprintf(str, “data/test_%05d.dat”, i);
int fd_dst = open(str, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (fd_dst < 0) { perror(“dst open”); return 1; }
size = write(fd_dst, buffer, g_size);
close(fd_dst);
if (size == -1) { perror(“dst write”); return 1; }
if (i % 10) continue;
clock_gettime(CLOCK_REALTIME, &stop);
msec = (stop.tv_sec-start.tv_sec)*1000 +
(stop.tv_nsec-start.tv_nsec)/1000000;
printf("%8d average:%ldms, total:%ldms \r", i, msec/i, msec);
fflush(stdout);
}
printf("\n");
return 0;
}
int op_file_read()
{
long msec;
timespec start, stop;
clock_gettime(CLOCK_REALTIME, &start);
for (int i = 1; i <= g_count; i++) {
char str[256];
sprintf(str, “data/test_%05d.dat”, i);
int fd_src = open(str, O_RDONLY);
if (fd_src < 0) { perror(“src open”); return 1; }
int size = read(fd_src, buffer, g_size);
close(fd_src);
if (size == -1) { perror(“src read”); return 1; }
if (i % 10) continue;
clock_gettime(CLOCK_REALTIME, &stop);
msec = (stop.tv_sec-start.tv_sec)*1000 +
(stop.tv_nsec-start.tv_nsec)/1000000;
printf("%8d average:%ldms, total:%ldms \r", i, msec/i, msec);
fflush(stdout);
}
printf("\n");
return 0;
}
int op_file_readwrite()
{
long msec;
timespec start, stop;
clock_gettime(CLOCK_REALTIME, &start);
for (int i = 1; i <= g_count; i++) {
char str[256];
sprintf(str, “data/test_%05d.dat”, i);
int fd_src = open(str, O_RDONLY);
if (fd_src < 0) { perror(“src open”); return 1; }
int size = read(fd_src, buffer, g_size);
close(fd_src);
if (size == -1) { perror(“src read”); return 1; }
sprintf(str, “dest/test_%05d.dat”, i);
int fd_dst = open(str, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (fd_dst < 0) { perror(“dst open”); return 1; }
size = write(fd_dst, buffer, g_size);
close(fd_dst);
if (size == -1) { perror(“dst write”); return 1; }
if (i % 10) continue;
clock_gettime(CLOCK_REALTIME, &stop);
msec = (stop.tv_sec-start.tv_sec)*1000 +
(stop.tv_nsec-start.tv_nsec)/1000000;
printf("%8d average:%ldms, total:%ldms \r", i, msec/i, msec);
fflush(stdout);
}
printf("\n");
return 0;
}
int remove_data(char* dir)
{
printf(“remove files in %s\n”, dir);
DIR* d = opendir(dir);
if (d == NULL) {
perror(“opendir”);
return 1;
}
long msec;
timespec start, stop;
clock_gettime(CLOCK_REALTIME, &start);
dirent* de = NULL;
de = readdir(d); // .
de = readdir(d); // …
for (int i = 1; (de = readdir(d)) != NULL; i++) {
char str[256];
sprintf(str, “%s/%s”, dir, de->d_name);
if (remove(str)) perror(“remove”);
if (i % 10) continue;
clock_gettime(CLOCK_REALTIME, &stop);
msec = (stop.tv_sec-start.tv_sec)*1000 +
(stop.tv_nsec-start.tv_nsec)/1000000;
printf("%8d average:%ldms, total:%ldms \r", i, msec/i, msec);
fflush(stdout);
}
printf("\n");
closedir(d);
return 0;
}
int generate_test_data(char* data_file, int size)
{
struct stat buf;
if ((stat(data_file, &buf) == 0) && (buf.st_size == size)) return 0;
int fd = open(data_file, O_WRONLY|O_CREAT|O_TRUNC,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (fd == -1) {
perror(“generate_test_data open”);
return 1;
}
for (int i = 0; i < size/80; i++) {
char str[100];
sprintf(str,
“%08d:0123456789012345678901234567890123456789012345678901234567890123456789
\n”, i*80);
write(fd, str, 80);
}
close(fd);
printf(“file generate: %s, size: %d\n”, data_file, size);
return 0;
}
int parse(int argc, char* argv[])
{
int opt;
while ((opt = getopt(argc, argv, “c:o:t:s:nprl”)) != -1) {
switch (opt) {
case ‘c’: g_count = atoi(optarg); break;
case ‘o’: g_operation = atoi(optarg); break;
case ‘t’: strcpy(g_target, optarg); break;
case ‘s’:
{
int size = atoi(optarg);
size = (size < 1) ? 1 : ((size > 1024) ? 1024 : size);
g_size = size*1024;
}
break;
case ‘p’: g_prompt = 1; break;
case ‘r’: g_remove = 1; break;
case ‘l’: g_loop = 1; break;
default: break;
}
}
return 0;
}
void free_buffer()
{
if (log_fd) {
fclose(log_fd);
log_fd = NULL;
}
if (buffer) {
free(buffer);
buffer = NULL;
}
}
void sig_handler(int signo)
{
pthread_t tid = pthread_self();
printf(“signal… pthread_self() is %d\n”, tid);
free_buffer();
// exit(1);
printf(“main thread exit…\n”);
pthread_exit(NULL);
}
int main(int argc, char* argv[])
{
parse(argc, argv);
printf(“count:%d, size:%d \n”, g_count, g_size);
buffer = (char*)malloc(g_size);
if (buffer == NULL) {
printf(“malloc error\n”);
return EXIT_FAILURE;
}
atexit(free_buffer);
log_fd = fopen(“perftest.log”, “w”);
if (log_fd == NULL) { perror(“log open”); return 1; }
fprintf(log_fd, “perftest.log\n”);
fprintf(log_fd, “count:%d, size:%d \n”, g_count, g_size);
#if 1
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGINT);
struct sigaction act;
act.sa_flags = 0;
act.sa_mask = set;
act.sa_handler = &sig_handler;
sigaction(SIGINT, &act, NULL);
#endif
if ((mkdir(“data”, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) != 0) && (errno
!= EEXIST)) {
perror(“mkdir data”);
return EXIT_FAILURE;
}
if ((mkdir(“dest”, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) != 0) && (errno
!= EEXIST)) {
perror(“mkdir dest”);
return EXIT_FAILURE;
}
g_src_file = “test_src.dat”;
if (generate_test_data(g_src_file, g_size) != 0) return EXIT_FAILURE;
if (g_remove && (remove_data(“data”) != 0)) return EXIT_FAILURE;
if (g_remove && (remove_data(“dest”) != 0)) return EXIT_FAILURE;
tm = time(NULL);
fprintf(log_fd, “start at %s\n”, ctime(&tm));
int i = 1;
do {
printf("********************************\n");
sleep(1);
printf(“write test…\n”);
if (op_file_write() != 0) {
fprintf(log_fd, “error: op_file_write() %s\n”, strerror(errno));
return EXIT_FAILURE;
}
sync();
printf(“read test…\n”);
if (op_file_read() != 0) {
fprintf(log_fd, “error: op_file_read() %s\n”, strerror(errno));
return EXIT_FAILURE;
}
sync();
printf(“read write test…\n”);
if (op_file_readwrite() != 0) {
fprintf(log_fd, “error: op_file_readwrite() %s\n”, strerror(errno));
return EXIT_FAILURE;
}
sync();
if (g_remove) {
if (remove_data(“data”) || remove_data(“dest”)) {
fprintf(log_fd, “error: remove_data() %s\n”, strerror(errno));
return EXIT_FAILURE;
}
}
sync();
tm = time(NULL);
fprintf(log_fd, “%05d done at %s\n”, i++, ctime(&tm));
sync();
} while (g_loop);
return EXIT_SUCCESS;
}
//
// end app.cc
//
i run it with -l option…
then one day after, the program terminate with an error message…
what’s wrong??