Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * honggfuzz - display statistics |
| 4 | * ----------------------------------------- |
| 5 | * |
| 6 | * Author: Robert Swiecki <swiecki@google.com> |
| 7 | * |
| 8 | * Copyright 2010-2015 by Google Inc. All Rights Reserved. |
| 9 | * |
| 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 11 | * not use this file except in compliance with the License. You may obtain |
| 12 | * a copy of the License at |
| 13 | * |
| 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | * |
| 16 | * Unless required by applicable law or agreed to in writing, software |
| 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 19 | * implied. See the License for the specific language governing |
| 20 | * permissions and limitations under the License. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #define _WITH_DPRINTF |
| 25 | |
| 26 | #include "common.h" |
| 27 | #include "display.h" |
| 28 | |
| 29 | #include <string.h> |
Jagger | 7acbf2e | 2015-09-06 20:02:32 +0200 | [diff] [blame] | 30 | #include <stdarg.h> |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <unistd.h> |
Anestis Bechtsoudis | e83ec67 | 2015-12-26 20:28:28 +0200 | [diff] [blame] | 33 | #include <inttypes.h> |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 34 | |
| 35 | #include "log.h" |
Robert Swiecki | 81c6a0d | 2015-09-08 15:43:20 +0200 | [diff] [blame] | 36 | #include "util.h" |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 37 | |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 38 | #define ESC_CLEAR "\033[H\033[2J" |
| 39 | #define ESC_NAV(x,y) "\033["#x";"#y"H" |
Jagger | 76b11bc | 2015-09-06 02:11:44 +0200 | [diff] [blame] | 40 | #define ESC_BOLD "\033[1m" |
| 41 | #define ESC_RESET "\033[0m" |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 42 | |
Jagger | 7acbf2e | 2015-09-06 20:02:32 +0200 | [diff] [blame] | 43 | static void display_put(const char *fmt, ...) |
| 44 | { |
Jagger | 7acbf2e | 2015-09-06 20:02:32 +0200 | [diff] [blame] | 45 | va_list args; |
| 46 | va_start(args, fmt); |
Jagger | ff4a420 | 2016-03-22 12:41:41 +0100 | [diff] [blame] | 47 | vdprintf(STDOUT_FILENO, fmt, args); |
Jagger | 7acbf2e | 2015-09-06 20:02:32 +0200 | [diff] [blame] | 48 | va_end(args); |
Jagger | 7acbf2e | 2015-09-06 20:02:32 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Robert Swiecki | 7353a8d | 2015-09-08 15:53:59 +0200 | [diff] [blame] | 51 | static void display_displayLocked(honggfuzz_t * hfuzz) |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 52 | { |
Jagger | 269cea5 | 2015-09-06 04:46:07 +0200 | [diff] [blame] | 53 | unsigned long elapsed = (unsigned long)(time(NULL) - hfuzz->timeStart); |
Robert Swiecki | 81c6a0d | 2015-09-08 15:43:20 +0200 | [diff] [blame] | 54 | |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 55 | size_t curr_exec_cnt = ATOMIC_GET(hfuzz->mutationsCnt); |
Robert Swiecki | 81c6a0d | 2015-09-08 15:43:20 +0200 | [diff] [blame] | 56 | /* |
| 57 | * We increase the mutation counter unconditionally in threads, but if it's |
| 58 | * above hfuzz->mutationsMax we don't really execute the fuzzing loop. |
| 59 | * Therefore at the end of fuzzing, the mutation counter might be higher |
| 60 | * than hfuzz->mutationsMax |
| 61 | */ |
| 62 | if (hfuzz->mutationsMax > 0 && curr_exec_cnt > hfuzz->mutationsMax) { |
| 63 | curr_exec_cnt = hfuzz->mutationsMax; |
| 64 | } |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 65 | static size_t prev_exec_cnt = 0UL; |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 66 | uintptr_t exec_per_sec = curr_exec_cnt - prev_exec_cnt; |
| 67 | prev_exec_cnt = curr_exec_cnt; |
| 68 | |
Jagger | 7acbf2e | 2015-09-06 20:02:32 +0200 | [diff] [blame] | 69 | display_put("%s", ESC_CLEAR); |
Jagger | 3905f55 | 2015-09-06 21:04:37 +0200 | [diff] [blame] | 70 | display_put("============================== STAT ==============================\n"); |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 71 | |
Jagger | 7acbf2e | 2015-09-06 20:02:32 +0200 | [diff] [blame] | 72 | display_put("Iterations: " ESC_BOLD "%zu" ESC_RESET, curr_exec_cnt); |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 73 | if (hfuzz->mutationsMax) { |
Jagger | 7acbf2e | 2015-09-06 20:02:32 +0200 | [diff] [blame] | 74 | display_put(" (out of: " ESC_BOLD "%zu" ESC_RESET ")", hfuzz->mutationsMax); |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 75 | } |
Jagger | bcd5785 | 2015-09-06 23:10:44 +0200 | [diff] [blame] | 76 | display_put("\n"); |
Jagger | 56ed764 | 2015-09-06 04:06:57 +0200 | [diff] [blame] | 77 | |
Robert Swiecki | 81c6a0d | 2015-09-08 15:43:20 +0200 | [diff] [blame] | 78 | char start_time_str[128]; |
| 79 | util_getLocalTime("%F %T", start_time_str, sizeof(start_time_str), hfuzz->timeStart); |
| 80 | display_put("Start time: " ESC_BOLD "%s" ESC_RESET " (" ESC_BOLD "%lu" |
| 81 | ESC_RESET " seconds elapsed)\n", start_time_str, elapsed); |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 82 | |
Jagger | 7acbf2e | 2015-09-06 20:02:32 +0200 | [diff] [blame] | 83 | display_put("Input file/dir: '" ESC_BOLD "%s" ESC_RESET "'\n", hfuzz->inputFile); |
Robert Swiecki | 72d2bef | 2016-01-19 14:39:26 +0100 | [diff] [blame] | 84 | display_put("Fuzzed cmd: '" ESC_BOLD "%s" ESC_RESET "'\n", hfuzz->cmdline_txt); |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 85 | if (hfuzz->linux.pid > 0) { |
Anestis Bechtsoudis | 7c88d7a | 2016-02-09 17:55:38 +0200 | [diff] [blame] | 86 | display_put("Remote cmd [" ESC_BOLD "%d" ESC_RESET "]: '" ESC_BOLD "%s" ESC_RESET "'\n", |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 87 | hfuzz->linux.pid, hfuzz->linux.pidCmd); |
Anestis Bechtsoudis | 7c88d7a | 2016-02-09 17:55:38 +0200 | [diff] [blame] | 88 | } |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 89 | |
Jagger | 7acbf2e | 2015-09-06 20:02:32 +0200 | [diff] [blame] | 90 | display_put("Fuzzing threads: " ESC_BOLD "%zu" ESC_RESET "\n", hfuzz->threadsMax); |
Robert Swiecki | 9ef7b21 | 2016-03-31 18:06:48 +0200 | [diff] [blame] | 91 | display_put("Execs (iterations) per second: " ESC_BOLD "%zu" ESC_RESET " (avg: " ESC_BOLD "%zu" |
| 92 | ESC_RESET ")\n", exec_per_sec, elapsed ? (curr_exec_cnt / elapsed) : 0); |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 93 | |
Anestis Bechtsoudis | 46ea10e | 2015-11-07 18:16:25 +0200 | [diff] [blame] | 94 | /* If dry run, print also the input file count */ |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 95 | if (hfuzz->origFlipRate == 0.0L && hfuzz->useVerifier) { |
Anestis Bechtsoudis | 46ea10e | 2015-11-07 18:16:25 +0200 | [diff] [blame] | 96 | display_put("Input Files: '" ESC_BOLD "%zu" ESC_RESET "'\n", hfuzz->fileCnt); |
| 97 | } |
| 98 | |
Anestis Bechtsoudis | d59af69 | 2015-09-21 15:15:05 +0300 | [diff] [blame] | 99 | display_put("Crashes: " ESC_BOLD "%zu" ESC_RESET " (unique: " ESC_BOLD "%zu" ESC_RESET |
Anestis Bechtsoudis | 79b799e | 2015-11-01 00:02:25 +0200 | [diff] [blame] | 100 | ", blacklist: " ESC_BOLD "%zu" ESC_RESET ", verified: " ESC_BOLD "%zu" ESC_RESET |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 101 | ") \n", ATOMIC_GET(hfuzz->crashesCnt), |
| 102 | ATOMIC_GET(hfuzz->uniqueCrashesCnt), |
| 103 | ATOMIC_GET(hfuzz->blCrashesCnt), ATOMIC_GET(hfuzz->verifiedCrashesCnt)); |
| 104 | display_put("Timeouts: " ESC_BOLD "%zu" ESC_RESET "\n", ATOMIC_GET(hfuzz->timeoutedCnt)); |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 105 | |
Anestis Bechtsoudis | 02b99be | 2015-12-27 11:53:01 +0200 | [diff] [blame] | 106 | /* Feedback data sources are enabled. Start with common headers. */ |
| 107 | if (hfuzz->dynFileMethod != _HF_DYNFILE_NONE || hfuzz->useSanCov) { |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 108 | display_put("Number of dynamic files: " ESC_BOLD "%zu" ESC_RESET "\n", hfuzz->dynfileqCnt); |
Robert Swiecki | 5395840 | 2015-09-08 16:20:50 +0200 | [diff] [blame] | 109 | display_put("Coverage (max):\n"); |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 110 | } |
Anestis Bechtsoudis | 02b99be | 2015-12-27 11:53:01 +0200 | [diff] [blame] | 111 | |
| 112 | /* HW perf specific counters */ |
Robert Swiecki | 5395840 | 2015-09-08 16:20:50 +0200 | [diff] [blame] | 113 | if (hfuzz->dynFileMethod & _HF_DYNFILE_INSTR_COUNT) { |
Anestis Bechtsoudis | e83ec67 | 2015-12-26 20:28:28 +0200 | [diff] [blame] | 114 | display_put(" - cpu instructions: " ESC_BOLD "%" PRIu64 ESC_RESET "\n", |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 115 | ATOMIC_GET(hfuzz->linux.hwCnts.cpuInstrCnt)); |
Robert Swiecki | 5395840 | 2015-09-08 16:20:50 +0200 | [diff] [blame] | 116 | } |
| 117 | if (hfuzz->dynFileMethod & _HF_DYNFILE_BRANCH_COUNT) { |
Anestis Bechtsoudis | e83ec67 | 2015-12-26 20:28:28 +0200 | [diff] [blame] | 118 | display_put(" - cpu branches: " ESC_BOLD "%" PRIu64 ESC_RESET "\n", |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 119 | ATOMIC_GET(hfuzz->linux.hwCnts.cpuBranchCnt)); |
Robert Swiecki | 5395840 | 2015-09-08 16:20:50 +0200 | [diff] [blame] | 120 | } |
Jagger | 3abc560 | 2016-02-04 00:53:43 +0100 | [diff] [blame] | 121 | if (hfuzz->dynFileMethod & _HF_DYNFILE_BTS_BLOCK) { |
Jagger | 39bd2b0 | 2016-02-04 01:16:15 +0100 | [diff] [blame] | 122 | display_put(" - BTS unique blocks: " ESC_BOLD "%" PRIu64 ESC_RESET "\n", |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 123 | ATOMIC_GET(hfuzz->linux.hwCnts.bbCnt)); |
Robert Swiecki | 5395840 | 2015-09-08 16:20:50 +0200 | [diff] [blame] | 124 | } |
Jagger | 3abc560 | 2016-02-04 00:53:43 +0100 | [diff] [blame] | 125 | if (hfuzz->dynFileMethod & _HF_DYNFILE_BTS_EDGE) { |
Jagger | 39bd2b0 | 2016-02-04 01:16:15 +0100 | [diff] [blame] | 126 | display_put(" - BTS unique edges: " ESC_BOLD "%" PRIu64 ESC_RESET "\n", |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 127 | ATOMIC_GET(hfuzz->linux.hwCnts.bbCnt)); |
Robert Swiecki | 5395840 | 2015-09-08 16:20:50 +0200 | [diff] [blame] | 128 | } |
Jagger | a2addb6 | 2016-02-04 03:53:53 +0100 | [diff] [blame] | 129 | if (hfuzz->dynFileMethod & _HF_DYNFILE_IPT_BLOCK) { |
| 130 | display_put(" - PT unique blocks: " ESC_BOLD "%" PRIu64 ESC_RESET "\n", |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 131 | ATOMIC_GET(hfuzz->linux.hwCnts.bbCnt)); |
Jagger | a2addb6 | 2016-02-04 03:53:53 +0100 | [diff] [blame] | 132 | } |
Robert Swiecki | 5395840 | 2015-09-08 16:20:50 +0200 | [diff] [blame] | 133 | if (hfuzz->dynFileMethod & _HF_DYNFILE_CUSTOM) { |
Anestis Bechtsoudis | e83ec67 | 2015-12-26 20:28:28 +0200 | [diff] [blame] | 134 | display_put(" - custom counter: " ESC_BOLD "%" PRIu64 ESC_RESET "\n", |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 135 | ATOMIC_GET(hfuzz->linux.hwCnts.customCnt)); |
Robert Swiecki | 5395840 | 2015-09-08 16:20:50 +0200 | [diff] [blame] | 136 | } |
Anestis Bechtsoudis | 02b99be | 2015-12-27 11:53:01 +0200 | [diff] [blame] | 137 | |
| 138 | /* Sanitizer coverage specific counters */ |
Anestis Bechtsoudis | e83ec67 | 2015-12-26 20:28:28 +0200 | [diff] [blame] | 139 | if (hfuzz->useSanCov) { |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 140 | uint64_t hitBB = ATOMIC_GET(hfuzz->sanCovCnts.hitBBCnt); |
| 141 | uint64_t totalBB = ATOMIC_GET(hfuzz->sanCovCnts.totalBBCnt); |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 142 | uint8_t covPer = totalBB ? ((hitBB * 100) / totalBB) : 0; |
| 143 | display_put(" - total hit #bb: " ESC_BOLD "%" PRIu64 ESC_RESET " (coverage %d%%)\n", |
| 144 | hitBB, covPer); |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 145 | display_put(" - total #dso: " ESC_BOLD "%" PRIu64 ESC_RESET " (instrumented only)\n", |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 146 | ATOMIC_GET(hfuzz->sanCovCnts.iDsoCnt)); |
Anestis Bechtsoudis | 56e360f | 2016-01-11 14:29:17 +0200 | [diff] [blame] | 147 | display_put(" - discovered #bb: " ESC_BOLD "%" PRIu64 ESC_RESET " (new from input seed)\n", |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 148 | ATOMIC_GET(hfuzz->sanCovCnts.newBBCnt)); |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 149 | display_put(" - crashes: " ESC_BOLD "%" PRIu64 ESC_RESET "\n", |
Jagger | d34417d | 2016-03-16 01:26:54 +0100 | [diff] [blame] | 150 | ATOMIC_GET(hfuzz->sanCovCnts.crashesCnt)); |
Anestis Bechtsoudis | e83ec67 | 2015-12-26 20:28:28 +0200 | [diff] [blame] | 151 | } |
Jagger | 3905f55 | 2015-09-06 21:04:37 +0200 | [diff] [blame] | 152 | display_put("============================== LOGS ==============================\n"); |
Jagger | baa20ea | 2015-09-06 01:12:08 +0200 | [diff] [blame] | 153 | } |
Robert Swiecki | 7353a8d | 2015-09-08 15:53:59 +0200 | [diff] [blame] | 154 | |
| 155 | extern void display_display(honggfuzz_t * hfuzz) |
| 156 | { |
Robert Swiecki | 7353a8d | 2015-09-08 15:53:59 +0200 | [diff] [blame] | 157 | display_displayLocked(hfuzz); |
Robert Swiecki | 7353a8d | 2015-09-08 15:53:59 +0200 | [diff] [blame] | 158 | } |