forked from intel/media-delivery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MSPerf.py
executable file
·1575 lines (1393 loc) · 100 KB
/
MSPerf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/python3
##################################################################################
# Copyright (c) 2020 Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
##################################################################################
##################################################################################
# By default script attempts to run all possible scenarios for the input clip.
# For example, if HEVC input it will run HEVC-AVC, HEVC-HEVC, etc. If encoder
# does not support input video (typically - resolution), we need to skip scenario
# and avoid error to let other scenarios execute.
##################################################################################
##################################################################################
# Performance automation flow: (by intel pnp silicon lab)
##################################################################################
import subprocess, sys, os, re, argparse, time, statistics, signal, getpass
########### James.Iwan@intel.com MSPerf ######################################
class MediaContent:
width = encode_bitrate = fps_target = performance_stream = performance_fps = init_stream_number = linux_perf_cmdlines = 0
def name (self, name):
self.name = name
def encode_bitrate (self, encode_bitrate):
self.encode_bitrate = encode_bitrate
def height (self, height):
self.height = height
def fps_target (self, fps_target):
self.fps_target = fps_target
def width(self, width):
self.width = width
def codec(self, codec):
self.codec = codec
def performance_stream (self, performance_stream):
self.performance_stream = performance_stream
def performance_fps (self, performance_fps):
self.performance_fps = performance_fps
def init_stream_number (self, init_stream_number):
self.init_stream_number = init_stream_number
def dispatch_cmdline (self, dispatch_cmdline):
self.dispatch_cmdline = dispatch_cmdline
def temp_path (self, temp_path):
self.temp_path = temp_path
def ffmpeg_mode (self, ffmpeg_mode):
self.ffmpeg_mode = ffmpeg_mode
# GemObject Tools
def filename_gpumem_trace(self, filename_gpumem_trace):
self.filename_gpumem_trace = filename_gpumem_trace
def gemobject_gpumem_trace_dump(self, gemobject_gpumem_trace_dump):
self.gemobject_gpumem_trace_dump = gemobject_gpumem_trace_dump
# Top Tools
def filename_cpumem_trace (self, filename_cpumem_trace):
self.filename_cpumem_trace = filename_cpumem_trace
def top_cpumem_trace_dump (self, top_cpumem_trace_dump):
self.top_cpumem_trace_dump = top_cpumem_trace_dump
# Linux Perf Tools
def linux_perf_dump (self, linux_perf_dump):
self.linux_perf_dump = linux_perf_dump
def linux_perf_gpu_freq_trace_dump (self, linux_perf_gpu_freq_trace_dump):
self.linux_perf_gpu_freq_trace_dump = linux_perf_gpu_freq_trace_dump
def filename_gpu_freq_trace (self, filename_gpu_freq_trace):
self.filename_gpu_freq_trace = filename_gpu_freq_trace
def linux_perf_mem_bw_trace_dump (self, linux_perf_mem_bw_trace_dump):
self.linux_perf_mem_bw_trace_dump = linux_perf_mem_bw_trace_dump
def filename_mem_bw_trace (self, filename_mem_bw_trace):
self.filename_mem_bw_trace = filename_mem_bw_trace
def tool_linux_perf_trace (self, tool_linux_perf_trace):
self.tool_linux_perf_trace = tool_linux_perf_trace
def linux_perf_cmdlines(self, linux_perf_cmdlines):
self.linux_perf_cmdlines = linux_perf_cmdlines
########### James.Iwan@intel.com MSPerf ######################################
def main():
startTime = time.time()
# Collect command line arguments
parser = argparse.ArgumentParser(description='MSPERF (MULTI STREAM PERFORMANCE) v0.20.06.03', conflict_handler='resolve')
parser.add_argument('workloads_path',help='Full path option for workload_directories/ OR for single workload_file')
parser.add_argument('--skip-ffmpeg', '--skip_ffmpeg', action='store_true', default=False, help='skipping measure that use FFMPEG app')
parser.add_argument('--skip-msdk', '--skip_msdk', action='store_true', default=False, help='skipping measure that use MSDK/Sample app')
parser.add_argument('--skip-perf', '--skip_perf', action='store_true', default=False, help='skipping linux perf stat Utilization, such as VD0/VD1/RCS/etc')
parser.add_argument('--skip-perf-trace', '--skip_perf_trace', action='store_true', default=False, help='skipping linux perf stat additional Traces, such as GT-Freq/BW-Rd/BW-Wr/etc')
parser.add_argument('--enable-debugfs', '--enable_debugfs', action='store_true', default=False, help='enabling further analysis tools such as CPU_mem, GPU_mem, etc')
parser.add_argument('--density-decode', '--density_decode', action='store_true', default=False, help='Enabling Density Decode support, HEVC and AVC')
parser.add_argument('--use-vdenc', '--use_vdenc', action='store_true', default=False,help='Enabling Fixed Function VDENC and LowPower mode')
parser.add_argument('--use-enctools', '--use_enctools', action='store_true', default=False, help='Enabling Enc tools default config file ')
parser.add_argument('--enctools-lad', '--enctools_lad', help='Custom Look Ahead Depth , Default=8')
parser.add_argument('--tu', '--tu', help='Custom Target Usage preset , Default=medium')
parser.add_argument('--async-depth', '--async_depth', help='Custom Async depth , Default depends on resoultion')
parser.add_argument('-c', '--codec', help='To choose Encoder Codec type, AVC or HEVC, Default will execute all')
parser.add_argument('-s', '--startStreams', help='To set starting of multi stream performance measurement, e.g. --startStreams 720p:8,1080p:5,2160p:2 or all:2, Default=all:1')
parser.add_argument('-e', '--endStreams', help='To set ending number of multi stream performance measurement, e.g. --endStreams 5, Default=NoLimit')
parser.add_argument('-n', '--numbers_of_iteration', help='Custom limit the number of iteration of each same execution (max is 4), Default=1')
parser.add_argument('--no-fps-limit', '--no_fps_limit', action='store_true', default=False, help='to run workload unconstraint, or as fast as possible')
parser.add_argument('--fps-target', '--fps_target', help='to overwrite fps limit, Default=input-fps')
parser.add_argument('-w_max', '--numbers_of_Workloads', help='Custom limit the number of total workloads to be executed')
parser.add_argument('-o', '--outdir', help='output directory for any artifacts')
parser.add_argument('-log', '--output_log_file', help='print any run-log into this file onto main directory, Default=msperf.txt')
parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Dump debug related printout, such as each-cmdlines/version-log/etc')
global ARGS
ARGS = parser.parse_args()
################################# Set artifacts path ##################################################
artifacts_path_default = os.getenv("HOME")
artifacts = os.getenv("ARTIFACTS")
if str(ARGS.outdir) != "None":
artifacts_path_users = os.path.realpath(ARGS.outdir)
artifact_path = artifacts_path_users + "/"
elif str(artifacts) != "None":
artifact_path = artifacts + "/measure/perf/"
else:
artifact_path = artifacts_path_default + "/measure/perf/"
################################# Multiple Device default/user overwrite check #########################
os_env_DEVICE = "/dev/dri/renderD128"
for k, v in os.environ.items():
if k == "DEVICE":
os_env_DEVICE = os.environ['DEVICE']
################################# Variable Assignment #################################################
starting_streamnumber = str(ARGS.startStreams) if ARGS.startStreams else "all:1"
maximum_iteration = int(ARGS.numbers_of_iteration) if ARGS.numbers_of_iteration else 1
endStreams = int(ARGS.endStreams) if ARGS.endStreams else 99
maximum_workloads = int(ARGS.numbers_of_Workloads) if ARGS.numbers_of_Workloads else 20
debug_verbose = ARGS.verbose
no_fps_limit = ARGS.no_fps_limit
tool_linux_perf = not ARGS.skip_perf
tool_linux_perf_trace = not ARGS.skip_perf_trace
enable_debugfs = ARGS.enable_debugfs
skip_ffmpeg = ARGS.skip_ffmpeg
skip_msdk = ARGS.skip_msdk
density_decode = ARGS.density_decode
use_vdenc = ARGS.use_vdenc
encode_codec = str(ARGS.codec).lower() if ARGS.codec else "all"
fps_target = float(ARGS.fps_target) if ARGS.fps_target else 0
script_root_path = os.path.dirname(os.path.realpath(__file__))
output_log_filename = str(ARGS.output_log_file) if str(ARGS.output_log_file) != "None" else "msperf.txt"
temp_path = "/tmp/perf/"
##################################################################################
# Initiate artifacts directory
##################################################################################
try:
# checks if path is a directory
isDirectory = os.path.isdir(artifact_path)
if not isDirectory:
os.system("mkdir -p " + artifact_path)
output_log_file = artifact_path + output_log_filename
output_log_handle = open(output_log_file, 'w')
except:
message_block(output_log_handle,'red', 'Unable to create artifact path ' + artifact_path)
raise sys.exit(1)
######################################################################################################
if debug_verbose:
printLog(output_log_handle, '#' * 69)
printLog(output_log_handle, 'MSPERF (MULTI STREAMS PERFORMANCE) v0.20.06.03')
printLog(output_log_handle, '#' * 69 + '\n')
if use_vdenc:
isSupported_vdenc_h264high = subprocess.Popen([os.path.dirname(os.path.realpath(__file__)) + '/isVdenc.sh', 'H264High'])
isSupported_vdenc_hevcmain = subprocess.Popen([os.path.dirname(os.path.realpath(__file__)) + '/isVdenc.sh', 'HEVCMain'])
if (isSupported_vdenc_h264high.returncode=="None") and (isSupported_vdenc_hevcmain.returncode=="None") :
printLog(output_log_handle, "VDENC supports has a problem", isSupported_vdenc_h264high.returncode, isSupported_vdenc_hevcmain.returncode)
exit(1)
elif isSupported_vdenc_h264high.returncode == 0:
printLog(output_log_handle, "VDENC supports H264High")
elif isSupported_vdenc_hevcmain.returncode == 0:
printLog(output_log_handle, "VDENC supports HEVCMain")
######################################################################################################
# Linux Perf pre-req
######################################################################################################
try:
if enable_debugfs and (sudo_password_request() != 0):
print("REJECTED !!! and continue without [utilization/metric/statistic] profiles")
exit(1)
else:
print("ACCEPTED !!! to continue with [utilization/metric/statistic] profiles")
if tool_linux_perf and tool_linux_perf_trace:
import matplotlib
matplotlib.use('Agg')
except:
message_block(output_log_handle,'red', 'Unable to import matplotlib: ')
raise sys.exit(1)
######################################################################################################
# output path and header creation
######################################################################################################
try:
##################################################################################
# Initiate temporary directory for calculation and post-processing data.
##################################################################################
directory_check = os.path.isdir(temp_path)
if not directory_check:
os.system("mkdir " + temp_path)
else:
os.system("rm -rf " + temp_path)
os.system("mkdir " + temp_path)
###############################################
# assigning initial multistream as per resolution options
###############################################
init_stream_720p = 1
init_stream_1080p = 1
init_stream_2160p = 1
if starting_streamnumber != "all:1":
starting_streamnumber_split = starting_streamnumber.split(',')
for resolution_mode in starting_streamnumber_split:
resolution_mode_split = resolution_mode.split(':')
if resolution_mode_split[1].isdigit():
if "720p:" in resolution_mode:
init_stream_720p = int(resolution_mode_split[1])
elif "1080p:" in resolution_mode:
init_stream_1080p = int(resolution_mode_split[1])
elif "2160p:" in resolution_mode:
init_stream_2160p = int(resolution_mode_split[1])
else:
printLog(output_log_handle, "ERROR: Syntax incorrect, Can not find resolution, please follow an example: -s 720p:8,1080p:5,2160p:2, and Try again")
return ()
else:
printLog(output_log_handle, "ERROR: Syntax incorrect, Value is not integer,", resolution_mode_split[1], "please follow an example: -s 720p:8,1080p:5,2160p:2, and Try again")
return()
except:
message_block(output_log_handle,'red', 'Unable to create directory or inaccessible: ' + local_output_path)
raise sys.exit(1)
######################################################################################################
# Setup for Workloads directory or a single Workload performance
######################################################################################################
try:
ARGS.workloads_path = os.path.realpath(ARGS.workloads_path)
# checks if path is a directory
isDirectory = os.path.isdir(ARGS.workloads_path)
# checks if path is a file
isFile = os.path.isfile(ARGS.workloads_path)
performance_sweeping_table = {}
performance_object_list = {}
printLog(output_log_handle, "\n")
printLog(output_log_handle, '#' * 69)
if (isDirectory):
content_path = str(ARGS.workloads_path)
if (content_path[-1] != "/"):
content_path = content_path + "/"
#################################################################################
# Contentlist naming convention array <content_name>_<resolution>_<bitrate>_<fps>_<totalFrames>.<codec>
# jiwan
##################################################################################
content_list_filename = temp_path + "content.list"
cmd_generate_content_list = "ls " + content_path + " | grep -E '\.h264|\.hevc|\.h265|\.mp4' > " + content_list_filename # Add more content container support into the grep list.
generate_list_status = os.system(cmd_generate_content_list)
with open(content_list_filename, "r") as content_list_temp_fh:
for content_filename in content_list_temp_fh:
content_filename = content_filename.rstrip()
printLog (output_log_handle, " Profiling: " + content_filename)
if ffmpegffprobeCheck(output_log_handle, content_path, content_filename, temp_path, debug_verbose, performance_sweeping_table, performance_object_list):
if debug_verbose:
printLog(output_log_handle, " PASS: via FFMPEG/FFPROBE")
printLog(output_log_handle, " content_fps =", performance_object_list[content_filename].fps_target,", content_height =", performance_object_list[content_filename].height, ", content_codec =",performance_object_list[content_filename].codec, "\n")
if (float(fps_target) > 0):
performance_object_list[content_filename].fps_target = float(fps_target)
content_list_temp_fh.close()
elif (isFile):
content_path, content_filename = os.path.split(ARGS.workloads_path)
content_path = content_path + "/" # required because the extraction dir/filename above doesn't include the "/" character.
printLog(output_log_handle, " Profiling: " + content_filename)
content_filename = content_filename.rstrip()
if ffmpegffprobeCheck(output_log_handle, content_path, content_filename, temp_path, debug_verbose, performance_sweeping_table, performance_object_list):
if debug_verbose:
printLog(output_log_handle, " PASS: via FFMPEG/FFPROBE")
printLog(output_log_handle, " content_fps =", performance_object_list[content_filename].fps_target,", content_height =", performance_object_list[content_filename].height, ", content_codec =",performance_object_list[content_filename].codec, "\n")
if (float(fps_target) > 0):
performance_object_list[content_filename].fps_target = float(fps_target)
else:
message_block(output_log_handle,'red', 'Unable to locate required workload path: ' + ARGS.workloads_path)
raise sys.exit(1)
except:
message_block(output_log_handle,'red', 'Unable to profile required workload path: ' + ARGS.workloads_path)
raise sys.exit(1)
##################################################################################
# Iterating measure applications
# 1st SMT
# 2nd FFMPEG
# 3rd TBD/continue..
##################################################################################
performance_starttime = time.time()
performance_datetime = str(time.ctime()) # to be used for archiving purposes.
for performance_applications in range (2):
required_information_file = os.path.dirname(os.path.realpath(__file__))
if (performance_applications == 0) and not skip_msdk:
ffmpeg_mode = False
performance_app_tag = "SMT"
if not ARGS.use_enctools:
required_information_file += "/por_SMT_LB.txt"
else:
required_information_file += "/por_SMT_LB_enctools.txt"
elif (performance_applications == 1) and not skip_ffmpeg:
if not ARGS.use_enctools:
required_information_file += "/por_FFMPEG_LB.txt"
else:
required_information_file += "/por_FFMPEG_LB_enctools.txt"
ffmpeg_mode = True
performance_app_tag = "FFMPEG"
else:
continue
######################################################################################################
# command line based on resolution
######################################################################################################
try:
cmdline_config_hevc2avc_exist = cmdline_config_avc2avc_exist = cmdline_config_hevc2hevc_exist = cmdline_config_avc2hevc_exist = cmdline_config_av12av1_exist = cmdline_config_decode_hevc_exist = cmdline_config_decode_avc_exist = False
with open(required_information_file, 'r') as configfile:
for workloadline in configfile:
if (not re.search("^#", str(workloadline))):
if (re.search(r"hevc-avc:", str(workloadline))): cmdline_config_hevc2avc_exist = True
if (re.search(r"avc-avc:", str(workloadline))): cmdline_config_avc2avc_exist = True
if (re.search(r"hevc-hevc:", str(workloadline))): cmdline_config_hevc2hevc_exist = True
if (re.search(r"avc-hevc:", str(workloadline))): cmdline_config_avc2hevc_exist = True
if (re.search(r"av1-av1:", str(workloadline))): cmdline_config_av12av1_exist = True
if (re.search(r"decode-hevc:", str(workloadline))): cmdline_config_decode_hevc_exist = True
if (re.search(r"decode-avc:", str(workloadline))): cmdline_config_decode_avc_exist = True
if (re.search(r"^720p_hevc-avc:\s", str(workloadline))): performance_cmdline_720p_hevc2avc = workloadline.replace("720p_hevc-avc: ", "")
if (re.search(r"^1080p_hevc-avc:\s", str(workloadline))): performance_cmdline_1080p_hevc2avc = workloadline.replace("1080p_hevc-avc: ", "")
if (re.search(r"^2160p_hevc-avc:\s", str(workloadline))): performance_cmdline_2160p_hevc2avc = workloadline.replace("2160p_hevc-avc: ", "")
if (re.search(r"^720p_avc-avc:\s", str(workloadline))): performance_cmdline_720p_avc2avc = workloadline.replace("720p_avc-avc: ", "")
if (re.search(r"^1080p_avc-avc:\s", str(workloadline))): performance_cmdline_1080p_avc2avc = workloadline.replace("1080p_avc-avc: ", "")
if (re.search(r"^2160p_avc-avc:\s", str(workloadline))): performance_cmdline_2160p_avc2avc = workloadline.replace("2160p_avc-avc: ", "")
if (re.search(r"^720p_hevc-hevc:\s", str(workloadline))): performance_cmdline_720p_hevc2hevc = workloadline.replace("720p_hevc-hevc: ", "")
if (re.search(r"^1080p_hevc-hevc:\s", str(workloadline))): performance_cmdline_1080p_hevc2hevc = workloadline.replace("1080p_hevc-hevc: ", "")
if (re.search(r"^2160p_hevc-hevc:\s", str(workloadline))): performance_cmdline_2160p_hevc2hevc = workloadline.replace("2160p_hevc-hevc: ", "")
if (re.search(r"^720p_avc-hevc:\s", str(workloadline))): performance_cmdline_720p_avc2hevc = workloadline.replace("720p_avc-hevc: ", "")
if (re.search(r"^1080p_avc-hevc:\s", str(workloadline))): performance_cmdline_1080p_avc2hevc = workloadline.replace("1080p_avc-hevc: ", "")
if (re.search(r"^2160p_avc-hevc:\s", str(workloadline))): performance_cmdline_2160p_avc2hevc = workloadline.replace("2160p_avc-hevc: ", "")
if (re.search(r"^720p_av1-av1:\s", str(workloadline))): performance_cmdline_720p_av12av1 = workloadline.replace("720p_av1-av1: ", "")
if (re.search(r"^1080p_av1-av1:\s", str(workloadline))): performance_cmdline_1080p_av12av1 = workloadline.replace("1080p_av1-av1: ", "")
if (re.search(r"^2160p_av1-av1:\s", str(workloadline))): performance_cmdline_2160p_av12av1 = workloadline.replace("2160p_av1-av1: ", "")
if (re.search(r"decode-hevc:\s",str(workloadline))): performance_cmdline_decode_hevc = workloadline.replace("decode-hevc: ", "")
if (re.search(r"decode-avc:\s",str(workloadline))): performance_cmdline_decode_avc = workloadline.replace("decode-avc: ", "")
except:
message_block(output_log_handle,'red', 'Unable to locate required file: ' + ARGS.required_information_file)
raise sys.exit(1)
##################################################################################
# Iterating measure sequence
##################################################################################
Workloads = ["HEVC-AVC",
"AVC-AVC",
"HEVC-HEVC",
"AVC-HEVC",
"AV1-AV1",
"DECODE-HEVC",
"DECODE-AVC"]
##################################################################################
startTime_sequence = time.time()
for performance_tag in Workloads:
##################################################################################
# Initiate outputfile measure result as per last best stream# and fps#
# Initiate outputfile measure table sweep as per last best stream# and fps#
##################################################################################
if performance_tag == "HEVC-AVC" and (encode_codec == "all" or encode_codec == "avc") and cmdline_config_hevc2avc_exist:
sequence_mode = "TRANSCODE"
elif performance_tag == "AVC-AVC" and (encode_codec == "all" or encode_codec == "avc") and cmdline_config_avc2avc_exist:
sequence_mode = "TRANSCODE"
elif performance_tag == "HEVC-HEVC" and (encode_codec == "all" or encode_codec == "hevc") and cmdline_config_hevc2hevc_exist:
sequence_mode = "TRANSCODE"
elif performance_tag == "AVC-HEVC" and (encode_codec == "all" or encode_codec == "hevc") and cmdline_config_avc2hevc_exist:
sequence_mode = "TRANSCODE"
elif performance_tag == "AV1-AV1" and (encode_codec == "all" or encode_codec == "av1") and cmdline_config_av12av1_exist:
if not ARGS.use_enctools:
sequence_mode = "TRANSCODE"
else:
printLog(output_log_handle, " ERROR : Perf Config file , AV1 CODEC with Enctools not supported" )
continue
elif performance_tag == "DECODE-HEVC" and density_decode and cmdline_config_decode_hevc_exist:
sequence_mode = "DECODE"
elif performance_tag == "DECODE-AVC" and density_decode and cmdline_config_decode_avc_exist:
sequence_mode = "DECODE"
else:
continue
output_log_file_performance_media = re.sub(r'.txt', "_" + performance_app_tag + "_" + performance_tag + "_performance.csv", output_log_file)
output_log_file_performance_sweep = re.sub(r'.txt', "_" + performance_app_tag + "_" + performance_tag + "_performance_table_sweep.csv", output_log_file)
##################################################################################
# Archiving potential duplicate runs.
##################################################################################
isFile = os.path.isfile(output_log_file_performance_media)
if (isFile):
archived_filepath = "archived_" + performance_datetime
archived_filepath = re.sub(r'\:', "", archived_filepath)
archived_filepath = re.sub(r'\s', "_", archived_filepath)
isDirectory = os.path.isdir(artifact_path + archived_filepath)
if not isDirectory:
archived_command = "mkdir " + artifact_path + archived_filepath
os.system(archived_command)
move_command = "mv " + artifact_path + "*" + performance_app_tag + "*" + performance_tag + "* " + artifact_path + archived_filepath + "/."
os.system(move_command)
##################################################################################
# Initiate temporary directory for calculation and post-processing data. ReCreated for every measure sequence.
##################################################################################
directory_check = os.path.isdir(temp_path)
filepath_free_info = temp_path + performance_app_tag + "_" + performance_tag + "_" + "free.txt"
filepath_lscpu_info = temp_path + performance_app_tag + "_" + performance_tag + "_" + "lscpu.txt"
if not directory_check:
os.system("mkdir " + temp_path)
os.system("free > " + filepath_free_info)
os.system("lscpu > " + filepath_lscpu_info)
else:
os.system("rm -rf " + temp_path)
os.system("mkdir " + temp_path)
os.system("free > " + filepath_free_info)
os.system("lscpu > " + filepath_lscpu_info)
local_output_path = artifact_path + "output/" # all the Metrics/Summary/Traces will be copy further into the current directory.
directory_check = os.path.isdir(local_output_path)
if not directory_check: os.system("mkdir " + local_output_path)
for a in range(int(maximum_iteration)):
iteration_path_cmd = temp_path + "iteration_" + str(a)
directory_check = os.path.isdir(iteration_path_cmd)
if not directory_check: os.system("mkdir " + iteration_path_cmd)
bm_output_handle = open(output_log_file_performance_media, 'w')
measure = "clipname, performance_stream, fps, runtime(s), GPU_Vid0(%), GPU_Vid1(%), GPU_Render(%), AVG_CPU(%), RC6(%), GPU_Freq_Avg(MHz), MEM_RES_Avg(MB/stream), MEM_RES_Total(MB), AVG_MEM(%), PHYSICAL_MEM(MB), CPU_IPC, TOTAL_CPU(%), GPU_MEM_RES_Avg(MB/stream), GPU_MEM_RES_Total(MB)\n"
bm_output_handle.write(measure)
performance_table_sweep = output_log_file_performance_sweep
bt_output_handle = open(performance_table_sweep, 'w')
########### James.Iwan@intel.com Multi Streams Perf ##############################
# ITERATION/WORKLOADS/etc START HERE
##################################################################################
for key in performance_object_list:
curContent = key.rstrip()
if curContent == "":
printLog(output_log_handle, "SCRIPT ERROR: empty content") # exit.
exit(1)
elif (re.search(r'.*.mp4$', curContent)) and (performance_app_tag == "SMT"):
printLog(output_log_handle, "\n")
printLog(output_log_handle, "[SKIPPED]: files in container formats (.mp4, .mkv, etc.) are not supported by MSDK samples ", curContent) # skip
continue
performance_sweeping_table[curContent] = []
if (performance_tag == "HEVC-AVC") and (encode_codec == "all" or encode_codec == "avc") and (performance_object_list[curContent].height <= 2160): # HEVC-AVC measure sequence
if performance_object_list[curContent].codec != "hevc": # skip if its not HEVC input clip, or if output Encode AVC tried height higher from 2160
continue
elif (performance_tag == "AVC-AVC") and (encode_codec == "all" or encode_codec == "avc") and (performance_object_list[curContent].height <= 2160): # AVC-AVC measure sequence
if performance_object_list[curContent].codec != "h264": # skip if its not h264 input clip, or if output Encode AVC tried height higher from 2160
continue
elif (performance_tag == "HEVC-HEVC") and (encode_codec == "all" or encode_codec == "hevc"): # HEVC-HEVC measure sequence
if performance_object_list[curContent].codec != "hevc": # skip if its not HEVC input clip
continue
elif (performance_tag == "AVC-HEVC") and (encode_codec == "all" or encode_codec == "hevc"): # AVC-HEVC measure sequence
if performance_object_list[curContent].codec != "h264": # skip if its not h264 input clip
continue
elif (performance_tag == "AV1-AV1") and (encode_codec == "all" or encode_codec == "av1"): # AV1-AV1 measure sequence
if performance_object_list[curContent].codec != "av1": # skip if its not av1 input clip
continue
elif (performance_tag == "DECODE-HEVC"): # Decode-HEVC measure sequence
if performance_object_list[curContent].codec != "hevc": # skip if its not HEVC input clip
continue
elif (performance_tag == "DECODE-AVC"): # Decode-AVC measure sequence
if performance_object_list[curContent].codec != "h264": # skip if its not H264 input clip
continue
else:
printLog(output_log_handle, "\n")
printLog(output_log_handle, '#' * 69)
printLog(output_log_handle, "[SKIPPED]: ", performance_app_tag, " ", performance_tag, " ", curContent) # skip
printLog(output_log_handle, '#' * 69)
continue
##################################################################################
# Create initialize streamnumber for each resolution
##################################################################################
if performance_object_list[curContent].encode_bitrate == "sd_bitrate":
streamnumber = init_stream_720p
performance_object_list[curContent].init_stream_number = init_stream_720p
elif performance_object_list[curContent].encode_bitrate == "hd_bitrate":
streamnumber = init_stream_1080p
performance_object_list[curContent].init_stream_number = init_stream_1080p
elif performance_object_list[curContent].encode_bitrate == "4k_bitrate":
streamnumber = init_stream_2160p
performance_object_list[curContent].init_stream_number = init_stream_2160p
else:
streamnumber = 1
performance_object_list[curContent].init_stream_number = 1
nextStreamNumber = True if int(streamnumber) > 0 else False
content_fps_limit = 0
performance_stream = 0
performance_fps = 0
performance_exetime = 0
performance_vid0_u = 0
performance_vid1_u = 0
performance_render_u = 0
performance_cpu_ipc = 0
performance_rc6_u = 0
performance_avg_freq = 0
performance_avg_res_mem = 0
performance_total_res_mem = 0
performance_avg_mem_percentage = 0
performance_avg_cpu_percentage = 0
performance_max_cpu_percentage = 0
performance_max_physical_mem = 0
performance_avg_res_gpumem = 0
performance_total_res_gpumem = 0
while nextStreamNumber and (streamnumber <= endStreams):
shell_script_mms = temp_path + "mms.sh" # Move this to /tmp/perf/
shell_script_handle = open(shell_script_mms, 'w')
avg_fps = exetime = vid0_u = vid1_u = render_u = avg_freq = 0
avg_fps_split = []
##################################################################################
# Creates Unique Concurrent Command Lines
##################################################################################
content_split = key.replace('.', '_').split('_')
clip_name = content_split[0]
clip_resolution = content_split[1]
clip_stream_iter_tag = performance_app_tag + "_" + performance_tag + "_" + clip_name+ "_" + clip_resolution + "_" + str(streamnumber)
fps_constraint = int(performance_object_list[curContent].fps_target)
shell_script_handle.write("echo " + clip_stream_iter_tag + "\n")
for m in range(int(streamnumber)):
##################################################################################
# Construct 720p/1080p/2160p Command lines for
##################################################################################
dispatch_cmdline = transcode_input_clip = "N/A"
if performance_tag == "HEVC-AVC" and (encode_codec == "all" or encode_codec == "avc"): # HEVC-AVC measure sequence
if performance_object_list[curContent].encode_bitrate == "sd_bitrate":
dispatch_cmdline = performance_cmdline_720p_hevc2avc
elif performance_object_list[curContent].encode_bitrate == "hd_bitrate":
dispatch_cmdline = performance_cmdline_1080p_hevc2avc
elif performance_object_list[curContent].encode_bitrate == "4k_bitrate":
dispatch_cmdline = performance_cmdline_2160p_hevc2avc
elif performance_tag == "AVC-AVC" and (encode_codec == "all" or encode_codec == "avc"): # AVC-AVC measure sequence
if performance_object_list[curContent].encode_bitrate == "sd_bitrate":
dispatch_cmdline = performance_cmdline_720p_avc2avc
elif performance_object_list[curContent].encode_bitrate == "hd_bitrate":
dispatch_cmdline = performance_cmdline_1080p_avc2avc
elif performance_object_list[curContent].encode_bitrate == "4k_bitrate":
dispatch_cmdline = performance_cmdline_2160p_avc2avc
elif performance_tag == "HEVC-HEVC" and (encode_codec == "all" or encode_codec == "hevc"): # HEVC-HEVC measure sequence
if performance_object_list[curContent].encode_bitrate == "sd_bitrate":
dispatch_cmdline = performance_cmdline_720p_hevc2hevc
elif performance_object_list[curContent].encode_bitrate == "hd_bitrate":
dispatch_cmdline = performance_cmdline_1080p_hevc2hevc
elif performance_object_list[curContent].encode_bitrate == "4k_bitrate":
dispatch_cmdline = performance_cmdline_2160p_hevc2hevc
elif performance_tag == "AVC-HEVC" and (encode_codec == "all" or encode_codec == "hevc"): # AVC-HEVC measure sequence
if performance_object_list[curContent].encode_bitrate == "sd_bitrate":
dispatch_cmdline = performance_cmdline_720p_avc2hevc
elif performance_object_list[curContent].encode_bitrate == "hd_bitrate":
dispatch_cmdline = performance_cmdline_1080p_avc2hevc
elif performance_object_list[curContent].encode_bitrate == "4k_bitrate":
dispatch_cmdline = performance_cmdline_2160p_avc2hevc
elif performance_tag == "AV1-AV1" and (encode_codec == "all" or encode_codec == "av1"): # AV1-AV1 measure sequence
if performance_object_list[curContent].encode_bitrate == "sd_bitrate":
dispatch_cmdline = performance_cmdline_720p_av12av1
elif performance_object_list[curContent].encode_bitrate == "hd_bitrate":
dispatch_cmdline = performance_cmdline_1080p_av12av1
elif performance_object_list[curContent].encode_bitrate == "4k_bitrate":
dispatch_cmdline = performance_cmdline_2160p_av12av1
elif performance_tag == "DECODE-HEVC": # DECODE HEVC
dispatch_cmdline = performance_cmdline_decode_hevc
elif performance_tag == "DECODE-AVC": # DECODE AVC
dispatch_cmdline = performance_cmdline_decode_avc
else:
break
async_default = '2'
if performance_object_list[curContent].encode_bitrate == "hd_bitrate" or performance_object_list[curContent].encode_bitrate == "sd_bitrate" :
async_default = '1'
if (ffmpeg_mode):
transcode_input_clip = "-i " + content_path + key
if not no_fps_limit:
transcode_input_clip = "-re " + transcode_input_clip
dispatch_cmdline = dispatch_cmdline.replace("-i <>", transcode_input_clip)
dispatch_cmdline = dispatch_cmdline.replace("-preset <>", "-preset "+ (ARGS.tu if ARGS.tu else 'veryfast' ))
dispatch_cmdline = dispatch_cmdline.replace("-async_depth <>", "-async_depth "+ (ARGS.async_depth if ARGS.async_depth else async_default ))
if ARGS.use_enctools:
dispatch_cmdline = dispatch_cmdline.replace("-look_ahead_depth <>", "-look_ahead_depth "+ (ARGS.enctools_lad if ARGS.enctools_lad else '8' ))
dispatch_cmdline = dispatch_cmdline.replace("-extra_hw_frames <>", "-extra_hw_frames "+ (ARGS.enctools_lad if ARGS.enctools_lad else '8' ) )
elif (sequence_mode == "TRANSCODE"): # SMT Transcode
dict_tu = {'veryslow' : '1','slower': '2','slow': '3','medium': '4','fast': '5','faster': '6','veryfast': '7'}
dispatch_cmdline = dispatch_cmdline.replace("-u <>", "-u "+ (dict_tu[ARGS.tu] if ARGS.tu else '7' ))
dispatch_cmdline = dispatch_cmdline.replace("-async <>", "-async "+ (ARGS.async_depth if ARGS.async_depth else async_default ))
if ARGS.use_enctools:
dispatch_cmdline = dispatch_cmdline.replace("-lad <>", "-lad "+ (ARGS.enctools_lad if ARGS.enctools_lad else '8' ) )
if performance_object_list[curContent].codec == "hevc":
transcode_input_clip = "-i::h265 " + content_path + key
if not no_fps_limit:
transcode_input_clip = "-fps " + str(fps_constraint) + " " + transcode_input_clip
dispatch_cmdline = dispatch_cmdline.replace("-i::h265 <>", transcode_input_clip)
elif performance_object_list[curContent].codec == "h264":
transcode_input_clip = "-i::h264 " + content_path + key
if not no_fps_limit:
transcode_input_clip = "-fps " + str(fps_constraint) + " " + transcode_input_clip
dispatch_cmdline = dispatch_cmdline.replace("-i::h264 <>", transcode_input_clip)
elif performance_object_list[curContent].codec == "av1" or "ivf":
transcode_input_clip = "-i::av1 " + content_path + key
if not no_fps_limit:
transcode_input_clip = "-fps " + str(fps_constraint) + " " + transcode_input_clip
dispatch_cmdline = dispatch_cmdline.replace("-i::av1 <>", transcode_input_clip)
elif (sequence_mode == "DECODE"): # SMT Decode
transcode_input_clip = "-i " + content_path + key
if not no_fps_limit:
transcode_input_clip = "-fps " + str(fps_constraint) + " " + transcode_input_clip
dispatch_cmdline = dispatch_cmdline.replace("-i <>", transcode_input_clip)
######################################################################################################
# this below code is for constructing unique output for each stream.
# e.g. Crowdrun_720p_output_1.264, Crowdrun_720p_output_2.264,
# and constructing unique log file for each stream for further post processing
# e.g. Crowdrun_720p_log_1.txt, Crowdrun_720p_log_2.txt,
# jiwan
##################################################################################
# Adding Constraint and UnConstraint FPS
if (ffmpeg_mode):
transcode_output_clip = local_output_path + clip_name + "_" + clip_resolution + "_" + str(m)
if use_vdenc:
transcode_output_clip = " -low_power true " + transcode_output_clip
dispatch_cmdline = dispatch_cmdline.replace("-y <>", "-y " + transcode_output_clip)
else: # SMT section (DEFAULT)
transcode_output_clip = local_output_path + clip_name + "_" + clip_resolution + "_" + str(m)
dispatch_cmdline = dispatch_cmdline.replace("-o::h264 <>", "-o::h264 " + transcode_output_clip)
dispatch_cmdline = dispatch_cmdline.replace("-o::h265 <>", "-o::h265 " + transcode_output_clip)
dispatch_cmdline = dispatch_cmdline.replace("-o::av1 <>", "-o::av1 " + transcode_output_clip)
# Adding Transcode_Output_Log file and Multiple Device knobs
if (ffmpeg_mode):
transcode_output_logfile = " 2> " + temp_path + clip_name + "_" + clip_resolution + "_" + str(streamnumber) + "_" + str(m) + "_transcode_log.txt"
ffmpeg_device_knob = " -qsv_device " + os_env_DEVICE
transcode_output_logfile = ffmpeg_device_knob + transcode_output_logfile
dispatch_cmdline = dispatch_cmdline.replace("-report", transcode_output_logfile).rstrip()
elif sequence_mode == "TRANSCODE": # Transcode
transcode_output_logfile = " -p " + temp_path + clip_name + "_" + clip_resolution + "_" + str(m) + "_transcode_log.txt"
smt_device_knob = " -device " + os_env_DEVICE
transcode_output_logfile = smt_device_knob + transcode_output_logfile
if use_vdenc:
transcode_output_logfile = " -lowpower:on " + transcode_output_logfile
dispatch_cmdline = dispatch_cmdline.replace("-p <>", transcode_output_logfile).rstrip()
elif (sequence_mode == "DECODE") and not ffmpeg_mode: # SMT DECODE
transcode_output_logfile = " > " + temp_path + clip_name + "_" + clip_resolution + "_" + str(m) + "_transcode_log.txt"
smt_device_knob = " -device " + os_env_DEVICE
transcode_output_logfile = smt_device_knob + transcode_output_logfile
dispatch_cmdline = dispatch_cmdline.replace("-p <>", transcode_output_logfile).rstrip()
##################################################################################
# Adding piping to log file and strip out the error messages
##################################################################################
if (ffmpeg_mode):
dispatch_cmdline = dispatch_cmdline + "\n"
elif (sequence_mode == "TRANSCODE"): # SMT TRANSCODE
dispatch_cmdline = dispatch_cmdline + " >> " + temp_path + "console_log.txt 2>&1" + "\n"
elif (sequence_mode == "DECODE"): # SMT DECODE
dispatch_cmdline = dispatch_cmdline + " 2>&1" + "\n"
performance_object_list[curContent].dispatch_cmdline = dispatch_cmdline
shell_script_handle.write(dispatch_cmdline)
shell_script_handle.close()
nextStreamNumber0 = False
nextStreamNumber1 = False
nextStreamNumber2 = False
nextStreamNumber3 = False
##################################################################################
# Dispatch and Post Process each result +-2%
##################################################################################
for j in range(maximum_iteration):
printLog(output_log_handle, "\n")
printLog(output_log_handle, '#' * 69)
print_performance_label = "PNP MEDIA " + performance_app_tag + " " + performance_tag + ": " + "MULTISTREAM: " + str(streamnumber) + " & ITERATION: " + str(j)
if (debug_verbose):
print_performance_label += " - " + clip_name
printLog(output_log_handle, print_performance_label)
printLog(output_log_handle, '#' * 69)
linux_perf_dump = temp_path + clip_stream_iter_tag + "_" + str(j) + "_metrics.txt"
filename_gpu_freq_trace = clip_stream_iter_tag + "_" + str(j) + "_gpu_freq_traces"
linux_perf_gpu_freq_trace_dump = temp_path + filename_gpu_freq_trace + ".txt"
filename_mem_bw_trace = clip_stream_iter_tag + "_" + str(j) + "_mem_bw_traces"
linux_perf_mem_bw_trace_dump = temp_path + filename_mem_bw_trace + ".txt"
performance_object_list[curContent].temp_path = temp_path
performance_object_list[curContent].linux_perf_dump = linux_perf_dump
performance_object_list[curContent].filename_gpu_freq_trace = filename_gpu_freq_trace
performance_object_list[curContent].linux_perf_gpu_freq_trace_dump = linux_perf_gpu_freq_trace_dump
performance_object_list[curContent].filename_mem_bw_trace = filename_mem_bw_trace
performance_object_list[curContent].linux_perf_mem_bw_trace_dump = linux_perf_mem_bw_trace_dump
performance_object_list[curContent].tool_linux_perf_trace = tool_linux_perf_trace
performance_object_list[curContent].ffmpeg_mode = ffmpeg_mode
graphic_model = "generic" # must search for profiling what graphic model that we performance.
metrics, gpu_freq_traces, mem_bw_traces = selectLinuxPerfMetrics(temp_path, graphic_model)
linux_perf_cmdlines = os.path.dirname(os.path.realpath(__file__)) + "/MSGo.py"
if tool_linux_perf:
if metrics != "":
linux_perf_cmdlines = "perf stat -a -e {} -o " + linux_perf_dump + " " + linux_perf_cmdlines
linux_perf_cmdlines = linux_perf_cmdlines.format(metrics)
if gpu_freq_traces != "":
linux_perf_cmdlines = "perf stat -I 100 -a -e {} -o " + linux_perf_gpu_freq_trace_dump + " " + linux_perf_cmdlines
linux_perf_cmdlines = linux_perf_cmdlines.format(gpu_freq_traces)
if mem_bw_traces != "":
linux_perf_cmdlines = "perf stat -I 100 -a -e {} -o " + linux_perf_mem_bw_trace_dump + " " + linux_perf_cmdlines
linux_perf_cmdlines = linux_perf_cmdlines.format(mem_bw_traces)
performance_object_list[curContent].linux_perf_cmdlines = linux_perf_cmdlines
p = subprocess.Popen(linux_perf_cmdlines, shell=True, stderr=subprocess.PIPE)
#p.send_signal(signal.SIGINT)
p.wait()
if (p.returncode != 0):
if debug_verbose:
printLog(output_log_handle, " [VERBOSE][CMD]", performance_object_list[curContent].dispatch_cmdline)
printLog(output_log_handle, " [VERBOSE][LINUX_PERF_TOOLS]", performance_object_list[curContent].linux_perf_cmdlines, "\n")
printLog(output_log_handle, " Exit early, hang/error in submitted commands:", str(p.returncode))
else:
printLog(output_log_handle, " Exit early, hang/error in submitted commands:", str(p.returncode), "(please use -v to debug further)")
sys.exit(p.returncode)
os.system('stty sane')
############################################################################################
# rename file with iteration# and put into the content object information
############################################################################################
filename_gpumem_trace = clip_stream_iter_tag + "_" + str(j) + "_gpumem_trace"
gemobject_gpumem_trace_dump = temp_path + filename_gpumem_trace + ".txt"
performance_object_list[curContent].filename_gpumem_trace = filename_gpumem_trace
performance_object_list[curContent].gemobject_gpumem_trace_dump = gemobject_gpumem_trace_dump
os.system("mv " + temp_path + clip_stream_iter_tag + "_gpumem_trace.txt " + gemobject_gpumem_trace_dump)
############################################################################################
# rename file with iteration# and put into the content object information
############################################################################################
filename_cpumem_trace = clip_stream_iter_tag + "_" + str(j) + "_cpumem_trace"
top_cpumem_trace_dump = temp_path + filename_cpumem_trace + ".txt"
performance_object_list[curContent].filename_cpumem_trace = filename_cpumem_trace
performance_object_list[curContent].top_cpumem_trace_dump = top_cpumem_trace_dump
os.system("mv " + temp_path + clip_stream_iter_tag + "_cpumem_trace.txt " + top_cpumem_trace_dump)
############################################################################################
nextStreamNumber0, avg_fps, exetime, vid0_u, vid1_u, render_u, cpu_ipc, rc6_u, avg_freq , avg_vm_mem, avg_shr_mem, avg_res_mem, total_res_mem, \
avg_mem_utilization, max_physical_mem, avg_cpu_percentage, max_cpu_percentage, avg_res_gpumem, total_res_gpumem = \
postprocess_multistream(output_log_handle, streamnumber, j, debug_verbose, filepath_free_info, filepath_lscpu_info, performance_object_list[curContent],sequence_mode)
if j == 0:
move_command = "mv " + temp_path + "*transcode_log.txt " + temp_path + "iteration_0/."
os.system(move_command)
avg_fps_split.append(avg_fps)
if j == 1:
move_command = "mv " + temp_path + "*transcode_log.txt " + temp_path + "iteration_1/."
os.system(move_command)
avg_fps_split.append(avg_fps)
if j == 2:
move_command = "mv " + temp_path + "*transcode_log.txt " + temp_path + "iteration_2/."
os.system(move_command)
avg_fps_split.append(avg_fps)
if j == 3:
move_command = "mv " + temp_path + "*transcode_log.txt " + temp_path + "iteration_3/."
os.system(move_command)
avg_fps_split.append(avg_fps)
printLog(output_log_handle, "ITERATION: Done")
##################################################################################
# Compare and Decide
##################################################################################
if nextStreamNumber0 or nextStreamNumber1 or nextStreamNumber2 or nextStreamNumber3:
performance_stream = streamnumber
performance_fps = round(statistics.mean(avg_fps_split),1)
performance_exetime = exetime
performance_vid0_u = vid0_u
performance_vid1_u = vid1_u
performance_render_u = render_u
performance_cpu_ipc = cpu_ipc
performance_rc6_u = rc6_u
performance_avg_freq = avg_freq
performance_avg_res_mem = avg_res_mem
performance_total_res_mem = total_res_mem
performance_avg_mem_percentage = avg_mem_utilization
performance_max_physical_mem = max_physical_mem
performance_avg_cpu_percentage = avg_cpu_percentage
performance_max_cpu_percentage = max_cpu_percentage
performance_avg_res_gpumem = avg_res_gpumem
performance_total_res_gpumem = total_res_gpumem
performance_sweeping_table[key].append(performance_fps)
nextStreamNumber = True
if int(streamnumber) == 1:
performance_table = key + "," + str(performance_fps)
bt_output_handle.write(performance_table)
else:
performance_table = "," + str(performance_fps)
bt_output_handle.write(performance_table)
streamnumber = streamnumber + 1
elif int(streamnumber) == 1:
performance_stream = 0
performance_fps = round(statistics.mean(avg_fps_split), 1)
performance_exetime = exetime
performance_vid0_u = vid0_u
performance_vid1_u = vid1_u
performance_render_u = render_u
performance_cpu_ipc = cpu_ipc
performance_rc6_u = rc6_u
performance_avg_freq = avg_freq
performance_avg_vm_mem = avg_vm_mem
performance_avg_shr_mem = avg_shr_mem
performance_total_res_mem = total_res_mem
performance_avg_res_mem = avg_res_mem
performance_avg_mem_percentage = avg_mem_utilization
performance_max_physical_mem = max_physical_mem
performance_avg_cpu_percentage = avg_cpu_percentage
performance_max_cpu_percentage = max_cpu_percentage
performance_avg_res_gpumem = avg_res_gpumem
performance_total_res_gpumem = total_res_gpumem
printLog(output_log_handle, " average current TPT: ",performance_stream, "average_fps: ", performance_fps)
performance_sweeping_table[key].append(performance_fps)
nextStreamNumber = False
performance_table = key + "," + str(performance_fps)
bt_output_handle.write(performance_table)
else:
last_failing_fps = round(statistics.mean(avg_fps_split), 1)
performance_sweeping_table[key].append(last_failing_fps) # to add the last failing multistreams.
nextStreamNumber = False
performance_table = "," + str(last_failing_fps)
bt_output_handle.write(performance_table)
printLog(output_log_handle, "MULTISTREAM: Done")
##################################################################################
# Before go to next workload, captured the measure result
##################################################################################
measure = key + "," + str(performance_stream) + "," \
+ str(performance_fps) + "," + str(performance_exetime) + "," \
+ str(performance_vid0_u) + "," + str(performance_vid1_u) + "," \
+ str(performance_render_u) + "," + str(performance_avg_cpu_percentage) + "," \
+ str(performance_rc6_u) + "," + str(performance_avg_freq) + "," \
+ str(performance_avg_res_mem) + "," + str(performance_total_res_mem) + "," \
+ str(performance_avg_mem_percentage) + "," + str(performance_max_physical_mem) + "," \
+ str(performance_cpu_ipc) + "," + str(performance_max_cpu_percentage) + "," \
+ str(performance_avg_res_gpumem) + "," + str(performance_total_res_gpumem) + "\n"
bm_output_handle.write(measure)
performance_table = "\n"
bt_output_handle.write(performance_table)
if str(performance_sweeping_table[key])[1:-1] == "":
printLog(output_log_handle, key, ": SKIPPED")
else:
printLog(output_log_handle, " measure streams of", key, ":", len(performance_sweeping_table[key]) - 1, ":", str(performance_sweeping_table[key])[1:-1])
printLog(output_log_handle, "WORKLOAD: Done")
##################################################################################
# Performance sequence is done
##################################################################################
##################################################################################
# Saved traces.
##################################################################################
output_directory_archived = re.sub(r'.txt', "_" + performance_app_tag + "_" + performance_tag + "_traces",output_log_filename)
output_directory_archived = artifact_path + output_directory_archived
move_command = "mv /tmp/perf " + output_directory_archived
os.system(move_command)
# print out total time during the measure sequence
end_message = "PERFORMANCE SEQUENCE : " + performance_tag + " : Done"
execution_time(output_log_handle, end_message, startTime_sequence, time.time())
##################################################################################
# start new start time of next measure sequence
##################################################################################
startTime_sequence = time.time()
end_message = "PERFORMANCE APPLICATION: " + performance_app_tag + " : Done"
execution_time(output_log_handle, end_message, performance_starttime, time.time())
##################################################################################
# Rename output/ path into output_<Application>/
##################################################################################
archived_local_output_path = re.sub(r'output', "output_" + performance_app_tag, local_output_path)
isDirectory = os.path.isdir(archived_local_output_path)
if (isDirectory):
rename_application_output_cmd = ("mv " + local_output_path + "* " + archived_local_output_path + ".")
os.system(rename_application_output_cmd)
os.system("rm -r local_output_path") # remove empty output directory after the archiving.
else:
rename_application_output_cmd = ("mv " + local_output_path + " " + archived_local_output_path)
os.system(rename_application_output_cmd)
##################################################################################
# start new start time of next measure application
##################################################################################
performance_starttime = time.time()
end_message = "PNP MEDIA PERFORMANCE: Done"
execution_time(output_log_handle, end_message, startTime, time.time())
printLog(output_log_handle, "\nDate:", time.ctime())
######################## PnP SiLab Sumack ########################################
def message_block(output_log_handle, block_color, block_str):
color_str = {'red': u'\u001b[41;1m', 'green': u'\u001b[42;1m', 'white': u'\u001b[7m', 'yellow': u'\u001b[43:1m'}
formatted_string = '\n' + color_str[block_color] + ' ' * (4 + len(block_str)) + u'\u001b[0m\n' + color_str[
block_color] \
+ ' ' + block_str + u' \u001b[0m\n' + color_str[block_color] + ' ' * (
4 + len(block_str)) + u'\u001b[0m\n'
printLog(output_log_handle, formatted_string)
##################################################################################
# Post Process Multistream FPS/stream against Content_FPS definition
# jiwan
##################################################################################
def postprocess_multistream(output_log_handle, stream_number, iteration_number, debug_verbose, tools_free_info, tools_lscpu_info, performance_object, sequence_mode):
if debug_verbose:
printLog(output_log_handle, " [VERBOSE][CMD]", performance_object.dispatch_cmdline)
printLog(output_log_handle, " [VERBOSE][LINUX_PERF_TOOLS]", performance_object.linux_perf_cmdlines, "\n")
next = True
runtime = vid0_utilization = vid1_utilization = render_utilization = cpu_ipc = \
rc6_utilization = avg_frequency = cpu_task_clock = \
total_vm_mem_value = total_res_mem_value = total_shr_mem_value = \
avg_vm_mem_value = avg_res_mem_value = avg_shr_mem_value = \
avg_cpu_percentage = avg_mem_utilization = total_CPU_percents_streams = \
total_MEM_percents_streams = max_cpu_percentage = max_physical_mem = total_res_gpumem = avg_res_gpumem = \
avg_avg_cpu_percents_streams = avg_avg_mem_percents_streams = 0
##################################################################################
# Example of Free info dump file
# total used free shared buff/cache available
# Mem: 16319120 702844 551948 9224 15064328 15294664
##################################################################################
free_list = {}
if os.path.isfile(tools_free_info):
with open(tools_free_info, "r") as free_info_handle:
for free_info in free_info_handle:
free_info = re.sub(r'\s+'," ",free_info)
if "Mem:" in free_info:
free_info_split = free_info.split(" ")
free_list["Mem_Total"] = float(free_info_split[1])/1000
free_list["Mem_Used"] = float(free_info_split[2])/1000
free_list["Mem_Avail"] = float(free_info_split[6])/1000