czwartek, 12 stycznia 2012
JFFS2 vs UBIFS
Interesting description of UBIFS (UBI File-System) and what might be more important description of main features of JFFS2 can be found here.
niedziela, 4 grudnia 2011
Linux serial terminal
Serial port communication in linux (with usb->serial converter in mind).
IMHO best is good old screen
Problem can appear after device (e.g. ttyUSB0) is created only for root.
udev rule has to be set. Add new file e.g. 99-local.rules to /etc/udev/rules.d directory:
To see if usb to serial converter is working in linux "lsusb" can be used.
Access to usb possible due to libusb.
References:
http://www.plugcomputer.org/plugwiki/index.php/Serial_terminal/Linux/Programs
http://www.libelle-systems.com/free/wine/serial_port_access.html
http://www.libusb.org/
IMHO best is good old screen
screen /dev/ttyUSB0 115200
Problem can appear after device (e.g. ttyUSB0) is created only for root.
udev rule has to be set. Add new file e.g. 99-local.rules to /etc/udev/rules.d directory:
# Locally defined rules.
# Give world read/write access to ttyS* and ttyUSB* serial devices
#
KERNEL=="tty[A-Z]*", GROUP="uucp", MODE="0666"
To see if usb to serial converter is working in linux "lsusb" can be used.
Access to usb possible due to libusb.
References:
http://www.plugcomputer.org/plugwiki/index.php/Serial_terminal/Linux/Programs
http://www.libelle-systems.com/free/wine/serial_port_access.html
http://www.libusb.org/
czwartek, 29 września 2011
Profiling
Basic profiling tool - gprof
Required '-pg' added for compilation and linking.
Profile results are stored in file 'gmon.out'. Default place for the file is working directory of the program being profiled. Important - process has to be closed with normal termination - exit() or end of main() function - profile file is saved on process termination.
Potentially interesting - environmental variables for gprof (not sure if working):
GMON_OUT_PREFIX, PROFDIR, PROFFLAGS.
sources:
http://sourceware.org/binutils/docs/gprof/
http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html
http://sourceware.org/gdb/onlinedocs/gdb/
Other:
Tool from Intel - Pin
GNU cflow analyzes a collection of C source files and prints a graph, charting control flow within the program.
ltrace, ptrace, etrace, ftrace
SystemTap - http://sourceware.org/systemtap/examples/general/para-callgraph.stp - Observe, systemtap and oprofile updates
-finstrument-functions gcc
http://blog.superadditive.com/2007/12/01/call-graphs-using-the-gnu-project-debugger/
Required '-pg' added for compilation and linking.
Profile results are stored in file 'gmon.out'. Default place for the file is working directory of the program being profiled. Important - process has to be closed with normal termination - exit() or end of main() function - profile file is saved on process termination.
Potentially interesting - environmental variables for gprof (not sure if working):
GMON_OUT_PREFIX, PROFDIR, PROFFLAGS.
sources:
http://sourceware.org/binutils/docs/gprof/
http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html
http://sourceware.org/gdb/onlinedocs/gdb/
Other:
Tool from Intel - Pin
GNU cflow analyzes a collection of C source files and prints a graph, charting control flow within the program.
ltrace, ptrace, etrace, ftrace
SystemTap - http://sourceware.org/systemtap/examples/general/para-callgraph.stp - Observe, systemtap and oprofile updates
-finstrument-functions gcc
http://blog.superadditive.com/2007/12/01/call-graphs-using-the-gnu-project-debugger/
środa, 6 lipca 2011
enum <-> string
Nice preprocessor usage (found here: http://lists.gnucash.org/pipermail/gnucash-devel/2005-March/012849.html)
#include
#define ENUM_BODY(name, value) \
name = value,
#define AS_STRING_CASE(name, value) \
case name: return #name;
#define FROM_STRING_CASE(name, value) \
if (strcmp(str, #name) == 0) { \
return name; \
}
#define DEFINE_ENUM(name, list) \
typedef enum { \
list(ENUM_BODY) \
}name; \
const char* asString(name n) { \
switch (n) { \
list(AS_STRING_CASE) \
default: return ""; \
} \
} \
name fromString(const char* str) { \
list(FROM_STRING_CASE) \
return 0; /* assert? throw? */ \
}
#define ENUM_LIST(_) \
_(RED, 0) \
_(GREEN, 1) \
_(BLUE, 87)
DEFINE_ENUM(Color, ENUM_LIST)
int main() {
Color c = GREEN;
printf("%d\n",c);
printf("%s\n", asString(c));
printf("%d\n", fromString("BLUE"));
}
Another enum -> string can be found here
#include
#define ENUM_BODY(name, value) \
name = value,
#define AS_STRING_CASE(name, value) \
case name: return #name;
#define FROM_STRING_CASE(name, value) \
if (strcmp(str, #name) == 0) { \
return name; \
}
#define DEFINE_ENUM(name, list) \
typedef enum { \
list(ENUM_BODY) \
}name; \
const char* asString(name n) { \
switch (n) { \
list(AS_STRING_CASE) \
default: return ""; \
} \
} \
name fromString(const char* str) { \
list(FROM_STRING_CASE) \
return 0; /* assert? throw? */ \
}
#define ENUM_LIST(_) \
_(RED, 0) \
_(GREEN, 1) \
_(BLUE, 87)
DEFINE_ENUM(Color, ENUM_LIST)
int main() {
Color c = GREEN;
printf("%d\n",c);
printf("%s\n", asString(c));
printf("%d\n", fromString("BLUE"));
}
Another enum -> string can be found here
niedziela, 22 maja 2011
Memory allocation checking
Here is list how to check for memory allocation problems (leaks, writing past buffer, etc.)
glibc based:
- mcheck(), mprobe() functions and MALLOC_CHECK_ env. variable (see 'man malloc' and http://www.gnu.org/s/libc/manual/html_node/Heap-Consistency-Checking.html)
- mtrace() function and 'mtrace' command http://www.gnu.org/s/libc/manual/html_node/Allocation-Debugging.html
- glibc-utils (mtrace, xtrace, memusage, ...)
gcc based:
- Mudflap Pointer Debugging http://gcc.gnu.org/wiki/Mudflap_Pointer_Debugging
- GCC extensions: Bounds checking patches, ProPolice Stack-Smashing Protector
One thing is not clear here - there is option -fbounds-check which seems to compile in gcc (does it work?) and 'bounds checking patches' which gives -fbounds-checking option.
One and only:
- valgrind
Other free solutions:
- Electric fence http://directory.fsf.org/project/ElectricFence/
- DUMA library http://sourceforge.net/projects/duma/
- Memwatch http://www.linkdata.se/sourcecode/memwatch/
- halloc - not really a checker but useful http://directory.fsf.org/project/halloc/
Proprietary:
- Insure++
- Purify (IBM-Rational)
There is basic question - maybe design approach should be different e.g.:
- allocate memory on startup (pool)
- use sentry to check if tasks release objects allocated on pool
glibc based:
- mcheck(), mprobe() functions and MALLOC_CHECK_ env. variable (see 'man malloc' and http://www.gnu.org/s/libc/manual/html_node/Heap-Consistency-Checking.html)
- mtrace() function and 'mtrace' command http://www.gnu.org/s/libc/manual/html_node/Allocation-Debugging.html
- glibc-utils (mtrace, xtrace, memusage, ...)
gcc based:
- Mudflap Pointer Debugging http://gcc.gnu.org/wiki/Mudflap_Pointer_Debugging
- GCC extensions: Bounds checking patches, ProPolice Stack-Smashing Protector
One thing is not clear here - there is option -fbounds-check which seems to compile in gcc (does it work?) and 'bounds checking patches' which gives -fbounds-checking option.
One and only:
- valgrind
Other free solutions:
- Electric fence http://directory.fsf.org/project/ElectricFence/
- DUMA library http://sourceforge.net/projects/duma/
- Memwatch http://www.linkdata.se/sourcecode/memwatch/
- halloc - not really a checker but useful http://directory.fsf.org/project/halloc/
Proprietary:
- Insure++
- Purify (IBM-Rational)
There is basic question - maybe design approach should be different e.g.:
- allocate memory on startup (pool)
- use sentry to check if tasks release objects allocated on pool
niedziela, 15 maja 2011
Here are potentially useful libraries used in Samba project.
TDB (Trivial DataBase)
"In concept, it is very much like GDBM, and BSD's DB except that it allows multiple simultaneous writers and uses locking internally to keep writers from trampling on each other. tdb is also extremely small."
It has added transactions support.
http://tdb.samba.org/index.html
TAlloc
"Hierarchical, reference counted memory pool system with destructors. It is the core memory allocator used in Samba (LGPL)."
http://talloc.samba.org/talloc/doc/html/index.html
man 3 talloc
TEvent
"Tevent is an event system based on the talloc memory management library."
http://tevent.samba.org/index.html
All Samba related sub-projects one can find at http://samba.com under "Related Sites".
Additionally here is page with junk code form Samba author:
http://www.samba.org/junkcode/
More description of junk code in conference materials.
Especially worth mentioning is 'segv_handler'.
TDB (Trivial DataBase)
"In concept, it is very much like GDBM, and BSD's DB except that it allows multiple simultaneous writers and uses locking internally to keep writers from trampling on each other. tdb is also extremely small."
It has added transactions support.
http://tdb.samba.org/index.html
TAlloc
"Hierarchical, reference counted memory pool system with destructors. It is the core memory allocator used in Samba (LGPL)."
http://talloc.samba.org/talloc/doc/html/index.html
man 3 talloc
TEvent
"Tevent is an event system based on the talloc memory management library."
http://tevent.samba.org/index.html
All Samba related sub-projects one can find at http://samba.com under "Related Sites".
Additionally here is page with junk code form Samba author:
http://www.samba.org/junkcode/
More description of junk code in conference materials.
Especially worth mentioning is 'segv_handler'.
Parallel mode extensions in gcc standard c++ library
Approach based on OpenMP. Here is info regarding the extension:
http://gcc.gnu.org/onlinedocs/libstdc++/manual/parallel_mode.html
http://gcc.gnu.org/onlinedocs/libstdc++/manual/parallel_mode.html
Subskrybuj:
Posty (Atom)