Jokes of the proper kind, properly told, can do more to enlighten questions of politics, philosophy, and literature than any number of dull arguments.
—Isaac Asimov, scientist and writer (1920-92)
(Source: fast-t-feasts, via ashalynd)
Announcing Common Crawl
Several years ago my friend Gil Elbaz (CEO of Factual; forefather of Google AdWords) approached me with an ambitious vision – he wanted to create an open not-for-profit crawl of the Web to ensure that everyone would have equal access to a Web-scale search index to build on and experiment with.
Self-modifying code for debug tracing in quasi-C
Printing a program’s state as it runs is the simple but effective debugging tool of programmers everywhere. For efficiency, we usually disable the most verbose output in production. But sometimes you need to diagnose a problem in a deployed system. It would be convenient to declare “tracepoints” and enable them at runtime, like so: Here’s a simple implementation of this API: Each tracepoint is simply a global variable. The construct This approach does introduce a bit of overhead. One concern is that reading a global variable will cause a cache miss and will also evict a line of useful data from the cache. There’s also some impact from adding a branch instruction. We’ll develop a significantly more complicated implementation which avoids both of these problems. Our new solution will be specific to x86-64 processors running Linux, though the idea can be ported to other platforms. This approach is inspired by various self-modifying-code schemes in the Linux kernel, such as ftrace, kprobes, immediate values, etc. It’s mostly intended as an example of how these tricks work. The code in this article is not production-ready.tracepoint foo_entry;
int foo(int n) {
TRACE(foo_entry, "called foo(%d)\n", n);
// ...
}
// Called from UI, monitoring interface, etc.
void debug_foo() {
enable(&foo_entry);
}typedef int tracepoint;
#define TRACE(_point, _args...) \
do { \
if (_point) printf(_args); \
} while (0)
static inline void enable(tracepoint *point) {
*point = 1;
}do { ... } while (0) is a standard trick to make macro-expanded code play nicely with its surroundings. We also use GCC’s syntax for macros with a variable number of arguments.


