static void run(void) { struct timeval starttime, endtime; u_int64_t totcycles; double time; gettimeofday(&starttime, NULL); runloop(); gettimeofday(&endtime, NULL); endtime.tv_sec -= starttime.tv_sec; if (endtime.tv_usec < starttime.tv_usec) { endtime.tv_sec--; endtime.tv_usec += 1000000; } endtime.tv_usec -= starttime.tv_usec; time = endtime.tv_sec + endtime.tv_usec/1000000.0; totcycles = showstats(); msg("Elapsed real time: %llu.%06lu seconds (%g mhz)", (unsigned long long) endtime.tv_sec, (unsigned long) endtime.tv_usec, totcycles/(time*1000000.0)); }
void main_dumpstate(void) { msg("mainloop: shutoff_flag %d continue_flag %d stop_flag %d", shutoff_flag, continue_flag, stop_flag); #ifdef USE_TRACE print_traceflags(); #endif gdb_dumpstate(); showstats(); clock_dumpstate(); cpu_dumpstate(); bus_dumpstate(); }
void pm_frameend() { float drawtime; float frametime; float queuewait; glFinish(); #if GL_PSP_statistics { GLuint t; glGetStatisticsuivPSP(GL_STATS_APPTIME_PSP, &t); drawtime = t; glGetStatisticsuivPSP(GL_STATS_FRAMETIME_PSP, &t); frametime = t; glGetStatisticsuivPSP(GL_STATS_QUEUEWAITTIME_PSP, &t); queuewait = t; glResetStatsPSP(GL_STATS_QUEUEWAITTIME_PSP); } #else end = now(); drawtime = (end - start); frametime = (end - prev); queuewait = 0; #endif drawtime /= 1000000.; frametime /= 1000000.; queuewait /= 1000000.; showstats(drawtime, frametime, queuewait); #if !GL_PSP_statistics prev = now(); #endif }
/* * This is the main drive for each connection. As you can tell, for the * first few steps we are using a blocking socket. If you remember the * older tinyproxy code, this use to be a very confusing state machine. * Well, no more! :) The sockets are only switched into nonblocking mode * when we start the relay portion. This makes most of the original * tinyproxy code, which was confusing, redundant. Hail progress. * - rjkaes */ void handle_connection(int fd) { struct conn_s *connptr; struct request_s *request = NULL; hashmap_t hashofheaders = NULL; char peer_ipaddr[PEER_IP_LENGTH]; char peer_string[PEER_STRING_LENGTH]; getpeer_information(fd, peer_ipaddr, peer_string); log_message(LOG_CONN, "Connect (file descriptor %d): %s [%s]", fd, peer_string, peer_ipaddr); connptr = initialize_conn(fd, peer_ipaddr, peer_string); if (!connptr) { close(fd); return; } if (check_acl(fd, peer_ipaddr, peer_string) <= 0) { update_stats(STAT_DENIED); indicate_http_error(connptr, 403, "Access denied", "detail", "The administrator of this proxy has not configured it to service requests from your host.", NULL); send_http_error_message(connptr); destroy_conn(connptr); return; } if (read_request_line(connptr) < 0) { update_stats(STAT_BADCONN); indicate_http_error(connptr, 408, "Timeout", "detail", "Server timeout waiting for the HTTP request from the client.", NULL); send_http_error_message(connptr); destroy_conn(connptr); return; } /* * The "hashofheaders" store the client's headers. */ if (!(hashofheaders = hashmap_create(HEADER_BUCKETS))) { update_stats(STAT_BADCONN); indicate_http_error(connptr, 503, "Internal error", "detail", "An internal server error occurred while processing your request. Please contact the administrator.", NULL); send_http_error_message(connptr); destroy_conn(connptr); return; } /* * Get all the headers from the client in a big hash. */ if (get_all_headers(connptr->client_fd, hashofheaders) < 0) { log_message(LOG_WARNING, "Could not retrieve all the headers from the client"); hashmap_delete(hashofheaders); update_stats(STAT_BADCONN); destroy_conn(connptr); return; } request = process_request(connptr, hashofheaders); if (!request) { if (!connptr->error_variables && !connptr->show_stats) { update_stats(STAT_BADCONN); destroy_conn(connptr); hashmap_delete(hashofheaders); return; } goto send_error; } connptr->upstream_proxy = UPSTREAM_HOST(request->host); if (connptr->upstream_proxy != NULL) { if (connect_to_upstream(connptr, request) < 0) { goto send_error; } } else { connptr->server_fd = opensock(request->host, request->port); if (connptr->server_fd < 0) { indicate_http_error(connptr, 500, "Unable to connect", "detail", PACKAGE " was unable to connect to the remote web server.", "error", strerror(errno), NULL); goto send_error; } log_message(LOG_CONN, "Established connection to host \"%s\" using file descriptor %d.", request->host, connptr->server_fd); if (!connptr->connect_method) establish_http_connection(connptr, request); } send_error: free_request_struct(request); if (process_client_headers(connptr, hashofheaders) < 0) { update_stats(STAT_BADCONN); if (!connptr->error_variables) { hashmap_delete(hashofheaders); destroy_conn(connptr); return; } } hashmap_delete(hashofheaders); if (connptr->error_variables) { send_http_error_message(connptr); destroy_conn(connptr); return; } else if (connptr->show_stats) { showstats(connptr); destroy_conn(connptr); return; } if (!connptr->connect_method || (connptr->upstream_proxy != NULL)) { if (process_server_headers(connptr) < 0) { if (connptr->error_variables) send_http_error_message(connptr); update_stats(STAT_BADCONN); destroy_conn(connptr); return; } } else { if (send_ssl_response(connptr) < 0) { log_message(LOG_ERR, "handle_connection: Could not send SSL greeting to client."); update_stats(STAT_BADCONN); destroy_conn(connptr); return; } } relay_connection(connptr); log_message(LOG_INFO, "Closed connection between local client (fd:%d) and remote client (fd:%d)", connptr->client_fd, connptr->server_fd); /* * All done... close everything and go home... :) */ destroy_conn(connptr); return; }
/* Read an event from the tracing output file. */ #if MP_GUI_SUPPORT static int readevent(XtPointer p) #else /* MP_GUI_SUPPORT */ static int readevent(void) #endif /* MP_GUI_SUPPORT */ { char s[4]; allocation *f; char *g, *h; void *a; size_t i, l, m; unsigned long n, t, u; if (refill(1)) switch (*bufferpos) { case 'A': bufferpos++; bufferlen--; currentevent++; n = getuleb128(); a = (void *) getuleb128(); l = getuleb128(); getsource(&t, &g, &h, &u); f = newalloc(n, currentevent, a, l); stats.acount++; stats.atotal += l; if (stats.pcount < stats.acount - stats.fcount) stats.pcount = stats.acount - stats.fcount; if (stats.ptotal < stats.atotal - stats.ftotal) stats.ptotal = stats.atotal - stats.ftotal; if ((stats.lsize == 0) || (stats.lsize > l)) stats.lsize = l; if (stats.usize < l) stats.usize = l; if (verbose) { fprintf(stdout, "%6lu alloc %6lu " MP_POINTER " %8lu" " %6lu %8lu\n", currentevent, n, a, l, stats.acount - stats.fcount, stats.atotal - stats.ftotal); if (displaysource) printsource(t, g, h, u); } if (hatffile != NULL) fprintf(hatffile, "1 %lu 0x%lx\n", l, a); if (f->entry != NULL) { if ((m = slotentry(f)) > maxslots) maxslots = m; fprintf(simfile, " {%lu, %lu, 0},\n", m, l); } #if MP_GUI_SUPPORT if (usegui) { if (addrbase == NULL) addrbase = (void *) __mp_rounddown((unsigned long) a, 1024); drawmemory(a, l, algc); return 0; } #endif /* MP_GUI_SUPPORT */ return 1; case 'R': bufferpos++; bufferlen--; currentevent++; n = getuleb128(); a = (void *) getuleb128(); l = getuleb128(); getsource(&t, &g, &h, &u); if (f = (allocation *) __mp_search(alloctree.root, n)) { if (f->time != 0) fprintf(stderr, "%s: Allocation index `%lu' has already " "been freed\n", progname, n); stats.acount++; stats.atotal += l; stats.fcount++; stats.ftotal += f->size; if (stats.pcount < stats.acount - stats.fcount) stats.pcount = stats.acount - stats.fcount; if (stats.ptotal < stats.atotal - stats.ftotal) stats.ptotal = stats.atotal - stats.ftotal; if ((stats.lsize == 0) || (stats.lsize > l)) stats.lsize = l; if (stats.usize < l) stats.usize = l; if (verbose) { fprintf(stdout, "%6lu realloc %6lu " MP_POINTER " %8lu %6lu %8lu\n", currentevent, n, a, l, stats.acount - stats.fcount, stats.atotal - stats.ftotal); if (displaysource) printsource(t, g, h, u); } if (hatffile != NULL) fprintf(hatffile, "4 %lu 0x%lx 0x%lx\n", l, f->addr, a); if (f->entry != NULL) { m = slotentry(f); fprintf(simfile, " {%lu, %lu, 1},\n", m, l); } #if MP_GUI_SUPPORT if (usegui) { drawmemory(f->addr, f->size, frgc); drawmemory(a, l, algc); } #endif /* MP_GUI_SUPPORT */ f->addr = a; f->size = l; } else fprintf(stderr, "%s: Unknown allocation index `%lu'\n", progname, n); #if MP_GUI_SUPPORT if (usegui) return 0; #endif /* MP_GUI_SUPPORT */ return 1; case 'F': bufferpos++; bufferlen--; currentevent++; n = getuleb128(); getsource(&t, &g, &h, &u); if (f = (allocation *) __mp_search(alloctree.root, n)) { if (f->time != 0) fprintf(stderr, "%s: Allocation index `%lu' has already " "been freed\n", progname, n); f->time = currentevent - f->event; stats.fcount++; stats.ftotal += f->size; if (verbose) { fprintf(stdout, "%6lu free %6lu " MP_POINTER " %8lu " "%6lu %6lu %8lu\n", currentevent, n, f->addr, f->size, f->time, stats.acount - stats.fcount, stats.atotal - stats.ftotal); if (displaysource) printsource(t, g, h, u); } if (hatffile != NULL) fprintf(hatffile, "2 0x%lx\n", f->addr); if (f->entry != NULL) { fprintf(simfile, " {%lu, 0, 0},\n", slotentry(f)); __mp_freeslot(&table, f->entry); f->entry = NULL; } #if MP_GUI_SUPPORT if (usegui) drawmemory(f->addr, f->size, frgc); #endif /* MP_GUI_SUPPORT */ } else fprintf(stderr, "%s: Unknown allocation index `%lu'\n", progname, n); #if MP_GUI_SUPPORT if (usegui) return 0; #endif /* MP_GUI_SUPPORT */ return 1; case 'H': bufferpos++; bufferlen--; a = (void *) getuleb128(); l = getuleb128(); if (verbose) fprintf(stdout, " reserve " MP_POINTER " %8lu\n", a, l); stats.rcount++; stats.rtotal += l; #if MP_GUI_SUPPORT if (usegui) { if (addrbase == NULL) addrbase = (void *) __mp_rounddown((unsigned long) a, 1024); drawmemory(a, l, frgc); return 0; } #endif /* MP_GUI_SUPPORT */ return 1; case 'I': bufferpos++; bufferlen--; a = (void *) getuleb128(); l = getuleb128(); if (verbose) fprintf(stdout, " internal " MP_POINTER " %8lu\n", a, l); stats.icount++; stats.itotal += l; #if MP_GUI_SUPPORT if (usegui) { drawmemory(a, l, ingc); return 0; } #endif /* MP_GUI_SUPPORT */ return 1; default: break; } if ((hatffile != NULL) && (hatffile != stdout) && (hatffile != stderr)) fclose(hatffile); if (simfile != NULL) { fputs(" {0, 0, 0}\n};\n\n\n", simfile); fputs("int main(void)\n{\n", simfile); fprintf(simfile, " void *p[%lu];\n", maxslots); fputs(" event *e;\n\n", simfile); fputs(" for (e = events; e->index != 0; e++)\n", simfile); fputs(" if (e->resize)\n", simfile); fputs(" {\n", simfile); fputs(" if ((p[e->index - 1] = realloc(p[e->index - 1], " "e->size)) == NULL)\n", simfile); fputs(" {\n", simfile); fputs(" fputs(\"out of memory\\n\", stderr);\n", simfile); fputs(" exit(EXIT_FAILURE);\n", simfile); fputs(" }\n", simfile); fputs(" }\n", simfile); fputs(" else if (e->size == 0)\n", simfile); fputs(" free(p[e->index - 1]);\n", simfile); fputs(" else if ((p[e->index - 1] = malloc(e->size)) == NULL)\n", simfile); fputs(" {\n", simfile); fputs(" fputs(\"out of memory\\n\", stderr);\n", simfile); fputs(" exit(EXIT_FAILURE);\n", simfile); fputs(" }\n", simfile); fputs(" return EXIT_SUCCESS;\n}\n", simfile); if ((simfile != stdout) && (simfile != stderr)) fclose(simfile); } getentry(s, sizeof(char), 4, 0); if (memcmp(s, MP_TRACEMAGIC, 4) != 0) { fprintf(stderr, "%s: Invalid file format\n", progname); exit(EXIT_FAILURE); } if (verbose) fputc('\n', stdout); showstats(); for (i = 0; i < MP_NAMECACHE_SIZE; i++) { if (funcnames[i] != NULL) free(funcnames[i]); if (filenames[i] != NULL) free(filenames[i]); } freeallocs(); fclose(tracefile); #if MP_GUI_SUPPORT if (usegui) return 1; #endif /* MP_GUI_SUPPORT */ return 0; }
void menu_option(unsigned char number) { FILE *savefile; FILE *optionfile; char filename[12], savepos; char oldinv; //holds options.inverted when entering setup int move_count; struct postype pos, newpos; switch (number) { case 100: //avcount=avtotal/avcount; if (g_path.move[0].f>0) showstats(nodes,g_seconds,g_depth,g_path); break; case 101: rival_help(70); break; case 119: rival_help(19); break; case 120: options.chessset++; if (options.chessset==3) options.chessset=0; break; case 109: options.whiteplayer=USER; options.blackplayer=USER; if (game.movenum>1) { game.movenum=game.movenum-1; pos=game.firstpos; for (move_count=1; move_count<=game.movenum; move_count++) { alter(&pos,game.previous_moves[move_count],&newpos); pos=newpos; } current=newpos; } else { game.movenum=0; current=game.firstpos; } movepointer=game.movenum; no_more_openings=FALSE; break; case 110: if (game.lastmove==0) { current=game.firstpos; } else { pos=game.firstpos; for (move_count=1; move_count<=game.lastmove; move_count++) { alter(&pos, game.previous_moves[move_count], &newpos); pos=newpos; } current=newpos; } game.movenum=game.lastmove; movepointer=game.movenum; break; case 111: current=game.firstpos; game.movenum=0; movepointer=game.movenum; no_more_openings=FALSE; options.whiteplayer=USER; options.blackplayer=USER; break; case 112: if ((savepos=get_savepos('w'))!=0) { strcpy(filename,"RIVAL\0"); if (savepos<10) { filename[5]=savepos+48; filename[6]='\0'; } else { filename[5]=savepos/10+48; filename[6]=savepos%10+48; filename[7]='\0'; } strcat(filename,".SAV"); if (confirmation("SAVE GAME")) { savefile=fopen(filename,"w"); if (savefile!=NULL) { savefiledata(savefile); } else // if savefile!=NULL { printf("ERROR! SAVE FAILED"); } fclose(savefile); } // if confirmation } break; case 113: if ((savepos=get_savepos('r'))!=0) { strcpy(filename,"RIVAL\0"); if (savepos<10) { filename[5]=savepos+48; filename[6]='\0'; } else { filename[5]=savepos/10+48; filename[6]=savepos%10+48; filename[7]='\0'; } strcat(filename, ".SAV"); if (((savefile=fopen(filename,"r"))!=NULL) && (confirmation("LOAD GAME"))) { readfiledata(savefile); if (game.movenum==0) { current=game.firstpos; movepointer=0; } else { pos=game.firstpos; for (move_count=1; move_count<=game.movenum; move_count++) { alter(&pos, game.previous_moves[move_count], &newpos); pos=newpos; } current=newpos; } FLAGnewstart=1; movepointer=game.movenum; } //movepointer=game.movenum; fclose(savefile); } break; case 107: variant_select(); break; case 106: time_select(); break; case 127: options.deep_thought=!options.deep_thought; break; case 133: break; case 118: options.library=!options.library; break; case 108: if (game.movenum<game.lastmove) { game.movenum=game.movenum+1; pos=current; alter(&pos,game.previous_moves[game.movenum],¤t); } movepointer=game.movenum; break; case 103: oldinv=options.inverted; options.inverted=0; enter_setup(); options.inverted=oldinv; break; case 117: options.analysis=!options.analysis; break; case 102: options.inverted=!options.inverted; break; case 104: options.whiteplayer=!options.whiteplayer; if (options.whiteplayer==PROGRAM) if (current.mvr=='w') FLAGnewstart=1; break; case 105: options.blackplayer=!options.blackplayer; if (options.blackplayer==PROGRAM) if (current.mvr=='b') FLAGnewstart=1; break; case 114: if (confirmation("NEW GAME")) initialise(startbrd); no_more_openings=FALSE; break; case 115: iconmenu=1; break; case 116: iconmenu=0; break; case 129: switch (options.sensitivity) { case LOWSENS : options.sensitivity=MEDSENS; break; case MEDSENS : options.sensitivity=HISENS; break; case HISENS : options.sensitivity=LOWSENS; break; } break; case 124: options=doptions; break; case 125: optionfile=fopen("options.riv","w"); fwrite(&options, sizeof(struct optiontype), 1, optionfile); fclose(optionfile); break; case 121: if (options.so<7) options.so+=1; else options.so=0; break; case 122: if (options.wo<35) options.wo+=5; else options.wo=0; if (options.wo==options.bo) if (options.wo<35) options.wo+=5; else options.wo=0; break; case 123: if (options.bo<35) options.bo+=5; else options.bo=0; if (options.wo==options.bo) if (options.bo<35) options.bo+=5; else options.bo=0; break; case 128: solvey(); break; case 130: break; case 148: options.game=0; break; case 126: options.pieceslide=!options.pieceslide; break; case 131: if (confirmation("QUIT RIVAL")) { SetTextMode(); printf("See you later!"); quit=1; } break; case 200: if (movepointer>0) movepointer--; break; case 201: if (movepointer<game.movenum) movepointer++; break; default: break; } }