Investigating Erlang by reading its system calls
jvns.ca
jvns.ca
erl -noshell +sbwt none -smp disable +A 0 -mode minimal -eval 'io:format("Hello world~n").' -s init stop
instead, which is much closer to what python/java et al runs, then at least I get around 2850 syscalls.
The constant ppoll:ing is because erts spins looking for new work from any fd. Specifically "/sys/devices/system/node/node0" is in order to check for cpu topology updates by the operating system, i.e. if for some reason a core/cpu is taken offline of something like that. This is limited in my example above by "+sbwt none"
IIRC the bind is an UDP socket to talk to the local nameserver. This is removed in my example with "-mode minimal".
Erlang is like another system inside your system, it's more akin to booting a system inside a vm just to echo some hello world.
I believe Erlang would do some interesting things there
† ring-0 only, no memory protection, exploratory dev/art focused
To put it another way, if you run code on a system with concurrency units sharing the memory (the heap), your code is running on DOS or Windows 3.1 which was cool in 1990s.
Erlang/Elixir is like running your code on a modern OS with a process memory separation, preemptable concurrency (processes don't have to yield by hand to others). Built in tracing and monitoring facilities (tracing, observer, dbg). Built in networking (distribution, global process registration, in memory distributed db) etc.
Erlang isn't a bare programming language like C, or even a high level, but still fundamentally simple language like Python.
It isn't just an intermediary bytecode running in a VM, like Java, that maps bytecode instructions to OS instructions.
It is instead more like a Smalltalk environment or similar; an entire ecosystem running for the specific purpose of providing you a very particular kind of programming environment.
Compared with strace on Linux it is like night and day.
On debugging, second bullet. She seems to agree.
One serious problem - it has to run as root.
If you want to debug Erlang program then Erlang/OTP already includes tools to help you do that: http://www.erlang-in-anger.com/ - 92 page manual that includes: - tracing functions called with defined parameters - analyzing crash dumps, memory leaks, cpu scheduling
epmd is a separate process, yes. But an erlang node connects to epmd in order to register it's name on it. It will bind a socket to talk with epmd (probably among other things).. See also: http://erlang.org/doc/apps/erts/erl_dist_protocol.html
$ cat hello.tl
(pprinl "hello, world")
$ strace txr hello.tl 2>&1 > /dev/null | wc -l
77
$ cat hello.c
#include <stdio.h>
int main(void) { printf("Hello, world\n"); }
$ cc -O hello.c -o hello
$ strace ./hello 2>&1 > /dev/null | wc -l
29
$ strace gawk 'BEGIN { print "hello") }' 2>&1 > /dev/null | wc -l
8467
$ strace txr -e '(put-line "hello")' 2>&1 > /dev/null | wc -l
70
Very similar.Obviously there are those who care about reasonable startup times and, ... others. :)
By the way, TXR supports setuid operation, and so it makes a few extra syscalls to check its security situation (am I running setuid? setgid?)
$ cat HelloWorld.java
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello, world");
}
}
$ strace java HelloWorld 2>&1 > /dev/null | wc -l
122 $ strace python -c "print('hello world')" 2>&1 > /dev/null | wc -l
924
$ strace python3 -c "print('hello world')" 2>&1 > /dev/null | wc -l
543 % strace perl -e "print 'Hello, World';" 2>&1 > /dev/null | wc -l
192Using your example:
$ strace python3 -c 'print("hello world", end="")' 2>&1 | hist
1. stat 122
2. rt_sigaction 68
3. fstat 67
4. read 55
5. close 47
6. open 37
7. mmap 34
8. lseek 30
9. getdents 18
10. mprotect 16
...
TOTAL: 567
$ strace python3 -S -c 'print("hello world", end="")' 2>&1 | hist
1. rt_sigaction 68
2. stat 51
3. fstat 39
4. mmap 31
5. read 27
6. close 26
7. open 23
8. mprotect 16
9. lseek 15
10. brk 10
...
TOTAL: 350 $ strace node -e 'console.log("hello world")' 2>&1 > /dev/null | wc -l
304Isn't it the case that in Java and Erlang we have a large VM environment that also needs to be launched before the first line of the trivial print statement is executed?
$ cargo new --bin hello
$ cd hello
$ cargo build --release
$ strace ./target/release/hello 2>&1 | wc -l
124Why not do a specific call before the actual code to segment the strace, or run it with repetitions and subtract+divide to get calls/repetition?
My first thought: "So this guy is investigating Erlang with strace, but he couldn't be bothered to Google articles on its design!?" Then I tried Googling this myself. Uh, yeah. I happen to know this stuff, even though I don't use Erlang, but it's not exactly easy to find packaged conveniently in one place.