Java 程序没有从 FIO 命令获取完整输出

问题描述 投票:0回答:0

我目前有一个使用命令行和参数运行 FIO 命令的程序。但它不会获取命令的完整输出,并且还会等待线程完成,然后再将任何内容打印到 GUI(不会冻结 GUI)。

public static String test_buffer(ArrayList<String> drives, int numJobs, int fileSize, int runtime, String byte_size) {
    String[] filenames = drives.stream()
            .map(diskName -> diskName.replaceAll("[^\\d]", ""))
            .map(diskName -> "--filename=\\\\.\\PhysicalDrive" + diskName)
            .toArray(String[]::new);

    String command = "C:\\Program Files\\fio\\fio.exe "
            + "--name=test "
            + "--bs=" + byte_size + " "
            + "--rw=read "
            + "--numjobs=" + numJobs + " "
            + "--size=" + fileSize + "g "
            + "--direct=1 "
            + "--runtime=" + runtime + " "
            + "--iodepth=16 "
            + "--eta-newline=1 "
            + String.join(" ", filenames);

    ExecutorService executor = Executors.newSingleThreadExecutor();
    StringBuilder output = new StringBuilder();
    objMargay_Controller.IO_TEXT_FIELD.setText(command + "\n");

    try {
        Process process = Runtime.getRuntime().exec(command);

        PipedOutputStream outputStream = new PipedOutputStream();
        PipedInputStream inputStream = new PipedInputStream(outputStream);
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

        executor.submit(() -> {
            try {
                String line;
                while ((line = reader.readLine()) != null) {
                    output.append(line).append("\n");
                    Log.IO_LOG(Programming.SAS_ADDR, line);
                    String finalLine = line;
                    Platform.runLater(() -> {
                        objMargay_Controller.IO_TEXT_FIELD.appendText(finalLine + "\n");
                        objMargay_Controller.IO_TEXT_FIELD.positionCaret(objMargay_Controller.IO_TEXT_FIELD.getLength());
                        objMargay_Controller.IO_TEXT_FIELD.setScrollTop(Double.MAX_VALUE);
                    });
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        });

        byte[] buffer = new byte[8192];
        int read;
        while ((read = process.getInputStream().read(buffer)) != -1) {
            outputStream.write(buffer, 0, read);
        }

        process.waitFor();
    } catch (Exception e) {
        e.printStackTrace();
    }

    executor.shutdown();
    return output.toString();
}

我的 GUI 中的输出给了我这个:

C:\Program Files\fio\fio.exe --name=test --bs=4k --rw=read --numjobs=2 --size=1g --direct=1 --runtime=20 --iodepth=16 --eta-newline=1 --filename=\\.\PhysicalDrive2 --filename=\\.\PhysicalDrive3
fio: this platform does not support process shared mutexes, forcing use of threads. Use the 'thread' option to get rid of this warning.
test: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=windowsaio, iodepth=16
...
fio-3.33
Starting 2 threads

test: (groupid=0, jobs=1): err= 0: pid=34208: Wed Feb 22 17:17:12 2023
  read: IOPS=12.3k, BW=48.1MiB/s (50.5MB/s)(963MiB/20002msec)
    slat (usec): min=6, max=194, avg=14.63, stdev= 4.49
    clat (nsec): min=371, max=151569k, avg=1280231.83, stdev=1443007.91
     lat (usec): min=31, max=151585, avg=1294.86, stdev=1442.83
    clat percentiles (usec):
     |  1.00th=[   50],  5.00th=[  128], 10.00th=[  141], 20.00th=[  190],
     | 30.00th=[  297], 40.00th=[  408], 50.00th=[  914], 60.00th=[ 2024],
     | 70.00th=[ 2180], 80.00th=[ 2278], 90.00th=[ 2409], 95.00th=[ 2540],
     | 99.00th=[ 4015], 99.50th=[ 5997], 99.90th=[ 8291], 99.95th=[ 9110],
     | 99.99th=[18744]
   bw (  KiB/s): min=41384, max=50952, per=50.04%, avg=49347.64, stdev=2453.12, samples=39
   iops        : min=10346, max=12738, avg=12336.74, stdev=613.22, samples=39
  lat (nsec)   : 500=0.01%, 750=0.01%
  lat (usec)   : 20=0.01%, 50=1.05%, 100=1.48%, 250=21.99%, 500=20.05%
  lat (usec)   : 750=4.32%, 1000=1.61%
  lat (msec)   : 2=8.62%, 4=39.88%, 10=0.96%, 20=0.03%, 50=0.01%
  lat (msec)   : 100=0.01%, 250=0.01%
  cpu          : usr=5.00%, sys=10.00%, ctx=0, majf=0, minf=0
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=9.6%, 16=90.3%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=99.9%, 8=0.1%, 16=0.1%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=246538,0,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=16
test: (groupid=0, jobs=1): err= 0: pid=21780: Wed Feb 22 17:17:12 2023
  read: IOPS=12.3k, BW=48.1MiB/s (50.5MB/s)(963MiB/20002msec)
    slat (usec): min=6, max=170, avg=14.30, stdev= 4.23
    clat (nsec): min=607, max=151422k, avg=1280571.28, stdev=1377931.65
     lat (usec): min=31, max=151436, avg=1294.88, stdev=1377.76
    clat percentiles (usec):
     |  1.00th=[   50],  5.00th=[  130], 10.00th=[  141], 20.00th=[  188],
     | 30.00th=[  297], 40.00th=[  404], 50.00th=[  873], 60.00th=[ 2024],
     | 70.00th=[ 2180], 80.00th=[ 2311], 90.00th=[ 2409], 95.00th=[ 2540],
     | 99.00th=[ 4293], 99.50th=[ 6259], 99.90th=[ 8094], 99.95th=[ 8848],
     | 99.99th=[25560]
   bw (  KiB/s): min=41392, max=52008, per=50.05%, avg=49348.05, stdev=2520.74, samples=39
   iops        : min=10348, max=13002, avg=12336.85, stdev=630.12, samples=39
  lat (nsec)   : 750=0.01%
  lat (usec)   : 20=0.01%, 50=0.99%, 100=1.10%, 250=22.62%, 500=20.15%
  lat (usec)   : 750=4.27%, 1000=1.55%
  lat (msec)   : 2=8.38%, 4=39.85%, 10=1.05%, 20=0.02%, 50=0.01%
  lat (msec)   : 100=0.01%, 250=0.01%
  cpu          : usr=5.00%, sys=10.00%, ctx=0, majf=0, minf=0
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=9.9%, 16=90.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=99.9%, 8=0.1%, 16=0.1%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=246547,0,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=16

Run status group 0 (all jobs):
   READ: bw=96.3MiB/s (101MB/s), 48.1MiB/s-48.1MiB/s (50.5MB/s-50.5MB/s), io=1926MiB (2020MB), run=20002-20002msec

但是,当从命令行运行相同的命令时,我得到这个:

C:\Program Files\fio>fio.exe --name=test --bs=4k --rw=read --numjobs=2 --size=1g --direct=1 --runtime=12 --iodepth=16 --terse-version=2 --eta-newline=1 --filename=\\.\PhysicalDrive2 --filename=\\.\PhysicalDrive3
fio: this platform does not support process shared mutexes, forcing use of threads. Use the 'thread' option to get rid of this warning.
test: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=windowsaio, iodepth=16
...
fio-3.33
Starting 2 threads
Jobs: 2 (f=4): [R(2)][25.0%][r=98.2MiB/s][r=25.1k IOPS][eta 00m:09s]
Jobs: 2 (f=4): [R(2)][41.7%][r=98.8MiB/s][r=25.3k IOPS][eta 00m:07s]
Jobs: 2 (f=4): [R(2)][58.3%][r=99.1MiB/s][r=25.4k IOPS][eta 00m:05s]
Jobs: 2 (f=4): [R(2)][75.0%][r=98.7MiB/s][r=25.3k IOPS][eta 00m:03s]
Jobs: 2 (f=4): [R(2)][91.7%][r=94.0MiB/s][r=24.1k IOPS][eta 00m:01s]
Jobs: 2 (f=4): [R(2)][100.0%][r=98.3MiB/s][r=25.2k IOPS][eta 00m:00s]
test: (groupid=0, jobs=1): err= 0: pid=24684: Wed Feb 22 17:36:59 2023
  read: IOPS=12.5k, BW=48.8MiB/s (51.2MB/s)(586MiB/12002msec)
    slat (usec): min=5, max=140, avg=11.90, stdev= 3.63
    clat (usec): min=17, max=173341, avg=1266.38, stdev=1621.94
     lat (usec): min=30, max=173348, avg=1278.28, stdev=1621.79
    clat percentiles (usec):
     |  1.00th=[  104],  5.00th=[  137], 10.00th=[  145], 20.00th=[  202],
     | 30.00th=[  302], 40.00th=[  392], 50.00th=[  848], 60.00th=[ 2024],
     | 70.00th=[ 2180], 80.00th=[ 2278], 90.00th=[ 2409], 95.00th=[ 2507],
     | 99.00th=[ 2704], 99.50th=[ 4080], 99.90th=[ 7504], 99.95th=[ 8225],
     | 99.99th=[18744]
   bw (  KiB/s): min=44464, max=51055, per=50.03%, avg=49986.78, stdev=1654.02, samples=23
   iops        : min=11116, max=12763, avg=12496.52, stdev=413.51, samples=23
  lat (usec)   : 20=0.01%, 50=0.33%, 100=0.60%, 250=22.62%, 500=22.00%
  lat (usec)   : 750=3.86%, 1000=1.23%
  lat (msec)   : 2=7.85%, 4=41.00%, 10=0.49%, 20=0.02%, 50=0.01%
  lat (msec)   : 250=0.01%
  cpu          : usr=0.00%, sys=8.33%, ctx=0, majf=0, minf=0
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=9.0%, 16=91.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.1%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=149908,0,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=16
test: (groupid=0, jobs=1): err= 0: pid=37548: Wed Feb 22 17:36:59 2023
  read: IOPS=12.5k, BW=48.8MiB/s (51.2MB/s)(586MiB/12002msec)
    slat (usec): min=5, max=204, avg=11.64, stdev= 3.39
    clat (nsec): min=535, max=173425k, avg=1266709.55, stdev=1542077.87
     lat (usec): min=37, max=173433, avg=1278.35, stdev=1541.97
    clat percentiles (usec):
     |  1.00th=[   59],  5.00th=[  131], 10.00th=[  145], 20.00th=[  200],
     | 30.00th=[  302], 40.00th=[  392], 50.00th=[  930], 60.00th=[ 2040],
     | 70.00th=[ 2180], 80.00th=[ 2278], 90.00th=[ 2409], 95.00th=[ 2507],
     | 99.00th=[ 2737], 99.50th=[ 3818], 99.90th=[ 7242], 99.95th=[ 8225],
     | 99.99th=[17433]
   bw (  KiB/s): min=44480, max=51007, per=50.03%, avg=49986.78, stdev=1652.07, samples=23
   iops        : min=11120, max=12751, avg=12496.52, stdev=413.02, samples=23
  lat (nsec)   : 750=0.01%
  lat (usec)   : 20=0.01%, 50=0.44%, 100=1.52%, 250=21.67%, 500=21.65%
  lat (usec)   : 750=3.77%, 1000=1.28%
  lat (msec)   : 2=8.09%, 4=41.10%, 10=0.45%, 20=0.01%, 250=0.01%
  cpu          : usr=0.00%, sys=8.33%, ctx=0, majf=0, minf=0
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=8.8%, 16=91.1%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.1%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=149906,0,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=16

Run status group 0 (all jobs):
   READ: bw=97.6MiB/s (102MB/s), 48.8MiB/s-48.8MiB/s (51.2MB/s-51.2MB/s), io=1171MiB (1228MB), run=12002-12002msec

我的问题是 - 为什么我在我的 GUI 中没有得到任何

Jobs: 2 (f=4): [R(2)][25.0%][r=98.2MiB/s][r=25.1k IOPS][eta 00m:09s]
行,但在直接从命令提示符运行时得到它们?我如何让这些行在它们发生时更新我的 GUI?

我也尝试过使用

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
并具有相同的输出。

java javafx command-line io java-threads
© www.soinside.com 2019 - 2024. All rights reserved.