Showing posts with label c. Show all posts
Showing posts with label c. Show all posts

Wednesday, August 31, 2016

Optimize a C program by visually checking the profiling data

You need ''gprof2dot.py'' (specific standalone tool) and the regular package ''dot'' (from graphviz).

''
g++ -pg -g myproc.cpp myproc
myproc myarg1 myarg2
gprof myproc | gprof2dot.py -s | dot -Tpng -o profiler.png
''

Note that the ''-g'' debugging option is required.

Note also that any code optimization flag, like ''-o3'' (aggressive speed optimization), will significantly impact the code layout, and it will be much harder to recognize the profiled sections.  It is much easier to read when most optimizations are tuned off (''-o1'' or ''-o0'').

But there is a nasty trade-off... Without optimization, the overall program will certainly behave differently than in production. It will not spend the same time in the same routines. Reciprocally, with full optimization you are closer to the real program you want to probe... but it will be sometimes just impossible to recognize the source code and unrolled functions that the profiler points to.

Wednesday, December 2, 2015

Rewriting a bare millis() clock on an AVR without the Arduino environment

This is a short stand-alone C source code that I wrote to simulate the Arduino millis() function on an Atmel AVR 328p microcontroller. It is part of a growing collection of AVR routines.


AVR 328p minimalist serial read/write source code

This is a C source code I wrote to do serial read/write on an Atmel AVR 328p microcontroller.
This is the same processor as the Arduino Uno for example. It is part of a growing collection of AVR routines.

And since you can set your own limits, you can use this code in place of the usual Serial class, as the default buffers are quite small and they may overflow if you are not processing them fast enough, or if you are sending too much data at once (eg. file copy/paste). Note that some terminals let you set add a small delay automatically after each line is sent, which is the way to go so as to leave enough time for your program to process the incoming flow.


Tuesday, April 28, 2015

increment a C float until it fails: maximum value is about 16,777,216

Higher limit of an incremented float in C


So I finally made it clear. The first increment that has no effect on a C ''float'' variable is around +16,777,216. So four-byte wise, a float still fails later than what I thought compared to a ''uint32_t''.