asmlinkage ssize_t our_write (int fd, char *buf, size_t count) { if(strstr(buf,"sleep")) return -1; printk (KERN_INFO "SYS_WRITE: %s\n",buf); return orig_write(fd,buf,count); }
ssize_t write(int fd, const void *buf, size_t count) { orig_write = dlsym(RTLD_NEXT,"write"); clock_t start = clock(); ssize_t temp = orig_write(fd,buf,count); clock_t end = clock(); double start_diff = ((double)(start-program_start))/(double)CLOCKS_PER_SEC; double end_diff = ((double)(end-program_start))/(double)CLOCKS_PER_SEC; printf("%lf %lf Write Called \n", start_diff, end_diff); return temp; }
ssize_t write(int fd, const void *buf, size_t count) { int size; int size_t_count=count; orig_write_f_type orig_write; //int gettimeofday(struct timeval *tv, struct timezone *tz); struct timeval tv0; struct timeval tv1; struct timezone tz; //mtx.lock(); orig_write = (orig_write_f_type)dlsym(RTLD_NEXT,"write"); gettimeofday(&tv0,&tz); size=orig_write(fd,buf,count); gettimeofday(&tv1,&tz); std::string str; std::ostringstream oss; oss << "write(" << fd << "," << buf << "," << count << ")\n"; log.add(oss.str()); if (size>=0) { if (myiio.existFd(fd)==-1) { Ifile ifi; ifi.setFd(fd); ifi.setName(getStrFDInfo(fd)); //ifi.setName(std::string("UNKNOWN-WRITE")); ifi.setState(IOBYFILE_WRITE); myiio.iiof.push_back(ifi); } add_write_count(fd,size); add_write_time(fd,tv0,tv1); } //mtx.unlock(); return size; }