void PR_Profile_f (void) { int i, j; int pmax; dfunction_t *f, *bestFunc; int total; int funcCount; qboolean byHC; const char *saveName = NULL; FILE *saveFile = NULL; int currentFile; int bestFile; int tally; const char *s; if (!sv.active) return; byHC = false; funcCount = 10; for (i = 1; i < Cmd_Argc(); i++) { s = Cmd_Argv(i); if (*s == 'h' || *s == 'H') { // Sort by HC source file byHC = true; } else if (*s == 's' || *s == 'S') { // Save to file if (i + 1 < Cmd_Argc() && !q_isdigit(*Cmd_Argv(i + 1))) { i++; saveName = FS_MakePath(FS_USERDIR, NULL, Cmd_Argv(i)); } else { saveName = FS_MakePath(FS_USERDIR, NULL, "profile.txt"); } } else if (q_isdigit(*s)) { // Specify function count funcCount = atoi(Cmd_Argv(i)); if (funcCount < 1) { funcCount = 1; } } } total = 0; for (i = 0; i < progs->numfunctions; i++) { total += pr_functions[i].profile; } if (saveName) { // Create the output file saveFile = fopen(saveName, "w"); if (saveFile == NULL) Con_Printf("Could not open %s\n", saveName); } if (byHC == false) { j = 0; do { pmax = 0; bestFunc = NULL; for (i = 0; i < progs->numfunctions; i++) { f = &pr_functions[i]; if (f->profile > pmax) { pmax = f->profile; bestFunc = f; } } if (bestFunc) { if (j < funcCount) { if (saveFile) { fprintf(saveFile, "%05.2f %s\n", ((float)bestFunc->profile / (float)total) * 100.0, PR_GetString(bestFunc->s_name)); } else { Con_Printf("%05.2f %s\n", ((float)bestFunc->profile / (float)total) * 100.0, PR_GetString(bestFunc->s_name)); } } j++; bestFunc->profile = 0; } } while (bestFunc); if (saveFile) { fclose(saveFile); } return; } currentFile = -1; do { tally = 0; bestFile = Q_MAXINT; for (i = 0; i < progs->numfunctions; i++) { if (pr_functions[i].s_file > currentFile && pr_functions[i].s_file < bestFile) { bestFile = pr_functions[i].s_file; tally = pr_functions[i].profile; continue; } if (pr_functions[i].s_file == bestFile) { tally += pr_functions[i].profile; } } currentFile = bestFile; if (tally && currentFile != Q_MAXINT) { if (saveFile) { fprintf(saveFile, "\"%s\"\n", PR_GetString(currentFile)); } else { Con_Printf("\"%s\"\n", PR_GetString(currentFile)); } j = 0; do { pmax = 0; bestFunc = NULL; for (i = 0; i < progs->numfunctions; i++) { f = &pr_functions[i]; if (f->s_file == currentFile && f->profile > pmax) { pmax = f->profile; bestFunc = f; } } if (bestFunc) { if (j < funcCount) { if (saveFile) { fprintf(saveFile, " %05.2f %s\n", ((float)bestFunc->profile / (float)total) * 100.0, PR_GetString(bestFunc->s_name)); } else { Con_Printf(" %05.2f %s\n", ((float)bestFunc->profile / (float)total) * 100.0, PR_GetString(bestFunc->s_name)); } } j++; bestFunc->profile = 0; } } while (bestFunc); } } while (currentFile != Q_MAXINT); if (saveFile) { fclose(saveFile); } }
/** * Push one byte through the VT52 emulator. * * @param from_modem one byte from the remote side. * @param to_screen if the return is Q_EMUL_FSM_ONE_CHAR or * Q_EMUL_FSM_MANY_CHARS, then to_screen will have a character to display on * the screen. * @return one of the Q_EMULATION_STATUS constants. See emulation.h. */ Q_EMULATION_STATUS vt52(const unsigned char from_modem, wchar_t * to_screen) { static unsigned char *count; static attr_t attributes; int new_row; int new_col; unsigned char from_modem2; /* * The VT52 spec only supports 7-bit ASCII. Strip the high bit off every * character. */ from_modem2 = from_modem & 0x7F; DLOG(("STATE: %d CHAR: 0x%02x '%c'\n", scan_state, from_modem2, from_modem2)); vt52_start: switch (scan_state) { case SCAN_NONE: /* * ESC */ if (from_modem2 == C_ESC) { save_char(from_modem2, to_screen); scan_state = SCAN_ESC; return Q_EMUL_FSM_NO_CHAR_YET; } /* * Only a few control chars to handle here. CR and LF are in * emulation.c . */ if (from_modem2 == 0x05) { DLOG(("Enquire\n")); /* * ENQ - transmit the answerback message. */ qodem_write(q_child_tty_fd, get_option(Q_OPTION_ENQ_ANSWERBACK), strlen(get_option(Q_OPTION_ENQ_ANSWERBACK)), Q_TRUE); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 0x08) { DLOG(("Backspace\n")); /* * Backspace. */ cursor_left(1, Q_FALSE); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 0x09) { DLOG(("Tab\n")); /* * Tab. */ while (q_status.cursor_x < 80) { cursor_right(1, Q_FALSE); if (q_status.cursor_x % 8 == 0) { break; } } clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 0x7F) { DLOG(("Del\n")); /* * Del - consume but do nothing. */ clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } /* * Any other control characters. */ if (iscntrl(from_modem2)) { /* * Consume but do nothing. */ clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } /* * This is a printable character. */ *to_screen = map_character(from_modem2); return Q_EMUL_FSM_ONE_CHAR; case SCAN_Y_1: save_char(from_modem2, to_screen); scan_state = SCAN_Y_2; return Q_EMUL_FSM_NO_CHAR_YET; case SCAN_Y_2: /* * q_emul_buffer[0] = ESC * q_emul_buffer[1] = 'Y' */ new_row = q_emul_buffer[2] - 32; new_col = from_modem2 - 32; if (new_row < 0) { new_row = 0; } if (new_col < 0) { new_col = 0; } DLOG(("Cursor position: %d %d\n", new_row, new_col)); cursor_position(new_row, new_col); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; case SCAN_ESC: if (from_modem2 == 'A') { DLOG(("Cursor up\n")); cursor_up(1, Q_FALSE); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'B') { DLOG(("Cursor down\n")); cursor_down(1, Q_FALSE); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'C') { DLOG(("Cursor right\n")); cursor_right(1, Q_FALSE); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'D') { DLOG(("Cursor left\n")); cursor_left(1, Q_FALSE); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'E') { DLOG(("Erase entire screen\n")); /* * Cursor position to (0,0) and erase entire screen. */ cursor_formfeed(); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'F') { DLOG(("Graphics mode ON\n")); graphics_mode = Q_TRUE; clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'G') { DLOG(("Graphics mode OFF\n")); graphics_mode = Q_FALSE; clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'H') { DLOG(("Cursor home\n")); cursor_position(0, 0); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'I') { DLOG(("Reverse linefeed\n")); /* * Move up one column, inserting a line if already at the top. */ if (q_status.cursor_y == 0) { scroll_down(1); } else { cursor_up(1, Q_FALSE); } clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'J') { DLOG(("Erase to end of screen\n")); /* * Erase from here to end of screen. */ erase_screen(q_status.cursor_y, q_status.cursor_x, HEIGHT - STATUS_HEIGHT - 1, WIDTH - 1, Q_FALSE); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'K') { DLOG(("Erase to end of line\n")); /* * Erase from here to end of line. */ erase_line(q_status.cursor_x, q_scrollback_current->length, Q_FALSE); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'Y') { /* * Cursor position. */ save_char(from_modem2, to_screen); scan_state = SCAN_Y_1; return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'Z') { DLOG(("DECID\n")); /* * Identify */ /* * Note the VT100 and above will send <ESC>/Z, but the DECScope * manual claims the VT52 will send <ESC>/K if it does not have * an "integral electrolytic copier" (an internal printer that * used wet paper). */ qodem_write(q_child_tty_fd, "\033/K", 3, Q_TRUE); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == '=') { DLOG(("Alternate keypad ON\n")); q_vt52_alternate_keypad_mode = Q_TRUE; clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == '>') { DLOG(("Alternate keypad OFF\n")); q_vt52_alternate_keypad_mode = Q_FALSE; clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == '[') { if (q_status.vt52_color == Q_TRUE) { /* * Fall into SCAN_CSI only if VT52_COLOR is enabled. */ save_char(from_modem2, to_screen); scan_state = SCAN_CSI; return Q_EMUL_FSM_NO_CHAR_YET; } DLOG(("Hold screen mode ON\n")); q_status.hold_screen_mode = Q_TRUE; clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == '\\') { DLOG(("Hold screen mode OFF\n")); q_status.hold_screen_mode = Q_FALSE; clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } break; case SCAN_CSI: /* * We are only going to support CSI Pn [ ; Pn ... ] m a.k.a. ANSI * Select Graphics Rendition. We can see only a digit or 'm'. */ if (q_isdigit(from_modem2)) { /* * Save the position for the counter. */ count = q_emul_buffer + q_emul_buffer_n; save_char(from_modem2, to_screen); scan_state = SCAN_CSI_PARAM; return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'm') { /* * ESC [ m mean ESC [ 0 m, all attributes off. */ DLOG(("ANSI SGR: reset\n")); q_current_color = Q_A_NORMAL | scrollback_full_attr(Q_COLOR_CONSOLE_TEXT); clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } /* * This means we entered HOLD SCREEN mode. */ DLOG(("Hold screen mode ON\n")); q_status.hold_screen_mode = Q_TRUE; /* * Reprocess the character from the top. */ clear_state(to_screen); goto vt52_start; case SCAN_CSI_PARAM: /* * Following through on the SGR code, we are now looking only for a * digit, semicolon, or 'm' * */ if ((q_isdigit(from_modem2)) || (from_modem2 == ';')) { save_char(from_modem2, to_screen); scan_state = SCAN_CSI_PARAM; return Q_EMUL_FSM_NO_CHAR_YET; } if (from_modem2 == 'm') { DLOG(("ANSI SGR: change text attributes\n")); /* * Text attributes. */ if (ansi_color(&attributes, &count) == Q_TRUE) { q_current_color = attributes; } else { break; } clear_state(to_screen); return Q_EMUL_FSM_NO_CHAR_YET; } break; } /* * This point means we got most, but not all, of a sequence. */ q_emul_buffer[q_emul_buffer_n] = from_modem2; q_emul_buffer_n++; *to_screen = q_emul_buffer[q_emul_buffer_i]; q_emul_buffer_i++; scan_state = SCAN_NONE; /* * Special case: one character returns Q_EMUL_FSM_ONE_CHAR. */ if (q_emul_buffer_n == 1) { q_emul_buffer_i = 0; q_emul_buffer_n = 0; return Q_EMUL_FSM_ONE_CHAR; } return Q_EMUL_FSM_MANY_CHARS; }