Using gprof with Nios II

Hi,

Has anybody been trying to use gprof within the NIOS II IDE ? We have some problems regarding the profiling data that is send through the jtag interface directly to the IDE console window.

We had a look to the documentation but there is little information regarding the use of the profiler with the NIOS II.

It seems that, to the difference of NIOS I, the profiling data is sent as binary data, resulting in the following stdout trace :

< Here the program standard output > **gmon.out data follows** < non readable binary data >

nios2-terminal: exiting due to ^D on remote

Does anybody knows how to solve this issue ?

Thank you in advance,

Steven

Reply to
steven derrien
Loading thread data ...

Hi Steven,

Here are the basic steps to using GPROF in Nios II:

(In the IDE):

  1. Add a compiler switch, "-pg", for your src code project (in the C/C++ build area of the project properties). This is standard fare for using GPROF regardless of processor.
  2. Add the same "-pg" switch for the compiler in your system library project.
  3. Check the "use profiling library" checkbox in syslib properties.

(From the SDK Shell):

  1. Run your program: Use nios2-terminal's "--gmon" switch which will automatically capture the profiling data into a 'gmon.out' file after your program finishes execution. This has to be done from the command line, not the IDE.

Note: nios2-terminal must be started with the processor in a paused state. You can do this by opening two SDK shell windows, downloading your program using "nios2-download " (which downloads your code and leaves the processor paused), then running "nios2-terminal

--gmon" in the second window, and finally running "nios2-download -g" in the first to start execution.

More notes: Your application must return from main() because the profiling library's data dump is triggered by reaching atexit().

Also, the above notes assume that you're using the JTAG UART for STDIO; for the conventional UART we cannot support GPROF with the above flow just yet (this is scheduled for the next release)

  1. Place the "gmon.out" file (generated in step 4) into the same dir as your .elf file
  2. Run nios2-elf-gprof gmon.out >
  3. Examine the output file for results.

The above flow was actually easier than I had expected given my GPROF experience with other processors :) However, I am sending an enhancement request to our engineering team to make the above flow all happen from within the IDE so that the SDK shell business isn't necessary.

Also, I'll see to it that this is looked at for a relevant app note when the time comes; in addition to GPROF there is a performance counter peripheral (which is documented in the Nios II kit) which is useful for profiling sections of code -- such an app note will likely describe the use of both tools.

Jesse Kempa Altera Corp. jkempa at altera dot com

Reply to
Jesse Kempa

Thank you for your help.

Steven

Jesse Kempa wrote:

Reply to
steven derrien

Jesse,

The performance counter is very usefull. I used it already in Nios1, with a custom peripheral just counting clock cycles. The point in my design was that I use a 64 bit counter. So it is expected to never roll over. The counter part of this is that you have to do two read actions to it to get the time.

If you then add some classes, you can define a kind of PseudoTimer class. Each instance keeps track of when it is started and stopped. Finde code below.

Hope this can be of any use for someone

Stefaan.

Verilog code for counter :

module never_ending_timer(Clk, Reset, Out, A, nRD, CS);

input Clk, Reset; input A, nRD, CS; output [31:0] Out;

parameter bits = 64;

reg [bits-1:0] cnt; reg [bits - 32 - 1 : 0] temp;

always @(posedge Clk or posedge Reset) if (Reset) begin cnt Ticks(); delta = t - start; start = t; if (delta > 0xFFFFFFFFFFFFFFFFL) return 0xFFFFFFFF; Running = 0; return (DWORD) delta; };

DWORD PeekDWORD() { //peak doesn't affect timer operation if (Running) { QWORD t = hw->Ticks(); delta = t - start; } if (delta > 0xFFFFFFFFFFFFFFFFL) return 0xFFFFFFFF; return (DWORD) delta; };

QWORD Peek() { //peak doesn't affect timer operation if (Running) { QWORD t = hw->Ticks(); delta = t - start; } return delta; };

QWORD Stop() { //you can use stop as a brand new starting point QWORD t = hw->Ticks(); delta = t - start; start = t; Running = 0; return delta; }; };

Reply to
Vanheesbeke Stefaan

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.