Thread overview
LDC2 and classic profiling
May 10, 2019
Denis Feklushkin
May 10, 2019
Johan Engelen
May 11, 2019
Denis Feklushkin
May 11, 2019
Denis Feklushkin
May 11, 2019
Johan Engelen
May 11, 2019
Denis Feklushkin
May 11, 2019
Denis Feklushkin
May 12, 2019
Denis Feklushkin
May 12, 2019
Johan Engelen
May 13, 2019
Denis Feklushkin
May 10, 2019
Build with dub some package. Profiling are enabled by dub.json:

"dflags-ldc": ["-fprofile-instr-generate", "-finstrument-functions", "-cov"],

Resulting default.profraw (and generated default.profdata) contains only calls to external libraries, but not my internal functions calls.

Why?

May 10, 2019
On Friday, 10 May 2019 at 14:00:30 UTC, Denis Feklushkin wrote:
> Build with dub some package. Profiling are enabled by dub.json:
>
> "dflags-ldc": ["-fprofile-instr-generate", "-finstrument-functions", "-cov"],
>
> Resulting default.profraw (and generated default.profdata) contains only calls to external libraries, but not my internal functions calls.
>
> Why?

You only need `-fprofile-instr-generate` for generating default.profraw.

> contains only calls to external libraries

That's impossible, because those are exactly _not_ profiled.

This may help: https://forum.dlang.org/post/voknxddblrbuywcyfdwt@forum.dlang.org

-Johan

May 11, 2019
On Friday, 10 May 2019 at 18:09:28 UTC, Johan Engelen wrote:

> You only need `-fprofile-instr-generate` for generating default.profraw.

Yep, it is because I also tried to use uftrace and xray

>
>> contains only calls to external libraries
>
> That's impossible, because those are exactly _not_ profiled.

Yes. Probably, it was uftrace output.

But, nevertheless, I do not see calls of my own functions.
In addition to the call _Dmain and _D4mainQfFAAyaZ9__lambda2MFZv

All another calls is made inside of this lambda - maybe lambdas is not traced by profiler?

>
> This may help: https://forum.dlang.org/post/voknxddblrbuywcyfdwt@forum.dlang.org

Already read it.
May 11, 2019
On Saturday, 11 May 2019 at 05:46:29 UTC, Denis Feklushkin wrote:

> All another calls is made inside of this lambda - maybe lambdas is not traced by profiler?

Tried to remove lambda with same result.

Command:

llvm-profdata show -all-functions -topn=100000 default.profdata

returns huge amount of std*, core*, vibe* calls - it is all used in my code. But here is no one my own function (except "main").

Also I changed flags to "dflags-ldc": ["-fprofile-instr-generate", "-O0"] - second flag disables optimisation (I assumed that optimizations magically completely remove calls to my functions. But this is probably not the case.)
May 11, 2019
On Saturday, 11 May 2019 at 06:59:52 UTC, Denis Feklushkin wrote:
> On Saturday, 11 May 2019 at 05:46:29 UTC, Denis Feklushkin wrote:
>
>> All another calls is made inside of this lambda - maybe lambdas is not traced by profiler?
>
> Tried to remove lambda with same result.
>
> Command:
>
> llvm-profdata show -all-functions -topn=100000 default.profdata
>
> returns huge amount of std*, core*, vibe* calls - it is all used in my code. But here is no one my own function (except "main").

Those calls are to templated functions I presume? (they are instantiated in your program and hence instrumented)

> Also I changed flags to "dflags-ldc": ["-fprofile-instr-generate", "-O0"] - second flag disables optimisation (I assumed that optimizations magically completely remove calls to my functions. But this is probably not the case.)

No, indeed, -O0 doesn't (shouldn't!) matter.

It is strange that you don't see calls to your functions. Just to verify, could you compile a simple program manually (without dub) and verify that you see calls to your own functions? Lambdas should also be instrumented, so please test that.

By the way, if you are on linux, then XRay should work like with clang ( -fxray-instrument )

-Johan

May 11, 2019
On Saturday, 11 May 2019 at 09:12:24 UTC, Johan Engelen wrote:

> Those calls are to templated functions I presume?

No

> instantiated in your program and hence instrumented)
>
>> Also I changed flags to "dflags-ldc": ["-fprofile-instr-generate", "-O0"] - second flag disables optimisation (I assumed that optimizations magically completely remove calls to my functions. But this is probably not the case.)
>
> No, indeed, -O0 doesn't (shouldn't!) matter.

Ok.

> It is strange that you don't see calls to your functions. Just to verify, could you compile a simple program manually (without dub) and verify that you see calls to your own functions?

Tried, and it works!

> Lambdas should also be instrumented, so please test that.

Works on simple program too.

> By the way, if you are on linux, then XRay should work like with clang ( -fxray-instrument )

Tried it, and xray also does not returns any info about my own functions...

May 11, 2019
On Saturday, 11 May 2019 at 11:34:35 UTC, Denis Feklushkin wrote:

> Tried it, and xray also does not returns any info about my own functions...

Maybe DUB caches binaries and linker links previous non-instrumented object files?
I tried "dub clean" and "dub clean-caches" but maybe it is need remove someting else?

May 12, 2019
On Saturday, 11 May 2019 at 11:38:17 UTC, Denis Feklushkin wrote:

>
> Maybe DUB caches binaries and linker links previous non-instrumented object files?
> I tried "dub clean" and "dub clean-caches" but maybe it is need remove someting else?

Checked with "dub -f" and nothing changed.
May 12, 2019
On Saturday, 11 May 2019 at 11:34:35 UTC, Denis Feklushkin wrote:
> On Saturday, 11 May 2019 at 09:12:24 UTC, Johan Engelen wrote:
>
>> Those calls are to templated functions I presume?
>
> No

Then I don't understand how you'd see instrumentation on functions that you did not compile with -fprofile-instr-generate (indirect calls to such functions may be recorded); the std lib is not compiled with profiling instrumentation, and so you shouldn't see any internal instrumentation of it. Unless those functions are instantiated in your object file (e.g. templates or explicitly inlined functions).

>>
>>> Also I changed flags to "dflags-ldc": ["-fprofile-instr-generate", "-O0"] - second flag disables optimisation (I assumed that optimizations magically completely remove calls to my functions. But this is probably not the case.)
>>
>> No, indeed, -O0 doesn't (shouldn't!) matter.
>
> Ok.
>
>> It is strange that you don't see calls to your functions. Just to verify, could you compile a simple program manually (without dub) and verify that you see calls to your own functions?
>
> Tried, and it works!
>
>> Lambdas should also be instrumented, so please test that.
>
> Works on simple program too.

Excellent.

I think dub -v will output the exact commands that dub is executing.
Looks like some parts are not compiled with the compile flag, and some other parts are?

>> By the way, if you are on linux, then XRay should work like with clang ( -fxray-instrument )
>
> Tried it, and xray also does not returns any info about my own functions...

You tried with DUB or manually? Note that XRay has a (configurable) threshold for not instrumenting very small functions.
See for example this test: https://github.com/ldc-developers/ldc/blob/master/tests/instrument/xray_simple_execution.d

-Johan

May 13, 2019
On Sunday, 12 May 2019 at 17:24:24 UTC, Johan Engelen wrote:

>
> Excellent.
>
> I think dub -v will output the exact commands that dub is executing.
> Looks like some parts are not compiled with the compile flag, and some other parts are?

Got it!

-v displays only one ldc2 execution with -fprofile-instr-generate
It contains huge number of -I and -dversion options, and this call contains main.d compilation. But main.d placed inside of subpackage and uses my own (outer) dependency package which also compiled without -fprofile-instr-generate and calls inside of this dependency is not displayed!

So, all another ldc2 calls which compiles dependencies is not contain -fprofile-instr-generate!

(Also, xray was affected same misconfiguration)

Thanks!