通过bash将输出重定向到文件

时间:2018-05-28 22:52:20

标签: bash

我需要在MIPS和ARM处理器上运行一系列程序执行模拟,因为我正在使用名为MPSoCBench的基准测试。总共将有200多个模拟,所以我创建了一个bash脚本来逐个执行它并将输出保存到文件中。但是,由于某种原因,它不会像应该的那样重定向输出。

这是bash脚本:

source env.sh
echo "Simulation start"
./MPSoCBench -p=mips -s=stringsearch -i=noc.lt -n=1 -r > output/MIPS/stringsearch/stringsearch-1.out
./MPSoCBench -p=mips -s=stringsearch -i=noc.lt -n=2 -r > output/MIPS/stringsearch/stringsearch-2.out
./MPSoCBench -p=mips -s=stringsearch -i=noc.lt -n=4 -r > output/MIPS/stringsearch/stringsearch-4.out
./MPSoCBench -p=mips -s=stringsearch -i=noc.lt -n=8 -r > output/MIPS/stringsearch/stringsearch-8.out

./MPSoCBench -p=mips -s=dijkstra -i=noc.lt -n=1 -r > output/MIPS/dijkstra/dijkstra-1.out
./MPSoCBench -p=mips -s=dijkstra -i=noc.lt -n=2 -r > output/MIPS/dijkstra/dijkstra-2.out
./MPSoCBench -p=mips -s=dijkstra -i=noc.lt -n=4 -r > output/MIPS/dijkstra/dijkstra-4.out
./MPSoCBench -p=mips -s=dijkstra -i=noc.lt -n=8 -r > output/MIPS/dijkstra/dijkstra-8.out

./MPSoCBench -p=mips -s=sha -i=noc.lt -n=1 -r > output/MIPS/sha/sha-1.out
./MPSoCBench -p=mips -s=sha -i=noc.lt -n=2 -r > output/MIPS/sha/sha-2.out
./MPSoCBench -p=mips -s=sha -i=noc.lt -n=4 -r > output/MIPS/sha/sha-4.out
./MPSoCBench -p=mips -s=sha -i=noc.lt -n=8 -r > output/MIPS/sha/sha-8.out

./MPSoCBench -p=mips -s=basicmath -i=noc.lt -n=1 -r > output/MIPS/basicmath/basicmath-1.out
./MPSoCBench -p=mips -s=basicmath -i=noc.lt -n=2 -r > output/MIPS/basicmath/basicmath-2.out
./MPSoCBench -p=mips -s=basicmath -i=noc.lt -n=4 -r > output/MIPS/basicmath/basicmath-4.out
./MPSoCBench -p=mips -s=basicmath -i=noc.lt -n=8 -r > output/MIPS/basicmath/basicmath-8.out

./MPSoCBench -p=mips -s=susanedges -i=noc.lt -n=1 -r > output/MIPS/susanedges/susanedges-1.out
./MPSoCBench -p=mips -s=susanedges -i=noc.lt -n=2 -r > output/MIPS/susanedges/susanedges-2.out
./MPSoCBench -p=mips -s=susanedges -i=noc.lt -n=4 -r > output/MIPS/susanedges/susanedges-4.out
./MPSoCBench -p=mips -s=susanedges -i=noc.lt -n=8 -r > output/MIPS/susanedges/susanedges-8.out

./MPSoCBench -p=mips -s=susansmoothing -i=noc.lt -n=1 -r > output/MIPS/susansmoothing/susansmoothing-1.out
./MPSoCBench -p=mips -s=susansmoothing -i=noc.lt -n=2 -r > output/MIPS/susansmoothing/susansmoothing-2.out
./MPSoCBench -p=mips -s=susansmoothing -i=noc.lt -n=4 -r > output/MIPS/susansmoothing/susansmoothing-4.out
./MPSoCBench -p=mips -s=susansmoothing -i=noc.lt -n=8 -r > output/MIPS/susansmoothing/susansmoothing-8.out

./MPSoCBench -p=mips -s=susancorners -i=noc.lt -n=1 -r > output/MIPS/susancorners/susancorners-1.out
./MPSoCBench -p=mips -s=susancorners -i=noc.lt -n=2 -r > output/MIPS/susancorners/susancorners-2.out
./MPSoCBench -p=mips -s=susancorners -i=noc.lt -n=4 -r > output/MIPS/susancorners/susancorners-4.out
./MPSoCBench -p=mips -s=susancorners -i=noc.lt -n=8 -r > output/MIPS/susancorners/susancorners-8.out

#Começo das simulações ARM

./MPSoCBench -p=arm -s=stringsearch -i=noc.lt -n=1 -r > output/ARM/stringsearch/stringsearch-1.out
./MPSoCBench -p=arm -s=stringsearch -i=noc.lt -n=2 -r > output/ARM/stringsearch/stringsearch-2.out
./MPSoCBench -p=arm -s=stringsearch -i=noc.lt -n=4 -r > output/ARM/stringsearch/stringsearch-4.out
./MPSoCBench -p=arm -s=stringsearch -i=noc.lt -n=8 -r > output/ARM/stringsearch/stringsearch-8.out

./MPSoCBench -p=arm -s=dijkstra -i=noc.lt -n=1 -r > output/ARM/dijkstra/dijkstra-1.out
./MPSoCBench -p=arm -s=dijkstra -i=noc.lt -n=2 -r > output/ARM/dijkstra/dijkstra-2.out
./MPSoCBench -p=arm -s=dijkstra -i=noc.lt -n=4 -r > output/ARM/dijkstra/dijkstra-4.out
./MPSoCBench -p=arm -s=dijkstra -i=noc.lt -n=8 -r > output/ARM/dijkstra/dijkstra-8.out

./MPSoCBench -p=arm -s=sha -i=noc.lt -n=1 -r > output/ARM/sha/sha-1.out
./MPSoCBench -p=arm -s=sha -i=noc.lt -n=2 -r > output/ARM/sha/sha-2.out
./MPSoCBench -p=arm -s=sha -i=noc.lt -n=4 -r > output/ARM/sha/sha-4.out
./MPSoCBench -p=arm -s=sha -i=noc.lt -n=8 -r > output/ARM/sha/sha-8.out

./MPSoCBench -p=arm -s=basicmath -i=noc.lt -n=1 -r > output/ARM/basicmath/basicmath-1.out
./MPSoCBench -p=arm -s=basicmath -i=noc.lt -n=2 -r > output/ARM/basicmath/basicmath-2.out
./MPSoCBench -p=arm -s=basicmath -i=noc.lt -n=4 -r > output/ARM/basicmath/basicmath-4.out
./MPSoCBench -p=arm -s=basicmath -i=noc.lt -n=8 -r > output/ARM/basicmath/basicmath-8.out

./MPSoCBench -p=arm -s=susanedges -i=noc.lt -n=1 -r > output/ARM/susanedges/susanedges-1.out
./MPSoCBench -p=arm -s=susanedges -i=noc.lt -n=2 -r > output/ARM/susanedges/susanedges-2.out
./MPSoCBench -p=arm -s=susanedges -i=noc.lt -n=4 -r > output/ARM/susanedges/susanedges-4.out
./MPSoCBench -p=arm -s=susanedges -i=noc.lt -n=8 -r > output/ARM/susanedges/susanedges-8.out

./MPSoCBench -p=arm -s=susansmoothing -i=noc.lt -n=1 -r > output/ARM/susansmoothing/susansmoothing-1.out
./MPSoCBench -p=arm -s=susansmoothing -i=noc.lt -n=2 -r > output/ARM/susansmoothing/susansmoothing-2.out
./MPSoCBench -p=arm -s=susansmoothing -i=noc.lt -n=4 -r > output/ARM/susansmoothing/susansmoothing-4.out
./MPSoCBench -p=arm -s=susansmoothing -i=noc.lt -n=8 -r > output/ARM/susansmoothing/susansmoothing-8.out

./MPSoCBench -p=arm -s=susancorners -i=noc.lt -n=1 -r > output/ARM/susancorners/susancorners-1.out
./MPSoCBench -p=arm -s=susancorners -i=noc.lt -n=2 -r > output/ARM/susancorners/susancorners-2.out
./MPSoCBench -p=arm -s=susancorners -i=noc.lt -n=4 -r > output/ARM/susancorners/susancorners-4.out
./MPSoCBench -p=arm -s=susancorners -i=noc.lt -n=8 -r > output/ARM/susancorners/susancorners-8.out
echo "Simulation end"

例如,如果我运行:./MPSoCBench -p=mips -s=susansmoothing -i=noc.lt -n=1 -r

终端输出为:

[['mips'], ['1'], ['susansmoothing'], ['noc.lt']]
./platform.noc.lt.x susansmoothing.mips.x 1

        SystemC 2.3.1-Accellera --- May 26 2018 15:28:48
        Copyright (c) 1996-2014 by all Contributors,
        ALL RIGHTS RESERVED

NOC:

2 Lines

2 Columns

4 Peripherals

1 Masters

3 Slaves

0 Inactive Nodes

4 Wrappers for Masters/Slaves

Printing mesh!

mesh[0][0]: status-> 1  x->0  y->0
mesh[0][1]: status-> 1  x->0  y->1
mesh[1][0]: status-> 1  x->1  y->0
mesh[1][1]: status-> 1  x->1  y->1
Printing Table of routs!
Number of Active Lines in the table of routs: 4 
m[0]: 536870912 0 0
 m[1]: 553648128 0 1
 m[2]: 570425344 1 0
 m[3]: 587202560 1 1
 ArchC: Reading ELF application file: susansmoothing.mips.x


ArchC: -------------------- Starting Simulation --------------------

MPSoCBench: The simulator is prepared.
MPSoCBench: Beggining of time simulation measurement.


--------------------------------------------------------------------
--------------------------  MPSoCBench------------------------------
------------------- Running: susansmoothing ------------------------
--------------- The results will be available in -------------------
--------------------  the output.pgm file---------------------------
--------------------------------------------------------------------


Join Point->0 of 1 processors are not over yet...
Join Point->0 of 1 processors are not over yet...

ArchC: -------------------- Simulation Finished --------------------
Load word counter = 26316758
Store word counter = 12413560
Add Sub counter = 14802018
Mult Div counter = 7571964
Logic Op counter = 638874
Comparision Op counter = 2287692
Branches counter = 3022673
NOP counter = 22570205
SYSTEM Calls counter = 0

Info: /OSCI/SystemC: Simulation stopped by user.
ArchC: Simulation statistics
    Times: 33.87 user, 0.12 system, 33.58 real
    Number of instructions executed: 89623826
    Simulation speed: 2646.11 K instr/s
cache: IC
Cache statistics:
Read:   miss: 7792815 (8.69503%) hit: 81830929 (91.305%)
Write:  miss: 0 (0%) hit: 0 (0%)
Number of block evictions: 2911967
cache: DC
Cache statistics:
Read:   miss: 5480795 (20.9281%) hit: 20707932 (79.0719%)
Write:  miss: 534193 (4.3008%) hit: 11886589 (95.6992%)
Number of block evictions: 973023

Total Time Taken (seconds): 33.581356
Simulation advance (seconds):   0.634481
MPSoCBench: Ending the time simulation measurement.


Lock Access:    138
Memory Reads:   27615606 
Memory Writes:  24841564

TESTING RESULTS

Test Passed.

如果我尝试使用以下命令将此输出重定向到文件:./MPSoCBench -p=mips -s=susansmoothing -i=noc.lt -n=1 -r > output/MIPS/susansmoothing/susansmoothing-1

然后发生了一些奇怪的事情,首先还有终端输出:

        SystemC 2.3.1-Accellera --- May 26 2018 15:28:48
        Copyright (c) 1996-2014 by all Contributors,
        ALL RIGHTS RESERVED
ArchC: Reading ELF application file: susansmoothing.mips.x


ArchC: -------------------- Starting Simulation --------------------

ArchC: -------------------- Simulation Finished --------------------
Load word counter = 26316752
Store word counter = 12413554
Add Sub counter = 14802013
Mult Div counter = 7571962
Logic Op counter = 638873
Comparision Op counter = 2287692
Branches counter = 3022669
NOP counter = 22570200
SYSTEM Calls counter = 0

Info: /OSCI/SystemC: Simulation stopped by user.
ArchC: Simulation statistics
    Times: 35.22 user, 0.12 system, 34.93 real
    Number of instructions executed: 89623796
    Simulation speed: 2544.68 K instr/s
cache: IC
Cache statistics:
Read:   miss: 7793395 (8.69568%) hit: 81830320 (91.3043%)
Write:  miss: 0 (0%) hit: 0 (0%)
Number of block evictions: 2911975
cache: DC
Cache statistics:
Read:   miss: 5481489 (20.9307%) hit: 20707230 (79.0693%)
Write:  miss: 534593 (4.30402%) hit: 11886183 (95.696%)
Number of block evictions: 973878

Total Time Taken (seconds): 34.931891
Simulation advance (seconds):   0.634481
MPSoCBench: Ending the time simulation measurement.


Lock Access:    138
Memory Reads:   27618954 
Memory Writes:  24841552

最后这里是文件susansmoothing-1:

./platform.noc.lt.x susansmoothing.mips.x 1

NOC:

2 Lines

2 Columns

4 Peripherals

1 Masters

3 Slaves

0 Inactive Nodes

4 Wrappers for Masters/Slaves

Printing mesh!

mesh[0][0]: status-> 1  x->0  y->0
mesh[0][1]: status-> 1  x->0  y->1
mesh[1][0]: status-> 1  x->1  y->0
mesh[1][1]: status-> 1  x->1  y->1
Printing Table of routs!
Number of Active Lines in the table of routs: 4 
m[0]: 536870912 0 0
 m[1]: 553648128 0 1
 m[2]: 570425344 1 0
 m[3]: 587202560 1 1


--------------------------------------------------------------------
--------------------------  MPSoCBench------------------------------
------------------- Running: susansmoothing ------------------------
--------------- The results will be available in -------------------
--------------------  the output.pgm file---------------------------
--------------------------------------------------------------------


Join Point->0 of 1 processors are not over yet...
Join Point->0 of 1 processors are not over yet...

MPSoCBench: The simulator is prepared.
MPSoCBench: Beggining of time simulation measurement.


TESTING RESULTS

Test Passed.

[['mips'], ['1'], ['susansmoothing'], ['noc.lt']]

就像有些线路被重定向而其他线路没有被重定向,这里发生了什么?也许多线程?如果是,我如何等待程序完成执行,然后将终端输出复制到文件?

谢谢。

1 个答案:

答案 0 :(得分:1)

程序输出似乎在STDERR而不是STDOUT上。试一试:

./MPSoCBench -p=mips -s=dijkstra -i=noc.lt -n=2 -r > output/MIPS/dijkstra/dijkstra-2.out

更改为

./MPSoCBench -p=mips -s=dijkstra -i=noc.lt -n=2 -r > output/MIPS/dijkstra/dijkstra-2.out 2>&1

请注意重定向后添加的2>&1。它发送STDERR - > STDOUT。

相关问题