Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
December 14, 2018 Map of functions | ||||
---|---|---|---|---|
| ||||
Hi Is there an utility to print the functions in a source file, for example: - main() --- calculate() ----- print() --- simulate() ----- print() ..... Thank you very much Giovanni Di Maria |
December 14, 2018 Re: Map of functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Giovanni Di Maria | On Friday, 14 December 2018 at 15:38:49 UTC, Giovanni Di Maria wrote:
> Hi
> Is there an utility to print
> the functions in a source file, for example:
>
> - main()
> --- calculate()
> ----- print()
> --- simulate()
> ----- print()
> .....
> Thank you very much
> Giovanni Di Maria
Do you really have a nested function print() inside a nested function calculate() inside main()? That is,
void main()
{
void calculate()
{
void print()
{
}
// maybe some calls to print()
}
// maybe some calls to calculate()
}
Or are you talking about the sequence in which function are *called*, and from where? Please clarify.
Ivan Kazmenko.
|
December 14, 2018 Re: Map of functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ivan Kazmenko | >
> Do you really have a nested function print() inside a nested function calculate() inside main()? That is,
Hi
this is only an example of names of funcions but the structure is this:
void main()
{
// maybe some calls to calculate()
}
void calculate()
{
// maybe some calls to print()
}
void print()
{
}
I need the flow of calls.
Thank you
Giovanni
|
December 14, 2018 Re: Map of functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Giovanni Di Maria | On Fri, 14 Dec 2018 16:33:44 +0000, Giovanni Di Maria wrote:
>
> I need the flow of calls.
> Thank you Giovanni
gprof will do this on Linux/BSD if gdc supports the -pg flag (I don't know whether it would, but assume so) and your application is working.
From code, you'd need to call a trace function on function entry. Mine lets you also specify a message (parameter values, etc.):
---
void trace(T...)(T args, string func = __FUNCTION__) {
import std.stdio : writeln;
if (args.length > 0) {
debug writeln("*trace: ", func, "- ", args);
} else {
debug writeln("*trace: ", func);
}
}
void main(int a, string b) {
trace();
trace(a, ", ", b);
}
---
|
December 14, 2018 Re: Map of functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to rjframe | Thank you very much, Fantastic!!! Giovanni |
December 15, 2018 Re: Map of functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to rjframe | On Friday, 14 December 2018 at 17:45:26 UTC, rjframe wrote: > On Fri, 14 Dec 2018 16:33:44 +0000, Giovanni Di Maria wrote: > >> >> I need the flow of calls. >> Thank you Giovanni > > gprof will do this on Linux/BSD if gdc supports the -pg flag (I don't know whether it would, but assume so) and your application is working. > > > From code, you'd need to call a trace function on function entry. Mine lets you also specify a message (parameter values, etc.): > > --- > void trace(T...)(T args, string func = __FUNCTION__) { > import std.stdio : writeln; > if (args.length > 0) { > debug writeln("*trace: ", func, "- ", args); > } else { > debug writeln("*trace: ", func); > } > } > > void main(int a, string b) { > trace(); > trace(a, ", ", b); > } > --- You can also generate a call graph using callgrind. That however will slow down your program. There are some python script that converts the output of callgrind to a dot file that can be converted to svg. https://stackoverflow.com/questions/33769323/make-callgrind-show-all-function-calls-in-the-kcachegrind-callgraph |
December 16, 2018 Re: Map of functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Francesco Mecca | Thank you very much. Great!!! Giovanni |
Copyright © 1999-2021 by the D Language Foundation