What is o-profile? See the description below extracted from http://oprofile.sourceforge.net/, o-profile official website OProfile is a system-wide profiler for Linux systems, capable of profiling all running code at low overhead. OProfile is released under the GNU GPL. It consists of a kernel driver and a daemon for collecting sample data, and several post-profiling tools for turning data into information. OProfile leverages the hardware performance counters of the CPU to enable profiling of a wide variety of interesting statistics, which can also be used for basic time-spent profiling. All code is profiled: hardware and software interrupt handlers, kernel modules, the kernel, shared libraries, and applications. OProfile is currently in alpha status; however it has proven stable over a large number of differing configurations; it is being used on machines ranging from laptops to 16-way NUMA-Q boxes. As always, there is no warranty. Why don’t we use gprof? For embedded system , […]
Finding and fixing memoy leaks in your software
Memory leaks will cause your device to crash after a period of time once it runs out of memory. A quick way to find out if your application has a memory leak(s) is to monitor it with top:
1 2 |
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 15 0 2156 668 572 S 0 5 .0 0:00.14 application |
If you see the %MEM increase over time for no particular reason, then you’ve got a memory leak. However, it might be tricky to isolate where the issue occurs exactly. The first thing to do is the review your source code for the following: Malloced memory is always freed fopen is always followed by fclose, and open by close scandir calls are properly freed Threads are properly terminated with pthread_cancel & pthread_join or pthread_detach, etc… If after a code review you cannot find the reason for the memory leak, use the following piece of code:
1 2 3 4 5 6 7 8 9 10 11 12 |
int return_process_memory_usage(void) { char buf[64]; int fd = open("/proc/self/statm", O_RDONLY); if(fd < 0) { return -1; } read(fd, buf, sizeof(buf)); close(fd); return atoi(buf); } #define DISPLAY_MEMORY_USAGE fprintf(stderr, "Memory usage: %d pages\n", return_process_memory_usage); |
The memory usage is displayed in numbers of pages. Usually, one page is 4096 […]
Mounting a JFFS2 image in a Linux PC
We often use JFFS2 binary images for embedded system, generating them with mkfs.jffs2. In some instances, it could also be good to mount a jffs2 image into your PC to modify it directly. To do that, type the following commands as root in a linux shell: modprobe mtdcore modprobe jffs2 modprobe mtdram modprobe mtdchar modprobe mtdblock dd if=image-jffs2 of=/dev/mtd0 mount /dev/mtdblock0 mnt If your image is larger than the default kernel size (4MB in my case), you can try to adjust the mtdram device size with the total_size parameters. when inserting the mtdram module, e.g.: modprobe mtdram total_size=8096 where total_size is expressed in KB Further details can be found @ http://www.handhelds.org/hypermail/familiar/62/6232.html Jean-Luc Aufranc (CNXSoft)Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011. www.cnx-software.com