void opd_print_stats(void) { DIR * dir; struct dirent * dirent; printf("\n%s\n", op_get_time()); printf("\n-- OProfile Statistics --\n"); printf("Nr. sample dumps: %lu\n", opd_stats[OPD_DUMP_COUNT]); printf("Nr. non-backtrace samples: %lu\n", opd_stats[OPD_SAMPLES]); printf("Nr. kernel samples: %lu\n", opd_stats[OPD_KERNEL]); printf("Nr. lost samples (no kernel/user): %lu\n", opd_stats[OPD_NO_CTX]); printf("Nr. lost kernel samples: %lu\n", opd_stats[OPD_LOST_KERNEL]); printf("Nr. incomplete code structs: %lu\n", opd_stats[OPD_DANGLING_CODE]); printf("Nr. samples lost due to sample file open failure: %lu\n", opd_stats[OPD_LOST_SAMPLEFILE]); printf("Nr. samples lost due to no permanent mapping: %lu\n", opd_stats[OPD_LOST_NO_MAPPING]); print_if("Nr. event lost due to buffer overflow: %u\n", "/dev/oprofile/stats", "event_lost_overflow", 1); print_if("Nr. samples lost due to no mapping: %u\n", "/dev/oprofile/stats", "sample_lost_no_mapping", 1); print_if("Nr. backtraces skipped due to no file mapping: %u\n", "/dev/oprofile/stats", "bt_lost_no_mapping", 0); print_if("Nr. samples lost due to no mm: %u\n", "/dev/oprofile/stats", "sample_lost_no_mm", 1); opd_ext_print_stats(); if (!(dir = opendir("/dev/oprofile/stats/"))) goto out; while ((dirent = readdir(dir))) { int cpu_nr; char path[256]; if (sscanf(dirent->d_name, "cpu%d", &cpu_nr) != 1) continue; snprintf(path, 256, "/dev/oprofile/stats/%s", dirent->d_name); printf("\n---- Statistics for cpu : %d\n", cpu_nr); print_if("Nr. samples lost cpu buffer overflow: %u\n", path, "sample_lost_overflow", 1); print_if("Nr. samples lost task exit: %u\n", path, "sample_lost_task_exit", 0); print_if("Nr. samples received: %u\n", path, "sample_received", 1); print_if("Nr. backtrace aborted: %u\n", path, "backtrace_aborted", 0); print_if("Nr. samples lost invalid pc: %u\n", path, "sample_invalid_eip", 0); } closedir(dir); out: fflush(stdout); }
/* _lib7_Sock_recv : (Socket, Int, Bool, Bool) -> unt8_vector::Vector * * The arguments are: socket, number of bytes, OOB flag and peek flag; the * result is the vector of bytes received. * * This function gets imported into the Mythryl world via: * src/lib/std/src/socket/socket-guts.pkg */ lib7_val_t _lib7_Sock_recv (lib7_state_t *lib7_state, lib7_val_t arg) { lib7_val_t vec; lib7_val_t result; int n; int socket = REC_SELINT(arg, 0); int nbytes = REC_SELINT(arg, 1); lib7_val_t oob = REC_SEL( arg, 2); lib7_val_t peek = REC_SEL( arg, 3); int flag = 0; if (oob == LIB7_true) flag |= MSG_OOB; if (peek == LIB7_true) flag |= MSG_PEEK; /* Allocate the vector. * Note that this might cause a GC: */ vec = LIB7_AllocRaw32 (lib7_state, BYTES_TO_WORDS(nbytes)); print_if("recv.c/before: socket d=%d nbytes d=%d oob=%s peek=%s\n",socket,nbytes,(oob == LIB7_true)?"TRUE":"FALSE",(peek == LIB7_true)?"TRUE":"FALSE"); errno = 0; /* do { */ /* Backed out 2010-02-26 CrT: See discussion at bottom of src/runtime/c-libs/lib7-socket/connect.c */ n = recv (socket, PTR_LIB7toC(char, vec), nbytes, flag); /* } while (n < 0 && errno == EINTR); */ /* Restart if interrupted by a SIGALRM or SIGCHLD or whatever. */ print_if( "recv.c/after: n d=%d errno d=%d (%s)\n", n, errno, errno ? strerror(errno) : ""); hexdump_if( "recv.c/after: Received data: ", PTR_LIB7toC(unsigned char, vec), n ); if (n < 0) return RAISE_SYSERR(lib7_state, status); else if (n == 0) return LIB7_string0; if (n < nbytes) { /* we need to shrink the vector */ LIB7_ShrinkRaw32 (lib7_state, vec, BYTES_TO_WORDS(n)); } SEQHDR_ALLOC (lib7_state, result, DESC_string, vec, n); return result; }
int main(int argc, const char * argv[]) { // insert code here... //Test case for Programming part 2 and 3 Vector<student> a; for (int i = 0; i < 100; i++) { student b((rand()%40)/10.0+1, "student" + std::to_string(i)); a.push_back(b); } print_if(a.begin(), a.end(), GPA_in_range<student>(3, 4)); //Testing /* Vector<int> c; for (int i = 0 ; i < 13; i++){ c.push_back(i);//{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; } Vector<int>::iterator itr1 = c.begin()+2;f Vector<int>::iterator itr2 = c.begin()+4; Vector<int>::iterator itr3 = c.begin()+8; std::cout << *(c.begin( ) + ( c.end( ) - c.begin( ) )/2 ) << std::endl; c.erase(itr2); std::cout << *itr1 << std::endl; std::cout << *itr2 << std::endl; std::cout << *itr3 << std::endl; std::cout << *(c.begin( ) + ( c.end( ) - c.begin( ) )/2 ) << std::endl; Vector< int > d; d.push_back(144); d.push_back(524); d.push_back(230); d.push_back(8); subtractOne( d.begin( ), d.end( ) ); for (int i = 0; i < d.size(); i++) { std::cout << d[i] << std:: endl;; } */ return 0; }
/* _lib7_Sock_connect: (Socket, Address) -> Void * * This function gets imported into the Mythryl world via: * src/lib/std/src/socket/socket-guts.pkg */ lib7_val_t _lib7_Sock_connect (lib7_state_t *lib7_state, lib7_val_t arg) { int socket = REC_SELINT(arg, 0); lib7_val_t addr = REC_SEL( arg, 1); int status; socklen_t addrlen = GET_SEQ_LEN(addr); { unsigned char* a = GET_SEQ_DATAPTR(unsigned char, addr); char buf[ 1024 ]; int i; buf[0] = '\0'; for (i = 0; i < addrlen; ++i) { sprintf (buf+strlen(buf), "%02x.", a[i]); } print_if( "connect.c/top: socket d=%d addrlen d=%d addr s='%s'\n", socket, addrlen, buf ); } errno = 0; status = connect ( socket, GET_SEQ_DATAPTR(struct sockaddr, addr), addrlen ); /* NB: Unix Network Programming p135 S5.9 says that * for connect() we cannot just retry on EINTR. * On p452 it says we must instead do a select(), * which will wait until the three-way TCP * handshake either succeeds or fails: */ /* Backed out 2010-02-26 CrT: See discussion at bottom of src/runtime/c-libs/lib7-socket/connect.c */ #ifdef SOME_OTHER_TIME if (status < 0 && errno == EINTR) { int eintr_count = 1; int maxfd = socket+1; fd_set read_set; fd_set write_set; do { print_if( "connect.c/mid: Caught EINTR #%d, doing a select() on fd %d\n", eintr_count, socket); FD_ZERO( &read_set); FD_ZERO(&write_set); FD_SET( socket, &read_set ); FD_SET( socket, &write_set ); errno = 0; status = select(maxfd, &read_set, &write_set, NULL, NULL); ++eintr_count; } while (status < 0 && errno == EINTR); /* According to p452, if the connection completes properly * the socket will be writable, but if it fails it will be * both readable and writable. On return 'status' is the * count of bits set in the fd_sets; if it is 2, the fd * is both readable and writable, implying connect failure. * To be on the safe side, in this case I ensure that status * is negative and errno set to something valid for a failed * connect(). I don't know if this situation is even possible: */ if (status == 2) { status = -1; errno = ENETUNREACH; /* Possibly ETIMEDOUT would be better? */ } } #endif print_if( "connect.c/bot: status d=%d errno d=%d\n", status, errno); CHECK_RETURN_UNIT(lib7_state, status); /* CHECK_RETURN_UNIT is from src/runtime/c-libs/lib7-c.h */ }