This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
pyctest-runner.py
executable file
·1750 lines (1597 loc) · 52.5 KB
/
pyctest-runner.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/env python
# -*- coding: utf-8 -*-
"""
PyCTest driver for timemory
"""
import os
import re
import sys
import platform
import traceback
import warnings
import multiprocessing as mp
import pyctest.pyctest as pyct
import pyctest.pycmake as pycm
import pyctest.helpers as helpers
from collections import OrderedDict
clobber_notes = True
available_tools = {
"avail": "TIMEMORY_BUILD_AVAIL",
"timem": "TIMEMORY_BUILD_TIMEM",
"kokkos": "TIMEMORY_BUILD_KOKKOS_TOOLS",
"kokkos-config": "TIMEMORY_BUILD_KOKKOS_CONFIG",
"dyninst": "TIMEMORY_BUILD_DYNINST_TOOLS",
"mpip": "TIMEMORY_BUILD_MPIP_LIBRARY",
"ompt": "TIMEMORY_BUILD_OMPT_LIBRARY",
"ncclp": "TIMEMORY_BUILD_NCCLP_LIBRARY",
"mallocp": "TIMEMORY_BUILD_MALLOCP_LIBRARY",
"compiler": "TIMEMORY_BUILD_COMPILER_INSTRUMENTATION",
"ert": "TIMEMORY_BUILD_ERT",
}
argparse_defaults = {}
build_name = ""
def get_branch(wd=pyct.SOURCE_DIRECTORY):
# handle pull-request
prname = None
if os.environ.get("CIRCLE_PULL_REQUEST", None) is not None:
prname = "pr"
prname = os.environ.get("CIRCLE_PR_REPONAME", prname)
if prname is None:
if os.environ.get("TRAVIS_EVENT_TYPE", "").lower() == "pull_request":
prname = os.environ.get("TRAVIS_PULL_REQUEST_SLUG", "pr").replace(
"/", "-"
)
# handle env specified
for env_var in ["CIRCLE_BRANCH", "TRAVIS_BRANCH"]:
env_branch = os.environ.get(env_var, None)
if env_branch is not None:
if prname is not None:
return "{}-{}".format(prname, env_branch)
return env_branch
cmd = pyct.command(["git", "show", "-s", "--pretty=%d", "HEAD"])
cmd.SetOutputStripTrailingWhitespace(True)
cmd.SetWorkingDirectory(wd)
cmd.Execute()
branch = cmd.Output()
branch = branch.split(" ")
if branch:
branch = branch[len(branch) - 1]
branch = branch.strip(")")
if not branch:
branch = pyct.GetGitBranch(wd)
return branch
def install_compile_time_perf(_dir):
import tempfile
if os.path.exists(os.path.join(_dir, "bin", "timem")):
return
source_dir = tempfile.mkdtemp()
def run_cmd(_cmd):
if not os.path.exists(source_dir):
os.makedirs(source_dir)
cmd = pyct.command(_cmd)
cmd.SetWorkingDirectory(source_dir)
cmd.SetOutputQuiet(False)
cmd.SetErrorQuiet(False)
cmd.Execute()
if int(cmd.Result()) > 0:
print("output message : {}".format(cmd.Output()))
print("error message : {}".format(cmd.Error()))
print(
"command failed with errc {}: {}".format(
cmd.Result(), " ".join(_cmd)
)
)
raise RuntimeError("command error")
git_cmd = helpers.FindExePath("git")
cmake_cmd = helpers.FindExePath("cmake")
if (git_cmd, cmake_cmd) is None:
return
run_cmd(
[
git_cmd,
"clone",
"https://github.com/jrmadsen/compile-time-perf.git",
]
)
run_cmd(
[
cmake_cmd,
"-B",
"build-ctp",
"-D",
f"CMAKE_INSTALL_PREFIX={_dir}",
"compile-time-perf",
]
)
run_cmd([cmake_cmd, "--build", "build-ctp", "--target", "all"])
run_cmd([cmake_cmd, "--build", "build-ctp", "--target", "install"])
os.environ["CMAKE_PREFIX_PATH"] = ":".join(
[_dir, os.environ.get("CMAKE_PREFIX_PATH", "")]
)
def configure():
# Get pyctest argument parser that include PyCTest arguments
parser = helpers.ArgumentParser(
project_name="timemory",
source_dir=os.getcwd(),
binary_dir=os.path.join(
os.getcwd(), "build-timemory", platform.system()
),
build_type="Release",
vcs_type="git",
use_launchers=False,
)
parser.add_argument(
"--quiet",
help="Disable reporting memory usage",
default=False,
action="store_true",
)
parser.add_argument(
"--arch",
help="TIMEMORY_USE_ARCH=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--profile",
help="Run gperf profiler",
default=None,
type=str,
choices=("cpu", "heap"),
)
parser.add_argument(
"--sanitizer",
help="Type of sanitizer",
default=None,
type=str,
choices=("leak", "memory", "address", "thread"),
)
parser.add_argument(
"--coverage",
help="TIMEMORY_USE_COVERAGE=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--static-analysis",
help="TIMEMORY_USE_CLANG_TIDY=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--tools",
help="TIMEMORY_BUILD_TOOLS=ON",
default=[],
nargs="*",
choices=available_tools.keys(),
)
parser.add_argument(
"--tau", help="TIMEMORY_USE_TAU=ON", default=False, action="store_true"
)
parser.add_argument(
"--cuda",
help="TIMEMORY_USE_CUDA=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--nvtx",
help="TIMEMORY_USE_NVTX=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--cupti",
help="TIMEMORY_USE_CUPTI=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--upcxx",
help="TIMEMORY_USE_UPCXX=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--gotcha",
help="TIMEMORY_USE_GOTCHA=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--gperftools",
help="TIMEMORY_USE_GPERFTOOLS=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--caliper",
help="TIMEMORY_USE_CALIPER=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--likwid",
help="TIMEMORY_USE_LIKWID=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--papi",
help="TIMEMORY_USE_PAPI=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--mpi", help="TIMEMORY_USE_MPI=ON", default=False, action="store_true"
)
parser.add_argument(
"--mpi-init",
help="TIMEMORY_USE_MPI_INIT=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--python",
help="TIMEMORY_BUILD_PYTHON=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--build-ompt",
help="TIMEMORY_BUILD_OMPT=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--extra-optimizations",
help="TIMEMORY_BUILD_EXTRA_OPTIMIZATIONS=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--lto",
help="TIMEMORY_BUILD_LTO=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--ipo",
help="CMAKE_INTERPROCEDURAL_OPTIMIZATION=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--developer",
help="TIMEMORY_BUILD_DEVELOPER=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--xray",
help="TIMEMORY_BUILD_XRAY=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--stats",
help="TIMEMORY_USE_STATISTICS=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--timing",
help="TIMEMORY_USE_COMPILE_TIMING=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--build-libs",
help="Build library type(s)",
default=["shared"],
nargs="*",
type=str,
choices=("static", "shared"),
)
parser.add_argument(
"--tls-model",
help="Thread-local static model",
default=("global-dynamic"),
type=str,
choices=(
"global-dynamic",
"local-dynamic",
"initial-exec",
"local-exec",
),
)
parser.add_argument(
"--cxx-standard",
help="C++ standard",
type=str,
default="17",
choices=("14", "17", "20"),
)
parser.add_argument(
"--generate", help="Generate the tests only", action="store_true"
)
parser.add_argument(
"-j",
"--cpu-count",
type=int,
default=mp.cpu_count(),
help="Parallel build jobs to run",
)
parser.add_argument(
"--quick",
help="Only build the library",
default=False,
action="store_true",
)
parser.add_argument(
"--minimal",
help="Only build unit tests (not examples)",
default=False,
action="store_true",
)
parser.add_argument(
"--compile-time-perf",
help="Build and install compile-time-perf in the given directory",
default=None,
type=str,
)
args = parser.parse_args()
if "kokkos-config" in args.tools and "kokkos" not in args.tools:
args.tools.append("kokkos")
if "shared" not in args.build_libs and args.python:
raise RuntimeError("Python cannot be built with static libraries")
if os.environ.get("CTEST_SITE") is not None:
pyct.set("CTEST_SITE", "{}".format(os.environ.get("CTEST_SITE")))
if os.path.exists(os.path.join(pyct.BINARY_DIRECTORY, "CMakeCache.txt")):
from pyctest import cmake_executable as cm
from pyctest import version_info as _pyctest_version
if (
_pyctest_version[0] == 0
and _pyctest_version[1] == 0
and _pyctest_version[2] < 11
):
cmd = pyct.command(
[cm, "--build", pyct.BINARY_DIRECTORY, "--target", "clean"]
)
cmd.SetWorkingDirectory(pyct.BINARY_DIRECTORY)
cmd.SetOutputQuiet(True)
cmd.SetErrorQuiet(True)
cmd.Execute()
else:
from pyctest.cmake import CMake
CMake("--build", pyct.BINARY_DIRECTORY, "--target", "clean")
helpers.RemovePath(
os.path.join(pyct.BINARY_DIRECTORY, "CMakeCache.txt")
)
if platform.system() != "Linux":
args.papi = False
os.environ["PYCTEST_TESTING"] = "ON"
os.environ["TIMEMORY_BANNER"] = "OFF"
os.environ["TIMEMORY_CTEST_NOTES"] = "ON"
os.environ["TIMEMORY_ENABLE_SIGNAL_HANDLER"] = "ON"
# os.environ["TIMEMORY_PLOT_OUTPUT"] = "OFF"
# update PYTHONPATH for the unit tests
pypath = os.environ.get("PYTHONPATH", "").split(":")
pypath = [pyct.BINARY_DIRECTORY] + pypath
os.environ["PYTHONPATH"] = ":".join(pypath)
global build_name
global argparse_defaults
# generate the defaults
argparse_defaults = {key: parser.get_default(key) for key in vars(args)}
# sort them for consistency
argparse_defaults = OrderedDict(sorted(argparse_defaults.items()))
# construct a build name from the arguments that were changed
for key, itr in argparse_defaults.items():
# ignore all pyctest args except the build type
if "pyctest_" in key and key != "pyctest_build_type":
continue
if "quiet" in key:
continue
if "compile_time_perf" in key:
continue
# get the current value
curr = args.__getattribute__(key)
# if the value is true
if curr != itr:
if isinstance(curr, bool) and curr:
# just add name of boolean options
build_name = "-".join([build_name, key[:4]])
elif isinstance(curr, list):
# if list, join the args
build_name = "-".join(
[
build_name,
"-".join(["{}".format(val[:6]) for val in curr]),
]
)
elif isinstance(curr, str):
# if string, just abbreviated name
build_name = "-".join([build_name, curr[:6]])
elif key == "cxx_standard":
# ignore all else except for the C++ standard
build_name = "-".join([build_name, f"cxx{itr}"])
build_name = "-".join(sorted(build_name.strip("-").split("-"))).replace(
"kokkos-kokkos", "kokkos-config"
)
if args.compile_time_perf is not None:
try:
install_compile_time_perf(args.compile_time_perf)
except RuntimeError:
pass
return args
def run_pyctest():
# run argparse, checkout source, copy over files
#
args = configure()
google_pprof = helpers.FindExePath("google-pprof")
if google_pprof is None:
google_pprof = helpers.FindExePath("pprof")
# find srun and mpirun
#
dmprun = None
dmpargs = ["-n", "2"]
for dmpexe in ("srun", "jsrun", "mpirun"):
try:
dmprun = helpers.FindExePath(dmpexe)
if dmprun is not None and os.path.isabs(dmprun):
if dmpexe == "srun":
dmpargs += ["-c", "1"]
elif dmpexe == "jsrun":
dmpargs += ["-c", "1"]
break
except Exception as e:
print("Exception: {}".format(e))
# Compiler version
#
if os.environ.get("CXX") is None:
os.environ["CXX"] = helpers.FindExePath("c++")
cmd = pyct.command([os.environ["CXX"], "--version"])
cmd.SetOutputStripTrailingWhitespace(True)
cmd.Execute()
compiler_version = cmd.Output().replace("Ubuntu", "").lower()
cn = os.environ["CXX"]
try:
cn = compiler_version.split()[0]
cv = re.search(r"(\b)\d+.\d", compiler_version)
compiler_version = "{}-{}".format(cn, cv.group()).replace("++", "xx")
except Exception as e:
print("Exception! {}".format(e))
cmd = pyct.command([os.environ["CXX"], "-dumpversion"])
cmd.SetOutputStripTrailingWhitespace(True)
cmd.Execute()
compiler_version = "{}{}".format(cn, cmd.Output()).replace("++", "xx")
# Set the build name
#
pyct.BUILD_NAME = (
"{}-{}-{}".format(
get_branch(pyct.SOURCE_DIRECTORY),
platform.uname()[0],
compiler_version,
)
.replace("/", "-")
.replace(" ", "-")
.replace("--", "-")
)
# build specifications
#
build_opts = {
"BUILD_SHARED_LIBS": "ON" if "shared" in args.build_libs else "OFF",
"BUILD_STATIC_LIBS": "ON" if "static" in args.build_libs else "OFF",
"CMAKE_INTERPROCEDURAL_OPTIMIZATION": "ON" if args.ipo else "OFF",
"CMAKE_CXX_STANDARD": "{}".format(args.cxx_standard),
"TIMEMORY_CI": "ON",
"TIMEMORY_TLS_MODEL": "{}".format(args.tls_model),
"TIMEMORY_CCACHE_BUILD": "OFF",
"TIMEMORY_BUILD_C": "ON",
"TIMEMORY_BUILD_LTO": "ON" if args.lto else "OFF",
"TIMEMORY_BUILD_OMPT": "ON" if args.build_ompt else "OFF",
"TIMEMORY_BUILD_TOOLS": "ON" if len(args.tools) > 0 else "OFF",
"TIMEMORY_BUILD_GOTCHA": "ON" if args.gotcha else "OFF",
"TIMEMORY_BUILD_PYTHON": "ON" if args.python else "OFF",
"TIMEMORY_BUILD_CALIPER": "ON" if args.caliper else "OFF",
"TIMEMORY_BUILD_DEVELOPER": "ON" if args.developer else "OFF",
"TIMEMORY_BUILD_TESTING": "ON" if not args.quick else "OFF",
"TIMEMORY_BUILD_EXAMPLES": "OFF"
if args.quick or args.minimal
else "ON",
"TIMEMORY_BUILD_EXTRA_OPTIMIZATIONS": "ON"
if args.extra_optimizations
else "OFF",
"TIMEMORY_USE_CTP": "ON"
if args.compile_time_perf is not None
else "OFF",
"TIMEMORY_USE_MPI": "ON" if args.mpi else "OFF",
"TIMEMORY_USE_TAU": "ON" if args.tau else "OFF",
"TIMEMORY_USE_ARCH": "ON" if args.arch else "OFF",
"TIMEMORY_USE_PAPI": "ON" if args.papi else "OFF",
"TIMEMORY_USE_CUDA": "ON" if args.cuda else "OFF",
"TIMEMORY_USE_NVTX": "ON" if args.nvtx else "OFF",
"TIMEMORY_USE_OMPT": "ON" if "ompt" in args.tools else "OFF",
"TIMEMORY_USE_XRAY": "ON" if args.xray else "OFF",
"TIMEMORY_USE_CUPTI": "ON" if args.cupti else "OFF",
"TIMEMORY_USE_UPCXX": "ON" if args.upcxx else "OFF",
"TIMEMORY_USE_LIKWID": "ON" if args.likwid else "OFF",
"TIMEMORY_USE_GOTCHA": "ON" if args.gotcha else "OFF",
"TIMEMORY_USE_PYTHON": "ON" if args.python else "OFF",
"TIMEMORY_USE_CALIPER": "ON" if args.caliper else "OFF",
"TIMEMORY_USE_COVERAGE": "ON" if args.coverage else "OFF",
"TIMEMORY_USE_GPERFTOOLS": "ON" if args.gperftools else "OFF",
"TIMEMORY_USE_STATISTICS": "ON" if args.stats else "OFF",
"TIMEMORY_USE_COMPILE_TIMING": "ON" if args.timing else "OFF",
"TIMEMORY_USE_SANITIZER": "OFF",
"TIMEMORY_USE_CLANG_TIDY": "ON" if args.static_analysis else "OFF",
}
if args.minimal:
build_opts["TIMEMORY_BUILD_MINIMAL_TESTING"] = "ON"
build_opts["TIMEMORY_BUILD_EXAMPLES"] = "OFF"
if args.papi:
build_opts["USE_PAPI"] = "ON"
if args.caliper:
build_opts["USE_CALIPER"] = "ON"
if args.mpi:
build_opts["USE_MPI"] = "ON"
if args.mpi and args.mpi_init:
build_opts["TIMEMORY_USE_MPI_INIT"] = "ON"
if args.build_ompt:
build_opts["OPENMP_ENABLE_LIBOMPTARGET"] = "OFF"
if "avail" not in args.tools:
args.tools.append("avail")
for key, opt in available_tools.items():
build_opts[opt] = "ON" if (key in args.tools) else "OFF"
if "dyninst" in args.tools:
build_opts["TIMEMORY_USE_DYNINST"] = "ON"
if args.python:
pyver = "{}{}".format(
sys.version_info[0],
sys.version_info[1],
)
pyct.BUILD_NAME = "{}-py{}".format(pyct.BUILD_NAME, pyver)
if args.profile is not None:
build_opts["TIMEMORY_USE_GPERFTOOLS"] = "ON"
components = "profiler" if args.profile == "cpu" else "tcmalloc"
build_opts["TIMEMORY_gperftools_COMPONENTS"] = components
if args.sanitizer is not None:
build_opts["SANITIZER_TYPE"] = args.sanitizer
build_opts["TIMEMORY_USE_SANITIZER"] = "ON"
if args.coverage:
gcov_exe = helpers.FindExePath("gcov")
if gcov_exe is not None:
pyct.COVERAGE_COMMAND = "{}".format(gcov_exe)
build_opts["TIMEMORY_USE_COVERAGE"] = "ON"
if pyct.BUILD_TYPE != "Debug":
warnings.warn(
"Forcing build type to 'Debug' when coverage is enabled"
)
pyct.BUILD_TYPE = "Debug"
else:
build_opts["TIMEMORY_USE_COVERAGE"] = "OFF"
pyct.set(
"CTEST_CUSTOM_COVERAGE_EXCLUDE",
";".join(
[
"/usr/.*",
".*external/.*",
".*examples/.*",
".*source/tests/.*",
".*source/tools/.*",
".*source/python/.*",
".*source/timemory/tpls/.*",
".*/signals.hpp",
".*/popen.cpp",
]
),
)
pyct.set("CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS", "100")
pyct.set("CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS", "100")
# Use the options to create a build name with configuration
pyct.BUILD_NAME = (
(
"{}-{}".format(pyct.BUILD_NAME, build_name)
.replace("/", "-")
.replace(" ", "-")
)
.strip("-")
.replace("origin-", "")
)
# default options
cmake_args = "-DCMAKE_BUILD_TYPE={}".format(pyct.BUILD_TYPE)
# customized from args
for key, val in build_opts.items():
cmake_args = "{} -D{}={}".format(cmake_args, key, val)
cmake_args = "-DPYTHON_EXECUTABLE={} {} {}".format(
sys.executable, cmake_args, " ".join(pycm.ARGUMENTS)
)
# how to build the code
#
ctest_cmake_cmd = "${CTEST_CMAKE_COMMAND}"
pyct.CONFIGURE_COMMAND = "{} {} {}".format(
ctest_cmake_cmd, cmake_args, pyct.SOURCE_DIRECTORY
)
# how to build the code
#
pyct.BUILD_COMMAND = "{} --build {} --target all --parallel {}".format(
ctest_cmake_cmd,
pyct.BINARY_DIRECTORY,
args.cpu_count,
)
# Windows build command extras
#
if platform.system() == "Windows":
pyct.BUILD_COMMAND = "{} -- /MP -A x64".format(pyct.BUILD_COMMAND)
# how to update the code
#
git_exe = helpers.FindExePath("git")
pyct.UPDATE_COMMAND = "{}".format(git_exe)
pyct.set("CTEST_UPDATE_TYPE", "git")
pyct.set("CTEST_GIT_COMMAND", "{}".format(git_exe))
# find the CTEST_TOKEN_FILE
#
if args.pyctest_token_file is None and args.pyctest_token is None:
home = helpers.GetHomePath()
if home is not None:
token_path = os.path.join(
home, os.path.join(".tokens", "nersc-cdash")
)
if os.path.exists(token_path):
pyct.set("CTEST_TOKEN_FILE", token_path)
# construct a command
#
def construct_name(test_name):
return test_name.replace("_", "-")
# construct a command
#
def construct_command(cmd, args):
global clobber_notes
_cmd = []
if args.profile is not None and google_pprof is not None:
_exe = os.path.basename(cmd[0])
if args.profile == "cpu":
_cmd.append(
os.path.join(pyct.BINARY_DIRECTORY, "gperf-cpu-profile.sh")
)
pyct.add_note(
pyct.BINARY_DIRECTORY,
"cpu.prof.{}/gperf.0.txt".format(_exe),
clobber=clobber_notes,
)
pyct.add_note(
pyct.BINARY_DIRECTORY,
"cpu.prof.{}/gperf.0.cum.txt".format(_exe),
clobber=False,
)
clobber_notes = False
elif args.profile == "heap":
_cmd.append(
os.path.join(pyct.BINARY_DIRECTORY, "gperf-heap-profile.sh")
)
for itr in [
"alloc_objects",
"alloc_space",
"inuse_objects",
"inuse_space",
]:
pyct.add_note(
pyct.BINARY_DIRECTORY,
"heap.prof.{}/gperf.0.0001.heap.{}.txt".format(
_exe, itr
),
clobber=clobber_notes,
)
# make sure all subsequent iterations don't clobber
clobber_notes = False
_cmd.extend(cmd)
return _cmd
# construct a command
#
def construct_roofline_command(cmd, dir, extra_opts=[], use_mpi=True):
_cmd = [
sys.executable,
"-m",
"timemory.roofline",
"-e",
"-D",
dir,
"--format",
"png",
]
_cmd.extend(extra_opts)
_cmd.extend(["--"])
if use_mpi and args.mpi and dmprun is not None:
_cmd += [dmprun] + dmpargs
_cmd.extend(cmd)
return _cmd
# testing environ
#
pypath = ":".join(
["{}".format(pyct.BINARY_DIRECTORY), os.environ.get("PYTHONPATH", "")]
)
base_env = ";".join(
[
"CPUPROFILE_FREQUENCY=200",
"CPUPROFILE_REALTIME=1",
"CALI_CONFIG_PROFILE=runtime-report",
"TIMEMORY_PLOT_OUTPUT=ON",
"PYTHONPATH={}".format(pypath),
]
)
if args.coverage or pyct.BUILD_TYPE == "Debug":
base_env = ";".join(
[base_env, "TIMEMORY_DEBUG=ON", "TIMEMORY_VERBOSE=6"]
)
test_env = ";".join(
[base_env, "TIMEMORY_DART_OUTPUT=ON", "TIMEMORY_DART_COUNT=1"]
)
# create tests
#
if "avail" in args.tools:
pyct.test(
"timemory-avail",
["./timemory-avail", "-a"],
{
"WORKING_DIRECTORY": pyct.BINARY_DIRECTORY,
"LABELS": pyct.PROJECT_NAME,
"TIMEOUT": "30",
"ENVIRONMENT": test_env,
},
)
if "timem" in args.tools:
def add_timem_test(name, cmd):
if len(cmd) > 1:
cmd.append("--")
cmd.append("sleep")
pyct.test(
"{}-zero".format(name),
cmd + ["0"],
{
"WORKING_DIRECTORY": pyct.BINARY_DIRECTORY,
"LABELS": pyct.PROJECT_NAME,
"TIMEOUT": "10",
"ENVIRONMENT": base_env,
},
)
pyct.test(
name,
cmd + ["2"],
{
"WORKING_DIRECTORY": pyct.BINARY_DIRECTORY,
"LABELS": pyct.PROJECT_NAME,
"TIMEOUT": "10",
"ENVIRONMENT": base_env,
},
)
add_timem_test("timemory-timem", ["./timem"])
add_timem_test(
"timemory-timem-shell", ["./timem", "-s", "-v", "2", "--debug"]
)
add_timem_test(
"timemory-timem-no-sample",
["./timem", "--disable-sample"],
)
add_timem_test(
"timemory-timem-json",
["./timem", "-o", "timem-output"],
)
if args.mpi and dmprun is not None:
add_timem_test(
"timemory-timem-mpi",
[dmprun] + dmpargs + ["./timem-mpi"],
)
add_timem_test(
"timemory-timem-mpi-shell",
[dmprun] + dmpargs + ["./timem-mpi", "-s"],
)
add_timem_test(
"timemory-timem-mpi-individual",
[dmprun] + dmpargs + ["./timem-mpi", "-i"],
)
add_timem_test(
"timemory-timem-mpi-individual-json",
[dmprun]
+ dmpargs
+ [
"./timem-mpi",
"-i",
"-o",
"timem-mpi-output",
],
)
if args.python:
pyct.test(
"timemory-python",
[
sys.executable,
"-c",
"import timemory; print(timemory.__file__)",
],
{
"WORKING_DIRECTORY": pyct.BINARY_DIRECTORY,
"LABELS": pyct.PROJECT_NAME,
"TIMEOUT": "120",
"ENVIRONMENT": base_env,
},
)
pyct.test(
"timemory-python-profiler",
[
sys.executable,
"./ex_python_profiler",
"10",
],
{
"WORKING_DIRECTORY": pyct.BINARY_DIRECTORY,
"LABELS": pyct.PROJECT_NAME,
"TIMEOUT": "120",
"ENVIRONMENT": base_env,
},
)
pyct.test(
"timemory-python-profiler-main",
[
sys.executable,
"-m",
"timemory.profiler",
"--max-stack-depth=10",
"-l",
"-f",
"-F",
"-c",
"wall_clock",
"peak_rss",
"--",
"./ex_python_external",
"12",
],
{
"WORKING_DIRECTORY": pyct.BINARY_DIRECTORY,
"LABELS": pyct.PROJECT_NAME,
"TIMEOUT": "120",
"ENVIRONMENT": base_env,
},
)
pyct.test(
"timemory-python-profiler-main-no-opts",
[
sys.executable,
"-m",
"timemory.profiler",
"./ex_python_external",
"5",
],
{
"WORKING_DIRECTORY": pyct.BINARY_DIRECTORY,
"LABELS": pyct.PROJECT_NAME,
"TIMEOUT": "120",
"ENVIRONMENT": base_env,
},
)
pyct.test(
"timemory-python-profiler-main-script",
[
os.path.join(
pyct.BINARY_DIRECTORY, "bin", "timemory-python-profiler"
),
"--max-stack-depth=10",
"-l",
"-f",
"-F",
"-c",
"wall_clock",
"peak_rss",
"--",
"./ex_python_external",
"12",
],
{
"WORKING_DIRECTORY": pyct.BINARY_DIRECTORY,
"LABELS": pyct.PROJECT_NAME,
"TIMEOUT": "120",
"ENVIRONMENT": base_env,
},
)
pyct.test(
"timemory-python-profiler-builtin",
[
sys.executable,
"-m",
"timemory.profiler",
"--max-stack-depth=10",
"-b",
"-l",
"-f",
"-F",
"-c",
"wall_clock",
"peak_rss",
"--",