pstack equivalent in erlang - erlang

When a Erlang system hangs I want to know what the system is doing during that time. For a c/c++ program, I can easily run the pstack, but I didn't find out a handy tool for this purpose in Erlang.
What is the pstack equivalent in Erlang?
Actually I want to check the running stack trace of the following process.
"/opt/couchbase/lib/erlang/erts-5.10.4.0.0.1/bin/beam.smp -P 327680 -K true -- -root /opt/couchbase/lib/erlang -progname erl --... "
and I started a new Erlang shell and start the webtool and check the appmon however I can't find the above application. What may cause this?
Thanks

Concerning pstack equivalent, have you read Erlang Profiling from official guide? It gives you lot of example on how to profile your application and find where your code stuck.
Another useful tools is observer it will show all working process, CPU usage, process stack and lot of more information.
If you don't see anything with these tools, you can try with Erlang debugger.
Now concerning couchbase, if your application is currently running, you can connect to it with Erlang shell and launch previous quoted commands and applications.
I don't know if you are using couchbase alone or with couchdb, but, if you want to use observer or other tools from command line, you can start couchdb with -i flag:
# -i use the interactive Erlang shell
couchdb -i
In case of your application run remotely without GUI, you can use etop, its a CLI alternative to observer. You can also dump etop output to file if you don't want to run it directly from your Erlang shell. IHMO, if you want more information concerning I/O or debug, use eprof, fprof and other profiling tools with dump file (see also eep profiling tool, easy to use).
Another alternative, if you are using SSH and want to see observer window, you can use X11Forwarding with ssh: ssh -X $yourserver or ssh -Y $yourserver and simply run observer:start(). in your Erlang shell.

Related

Replace Erlang shell with system command

Is it possible to replace the erl shell with a system command? Similar to how you would with a POSIX exec call?
I'm trying to set up an SSH server in Erlang that gives a separate CLI instead of the built in one. I'm aware of OpenSSH's sshd's options to do this; does Erlang have something similar?
For example, how would I get the following command to work as it does with sshd(8) in an Erlang environment?
# connect to Erlang SSH server and drop into IPython shell
ssh user#host ipython
I have the server working fine—I'm able to connect without problems—and I know that you can develop your own CLI with the ssh_cli option for ssh:daemon. It might have something to do with ports and drivers or the user_drv:start command, but I'm having difficulty figuring out how this all works.

getting process ID of a pub serve to then kill that thread/process

So when I run my Polymer Dart application, i use pub serve and the serve is created and served. It will stay running until until i break out of it. I was curious if there is a way to programmatically stop it.
One of the options I was looking at was looking at the running processes and then killing the pub serve process.
I was not sure though how i would get the process id to kill it, or unless there was another option.
Maybe someone has an even better approach to shutdown pub serve on the machine automatically, as a form of cleanup?
The issue I have noticed is that if i get the running proceesses, i only see "cmd" as a process so that isnt the best determining factor.
I was not sure if there was a way via pub on serve to get its process if, if it set a flag or global of sorts I could leverage
This is not a Dart or Pub question really, it's a Windows, MacOS, Linux etc. shell process control question.
The question is more suited to Stack Exchange Superuser https://superuser.com/ I believe. You could look over there for more detailed answer ... but ... assuming you are using the windows command prompt:
start /B starts a process in the background.
tasklist can be used to look up running process PIDs.
taskkill /PID kills a running process.
You can use help <command> or search for documentation.
I have not used these personally but it looks awkward as start /B does not give you the PID of the process it ran. Unix shells such as Bash have good facilities for running processes in the background. Windows Powershell may have better support also.

Start Erlang on startup.

I'm working on using erlang development server. Is there a way fro me to start the erlang vm and continue from the commandline or add a script to the startup files? To be clear I want to start erlang and keep it running outside of the command prompt.
You can use the -detached flag. See http://www.erlang.org/doc/man/erl.html for more information.
I usually use scripts, which rebar create-node do provide. There is such commands as: start, stop, ping and attach. Although you must use erlang releases in order to use this scripts (at list take a look at template, maybe it would be helpful)

Profiling linked-in drivers in Erlang

How can I profile a linked-in port driver? OTP tools (fprof, etc.) apparently only profile Erlang code, and I don't have a C executable file to feed to gprof.
Can't you just profile the erl executable and then get that to the gprof tool? I am pretty sure this is how it is done by the Erlang devs anyway.
as far as linked-in port driver is .so library that is dynamically loaded into erl process (on linux) you can run valgrind --tool=callgrind --callgrind-out-file=file.out erl (see other options in docs for callgrind), then execute some tests from erl shell, exit from shell and load file.out in some tool like KCachegrind

Riak on Windows

I want to play with Riak http://riak.basho.com/ or a least get it running on a Windows system. I have downloaded the source code and compiled it but that's where I get stuck, how do I start it?
It does run, altough I havent managed to run it as a service yet.
Install CYGwin, install latest erlang, get source code, compile in cygwin
then the fun part, adjust according to your paths and place into a batch
c:\riak\rel\riak\erts-5.7.4\bin\erl -boot c:\riak\rel\riak\releases\0.8\riak -embedded -config c:\riak\rel\riak\etc\app.config -args_file c:\riak\rel\riak\etc\vm.args -- console
Regards
Looks like the riak source has several bash start scripts. You would have to convert those to a windows batch script equivalent. That could be a fairly interesting chore given how limited batch scripts are. Those start-*.sh files show how to start it up though so I'd start there.
The http://hg.basho.com/riak/src/tip/README Readme file has futher info on what each script does.
Riak can not be run on Windows, only on Linux and Mac.
An alternative is to run VMWare or VirtualBox and run Riak inside a Linux VM. Works great for me.
Running it inside docker instance works very well - this is in 2017 the only way to successfully run Riak on Windows. You could probably get something running using Cygwin but this will be very complex and unreliable. Running under Docker is currently the most idiomatic solution.

Resources