function getTraceStatsValue()

in webview-ui/src/manualTest/inspektorGadgetTests.tsx [249:368]


    function getTraceStatsValue(columnKey: string): TraceOutputValue | undefined {
        const operations = ["accept", "close"];
        const protocols = ["TCP", "UDP"];
        const qrValues = ["Q", "R"];
        const packetTypes = ["HOST", "OUTGOING", "OTHERHOST"];
        const queryTypes = ["A", "AAAA"];
        const socketStatuses = ["ESTABLISHED", "LISTEN", "TIME_WAIT", "INACTIVE", "ACTIVE"];
        switch (columnKey) {
            case "family":
                return 2;
            case "ipversion":
                return 4;
            case "src.addr":
                return "10.244.0.11";
            case "dst.addr":
                return "52.191.16.54";
            case "src.port":
                return "55555";
            case "dst.port":
                return "443";
            case "sent":
                return ~~(Math.random() * 1000);
            case "received":
                return ~~(Math.random() * 1000);
            case "type":
                return "normal";
            case "message":
                return undefined; // Set when type is in (ERR, WARN, DEBUG, INFO)
            case "operation":
                return operations[~~(Math.random() * operations.length)];
            case "netnsid":
                return ~~(Math.random() * 1000000000) + 4000000000;
            case "protocol":
                return protocols[~~(Math.random() * protocols.length)];
            case "status":
                return socketStatuses[~~(Math.random() * socketStatuses.length)];
            case "inodeNumber":
                return ~~(Math.random() * 65535);
            case "reads":
                return ~~(Math.random() * 100);
            case "writes":
                return ~~(Math.random() * 10);
            case "rbytes":
                return ~~(Math.random() * 10000);
            case "wbytes":
                return ~~(Math.random() * 1000);
            case "fileType":
                return "R".charCodeAt(0);
            case "filename":
                return "file.txt";
            case "write":
                return !~~(Math.random() * 2);
            case "major":
                return ~~(Math.random() * 10);
            case "minor":
                return undefined;
            case "bytes":
                return ~~(Math.random() * 1000);
            case "us":
                return ~~(Math.random() * 1000);
            case "ops":
                return ~~(Math.random() * 100);
            case "currentRuntime":
                return ~~(Math.random() * 1000);
            case "currentRunCount":
                return ~~(Math.random() * 10);
            case "cumulRuntime":
                return ~~(Math.random() * 10000);
            case "cumulRunCount":
                return ~~(Math.random() * 100);
            case "totalRuntime":
                return ~~(Math.random() * 20000);
            case "totalRunCount":
                return ~~(Math.random() * 200);
            case "mapMemory":
                return ~~(Math.random() * 10000);
            case "mapCount":
                return ~~(Math.random() * 10);
            case "totalCpuUsage":
                return ~~(Math.random() * 100) * 0.0001;
            case "perCpuUsage":
                return ~~(Math.random() * 100) * 0.0001;
            case "kernelStack":
                return `["hrtimer_active", "do_nanosleep", "hrtimer_nanosleep", "__x64_sys_nanosleep", "do_syscall_64", "entry_SYSCALL_64_after_hwframe"]`;
            case "userStack":
                return `["[unknown]", "[unknown]", "[unknown]", "[unknown]", "[unknown]", "[unknown]", "[unknown]"]`;
            case "count":
                return ~~(Math.random() * 5);
            case "timestamp":
                return new Date().getTime() * 1000000 + ~~(Math.random() * 1000000); // fake nanosecond resolution
            case "id":
                return Array.from({ length: 4 }, () => ~~(Math.random() * 16))
                    .map((byte) => (byte & 0xff).toString(16))
                    .join(""); // Random 4-character hex string
            case "qr":
                return qrValues[~~(Math.random() * qrValues.length)];
            case "nameserver":
                return "168.61.144.22";
            case "pktType":
                return packetTypes[~~(Math.random() * packetTypes.length)];
            case "qtype":
                return queryTypes[~~(Math.random() * queryTypes.length)];
            case "name":
                return "some.domain.com";
            case "rcode":
                return "NoError";
            case "numAnswers":
                return 1;
            case "addresses":
                return `["20.40.70.210"]`;
            case "ret":
                return 0;
            case "args":
                return `["-arg", "14"]`;
            case "cwd":
                return "/path/to/cwd";
            default:
                return `${columnKey}?`;
        }
    }