www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [dub] Passing --DRT-gcopt to dmd

reply Anonymouse <asdf asdf.net> writes:
I'm trying to tweak the GC when compiling with dub, starting with 
something easy like profile:1.

 $ grep dflags dub.json
     "dflags": [ "-lowmem", "--DRT-gcopt=profile:1" ],
 $ dub test
Doesn't work, doesn't give any extra output. Entering bogus flags like --DRT-gcopt=banana:1 doesn't evoke any error message either, making me doubt it's being passed on at all.
 $ dmd -oftest -lowmem --DRT-gcopt=profile:1 source/**/*.d
         Number of collections:  13
         Total GC prep time:  7 milliseconds
         Total mark time:  2110 milliseconds
         Total sweep time:  270 milliseconds
         Total page recovery time:  204 milliseconds
         Max Pause Time:  472 milliseconds
         Grand total GC time:  2592 milliseconds
 GC summary: 1099 MB,   13 GC 2592 ms, Pauses 2117 ms <  472 ms
Manual dmd invocation does work, so it's not like dmd is ignoring --DRT-gcopt.
 $ dub test --DRT-gcopt=profile:1
 [...]
         Number of collections:  10
         Total GC prep time:  0 milliseconds
         Total mark time:  4 milliseconds
         Total sweep time:  7 milliseconds
         Total page recovery time:  4 milliseconds
         Max Pause Time:  0 milliseconds
         Grand total GC time:  15 milliseconds
 GC summary:   12 MB,   10 GC   15 ms, Pauses    4 ms <    0 ms
The totals should be in the ballpark of 1Gb+ (as above), not 12Mb. Is it only profiling dub itself? (Incidentally this is roughly what dmd reports if called without -lowmem.)
 $ export DRT_GCOPT=profile:1
 $ dub test
Doesn't work either, I can't actually get the env var to affect dmd at all, even when manually running it. What is the correct way?
May 31 2019
next sibling parent reply Mike Parker <aldacron gmail.com> writes:
On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:

 What is the correct way?
--DRT flags are for run time, not compile time. They're intended to be passed to your executable and not the compiler. From the docs [1]: "By default, GC options can only be passed on the command line of the program to run" With dub, anything following a solitary -- on the command line will be passed to the application [2], so you probably want something like this: dub test -- --DRT-gcopt=profile:1 [1] https://dlang.org/spec/garbage.html#gc_config [2] https://dub.pm/commandline
May 31 2019
next sibling parent reply Anonymouse <asdf asdf.net> writes:
On Friday, 31 May 2019 at 10:47:20 UTC, Mike Parker wrote:
 On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:

 What is the correct way?
--DRT flags are for run time, not compile time. They're intended to be passed to your executable and not the compiler. From the docs [1]: "By default, GC options can only be passed on the command line of the program to run"
My use-case is limiting the amount of memory dmd will allocate before -lowmem kicks in and collects (by use of --DRT-gcopt=heapSizeFactor on dmd), to accomodate for limited available memory. As pasted in the original post I seem to be able to do this manually. So there is no way to set up a dub build configuration that automates this?
May 31 2019
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Friday, 31 May 2019 at 13:37:05 UTC, Anonymouse wrote:
 On Friday, 31 May 2019 at 10:47:20 UTC, Mike Parker wrote:
 On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:

 What is the correct way?
--DRT flags are for run time, not compile time. They're intended to be passed to your executable and not the compiler. From the docs [1]: "By default, GC options can only be passed on the command line of the program to run"
My use-case is limiting the amount of memory dmd will allocate before -lowmem kicks in and collects (by use of --DRT-gcopt=heapSizeFactor on dmd), to accomodate for limited available memory. As pasted in the original post I seem to be able to do this manually. So there is no way to set up a dub build configuration that automates this?
You can specify the parameters also in code. See example here https://dlang.org/changelog/2.085.0.html#gc_cleanup Kind regards Andre
May 31 2019
parent Anonymouse <asdf asdf.net> writes:
On Friday, 31 May 2019 at 13:50:57 UTC, Andre Pany wrote:
 You can specify the parameters also in code. See example here

 https://dlang.org/changelog/2.085.0.html#gc_cleanup
I need it to apply to dmd though, I'm exceeding memory limits when compiling. Once done the program doesn't need a whole lot of it, but dmd -lowmem does.
May 31 2019
prev sibling parent Andre Pany <andre s-e-a-p.de> writes:
On Friday, 31 May 2019 at 10:47:20 UTC, Mike Parker wrote:
 On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:

 What is the correct way?
--DRT flags are for run time, not compile time. They're intended to be passed to your executable and not the compiler. From the docs [1]: "By default, GC options can only be passed on the command line of the program to run" With dub, anything following a solitary -- on the command line will be passed to the application [2], so you probably want something like this: dub test -- --DRT-gcopt=profile:1 [1] https://dlang.org/spec/garbage.html#gc_config [2] https://dub.pm/commandline
This might be eaten by the runtime of dub and not the application. Kind regards Andre
May 31 2019
prev sibling parent reply kinke <noone nowhere.com> writes:
On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:
 $ grep dflags dub.json
     "dflags": [ "-lowmem", "--DRT-gcopt=profile:1" ],
This should work indeed. I guess it doesn't because dub probably uses a response file containing all cmdline options, whereas -lowmem definitely [and --DRT-* probably] need to be direct cmdline args.
May 31 2019
parent reply Anonymouse <asdf asdf.net> writes:
On Friday, 31 May 2019 at 15:31:13 UTC, kinke wrote:
 On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:
 $ grep dflags dub.json
     "dflags": [ "-lowmem", "--DRT-gcopt=profile:1" ],
This should work indeed. I guess it doesn't because dub probably uses a response file containing all cmdline options, whereas -lowmem definitely [and --DRT-* probably] need to be direct cmdline args.
Is this something I can/should report? (Where do dub issues go?)
May 31 2019
parent Mathias Lang <pro.mathias.lang gmail.com> writes:
On Friday, 31 May 2019 at 15:41:24 UTC, Anonymouse wrote:
 On Friday, 31 May 2019 at 15:31:13 UTC, kinke wrote:
 On Friday, 31 May 2019 at 10:27:44 UTC, Anonymouse wrote:
 $ grep dflags dub.json
     "dflags": [ "-lowmem", "--DRT-gcopt=profile:1" ],
This should work indeed. I guess it doesn't because dub probably uses a response file containing all cmdline options, whereas -lowmem definitely [and --DRT-* probably] need to be direct cmdline args.
Is this something I can/should report? (Where do dub issues go?)
Replying here despite the delay because this is one of the top post when one google for gcopts. This will be possible with the new version of the runtime (>=2.091.0, not released yet). It has been filled as https://issues.dlang.org/show_bug.cgi?id=20459 and was fixed in https://github.com/dlang/druntime/pull/2881 which means dub compiled with druntime >= 2.091 will allow you to do: `dub -- --DRT-gcopt=profile:1` And any other D program will ignore `--DRT` options if provided after the `--` delimiter.
Feb 03 2020