int mod_writenull(A_UNUSED int argc,A_UNUSED char **argv) { uint64_t times[ARRAY_SIZE(sizes)] = {0}; int fd = open("/dev/null",O_WRONLY); if(fd < 0) { printe("Unable to open /dev/null"); return 1; } for(size_t s = 0; s < ARRAY_SIZE(sizes); ++s) { uint64_t start = rdtsc(); for(int i = 0; i < PACKET_COUNT; ++i) { if(write(fd,buffer,sizes[s]) != (ssize_t)sizes[s]) printe("write failed"); } times[s] = rdtsc() - start; } close(fd); for(size_t s = 0; s < ARRAY_SIZE(sizes); ++s) { printf("per-msg=%5Lu throughput=%Lu MB/s (%db packets)\n", times[s] / PACKET_COUNT, (sizes[s] * PACKET_COUNT) / tsctotime(times[s]),sizes[s]); } return 0; }
int main(int argc,char **argv) { uint64_t start,end; char path[MAX_PATH_LEN + 1] = "/bin/"; if(argc < 2 || isHelpCmd(argc,argv)) usage(argv[0]); strcat(path,argv[1]); if(signal(SIGINT,sigHdlr) == SIG_ERR) error("Unable to set sig-handler for signal %d",SIGINT); start = rdtsc(); if((waitingPid = fork()) == 0) { size_t i; const char **args = (const char**)malloc(sizeof(char*) * (argc - 1)); if(!args) error("Not enough mem"); for(i = 1; i < (size_t)argc; i++) args[i - 1] = argv[i]; args[argc - 1] = NULL; execvp(args[0],args); error("Exec failed"); } else if(waitingPid < 0) error("Fork failed"); else { sExitState state; int res; while(1) { res = waitchild(&state,-1); if(res != -EINTR) break; } end = rdtsc(); if(res < 0) error("Wait failed"); fprintf(stderr,"\n"); fprintf(stderr,"Process %d (%s) terminated with exit-code %d\n",state.pid,path,state.exitCode); if(state.signal != SIG_COUNT) fprintf(stderr,"It was terminated by signal %d\n",state.signal); fprintf(stderr,"Runtime: %Lu us\n",state.runtime); fprintf(stderr,"Realtime: %Lu us\n",tsctotime(end - start)); fprintf(stderr,"Scheduled: %lu times\n",state.schedCount); fprintf(stderr,"Syscalls: %lu\n",state.syscalls); fprintf(stderr,"Migrations: %lu\n",state.migrations); fprintf(stderr,"Own mem: %lu KiB\n",state.ownFrames * 4); fprintf(stderr,"Shared mem: %lu KiB\n",state.sharedFrames * 4); fprintf(stderr,"Swapped: %lu KiB\n",state.swapped * 4); } return EXIT_SUCCESS; }
int main(int argc,const char *argv[]) { size_t bs = 4096; size_t count = 0; ullong total = 0; char *inFile = NULL; char *outFile = NULL; FILE *in = stdin; FILE *out = stdout; int res = ca_parse(argc,argv,CA_NO_DASHES | CA_NO_FREE | CA_REQ_EQ, "if=s of=s bs=k count=k",&inFile,&outFile,&bs,&count); if(res < 0) { printe("Invalid arguments: %s",ca_error(res)); usage(argv[0]); } if(ca_hasHelp()) usage(argv[0]); if(signal(SIGINT,interrupted) == SIG_ERR) error("Unable to set sig-handler for SIGINT"); if(inFile) { in = fopen(inFile,"r"); if(in == NULL) error("Unable to open '%s'",inFile); } if(outFile) { out = fopen(outFile,"w"); if(out == NULL) error("Unable to open '%s'",outFile); } uint64_t start = rdtsc(), end; { ulong shname; uchar *shmem; if(sharebuf(fileno(in),bs,(void**)&shmem,&shname,0) < 0) { if(shmem == NULL) error("Unable to mmap buffer"); } size_t result; ullong limit = (ullong)count * bs; while(run && (!count || total < limit)) { if((result = fread(shmem,1,bs,in)) == 0) break; if(fwrite(shmem,1,bs,out) == 0) break; total += result; } if(ferror(in)) error("Read failed"); if(ferror(out)) error("Write failed"); destroybuf(shmem,shname); } end = rdtsc(); uint64_t usecs = tsctotime(end - start); printf("%zu records in\n",count); printf("%zu records out\n",count); printf("%Lu bytes (%.1lf MB) copied, %.1lf s, %.1lf MB/s\n", total,total / 1000000.0,usecs / 1000000.0,total / (double)usecs); if(inFile) fclose(in); if(outFile) fclose(out); return EXIT_SUCCESS; }
int main(int argc,const char *argv[]) { size_t bs = 4096; size_t count = 0; ullong total = 0; char *inFile = NULL; char *outFile = NULL; int infd = STDIN_FILENO; int outfd = STDOUT_FILENO; int res = ca_parse(argc,argv,CA_NO_DASHES | CA_NO_FREE | CA_REQ_EQ, "if=s of=s bs=k count=k",&inFile,&outFile,&bs,&count); if(res < 0) { printe("Invalid arguments: %s",ca_error(res)); usage(argv[0]); } if(ca_hasHelp()) usage(argv[0]); if(signal(SIGINT,interrupted) == SIG_ERR) error("Unable to set sig-handler for SIGINT"); if(inFile) { infd = open(inFile,O_RDONLY); if(infd < 0) error("Unable to open '%s'",inFile); } if(outFile) { outfd = open(outFile,O_WRONLY); if(outfd < 0) error("Unable to open '%s'",outFile); } uint64_t start = rdtsc(), end; { int shmfd; uchar *shmem; if((shmfd = sharebuf(infd,bs,(void**)&shmem,0)) < 0) { if(shmem == NULL) error("Unable to mmap buffer"); } if(shmem) { if(delegate(outfd,shmfd,O_RDONLY,DEL_ARG_SHFILE) < 0) {} } ssize_t result; ullong limit = (ullong)count * bs; while(run && (!count || total < limit)) { if((result = read(infd,shmem,bs)) <= 0) { if(result < 0) error("Read failed"); break; } if(write(outfd,shmem,result) < 0) error("Write failed"); total += result; } destroybuf(shmem,shmfd); } end = rdtsc(); uint64_t usecs = tsctotime(end - start); printf("%zu records in\n",count); printf("%zu records out\n",count); printf("%Lu bytes (%.1lf MB) copied, %.1lf s, %.1lf MB/s\n", total,total / 1000000.0,usecs / 1000000.0,total / (double)usecs); if(inFile) close(infd); if(outFile) close(outfd); return EXIT_SUCCESS; }