Using strace for analyzing performance

There is a very nice example on the O’reilly ‘Linux Under The Hood’ training about using strace to compare performance of two commands that provide the same output but with different calls. The two different commands were: ls and echo *, that they both provide the listing of the current directory.

First using the strace with ls:

kosmas:$ strace -c ls
abi-4.13.0-45-generic      config-4.4.0-31-generic        initrd.img-4.4.0-31-generic   System.map-4.15.0-123-generic         vmlinuz-4.15.0-123-generic
abi-4.13.0-46-generic      efi                            memtest86+.bin                System.map-4.15.0-124-generic         vmlinuz-4.15.0-124-generic
abi-4.4.0-31-generic       grub                           memtest86+.elf                System.map-4.15.0-126-generic         vmlinuz-4.15.0-126-generic
config-4.13.0-45-generic   initrd.img-4.13.0-45-generic   memtest86+_multiboot.bin      System.map-4.4.0-31-generic           vmlinuz-4.4.0-31-generic
config-4.13.0-46-generic   initrd.img-4.13.0-46-generic   retpoline-4.13.0-45-generic   vmlinuz-4.13.0-45-generic             vmlinuz-4.4.0-31-generic.efi.signed
config-4.15.0-123-generic  initrd.img-4.15.0-123-generic  retpoline-4.13.0-46-generic   vmlinuz-4.13.0-45-generic.efi.signed
config-4.15.0-124-generic  initrd.img-4.15.0-124-generic  System.map-4.13.0-45-generic  vmlinuz-4.13.0-46-generic
config-4.15.0-126-generic  initrd.img-4.15.0-126-generic  System.map-4.13.0-46-generic  vmlinuz-4.13.0-46-generic.efi.signed
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 15.81    0.000095          12         8           write
 14.64    0.000088           7        12           mprotect
 13.48    0.000081           5        17           mmap
  9.98    0.000060           7         9           openat
  7.82    0.000047           4        11           close
  7.32    0.000044          22         2           getdents
  6.82    0.000041           6         7           read
  5.66    0.000034           3        10           fstat
  4.99    0.000030           4         8         8 access
  3.16    0.000019          10         2         2 statfs
  2.00    0.000012          12         1           munmap
  1.83    0.000011           4         3           brk
  1.66    0.000010           5         2           ioctl
  1.50    0.000009           5         2           rt_sigaction
  0.67    0.000004           4         1           rt_sigprocmask
  0.67    0.000004           4         1           arch_prctl
  0.67    0.000004           4         1           set_tid_address
  0.67    0.000004           4         1           set_robust_list
  0.67    0.000004           4         1           prlimit64
  0.00    0.000000           0         1           execve
------ ----------- ----------- --------- --------- ----------------
100.00    0.000601                   100        10 total

And using the same with echo *

kosmas:$ strace -c echo *
abi-4.13.0-45-generic abi-4.13.0-46-generic abi-4.4.0-31-generic config-4.13.0-45-generic config-4.13.0-46-generic config-4.15.0-123-generic config-4.15.0-124-generic config-4.15.0-126-generic config-4.4.0-31-generic efi grub initrd.img-4.13.0-45-generic initrd.img-4.13.0-46-generic initrd.img-4.15.0-123-generic initrd.img-4.15.0-124-generic initrd.img-4.15.0-126-generic initrd.img-4.4.0-31-generic memtest86+.bin memtest86+.elf memtest86+_multiboot.bin retpoline-4.13.0-45-generic retpoline-4.13.0-46-generic System.map-4.13.0-45-generic System.map-4.13.0-46-generic System.map-4.15.0-123-generic System.map-4.15.0-124-generic System.map-4.15.0-126-generic System.map-4.4.0-31-generic vmlinuz-4.13.0-45-generic vmlinuz-4.13.0-45-generic.efi.signed vmlinuz-4.13.0-46-generic vmlinuz-4.13.0-46-generic.efi.signed vmlinuz-4.15.0-123-generic vmlinuz-4.15.0-124-generic vmlinuz-4.15.0-126-generic vmlinuz-4.4.0-31-generic vmlinuz-4.4.0-31-generic.efi.signed
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
  0.00    0.000000           0         1           read
  0.00    0.000000           0         1           write
  0.00    0.000000           0         5           close
  0.00    0.000000           0         4           fstat
  0.00    0.000000           0         6           mmap
  0.00    0.000000           0         4           mprotect
  0.00    0.000000           0         1           munmap
  0.00    0.000000           0         3           brk
  0.00    0.000000           0         3         3 access
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         1           arch_prctl
  0.00    0.000000           0         3           openat
------ ----------- ----------- --------- --------- ----------------
100.00    0.000000                    33         3 total

So the difference in time is 0.00000 for the echo and 0.000601 for the ls.

Similarly the number of calls for the echo is 33, but ls is using 100.

Raspberry, Ubuntu and Megatools

To install megtools (command line utilities for Mega.nz), in your raspberry with ubuntu installed follow the steps below (thanks to the instructions from here: https://www.instructables.com/id/Descarga-archivos-de-Mega-con-Raspberry-Pi/)

  • Install the necessary packages
sudo apt-get -y install build-essential libglib2.0-dev libssl-dev libcurl4-openssl-dev libgirepository1.0-dev 

You may also need to add some additional packages if there is an error about the documentation.

  • Get the latest source code from https://megatools.megous.com
wget https://megatools.megous.com/builds/megatools-1.10.3.tar.gz
  • Compile and install them
tar xvfz megatools-1.10.3.tar.gz
cd megatools-1.10.3
./configure
make
sudo make install
sudo ldconfig
  • Add your Mega account credentials in ~/.megarc like:
[Login]
Username = my_mega@email
Password = mypassword
  • use the mega tools commands (megacopy, megals, megaget etc.

Erlang and Elixir with asdf in Raspberry 4 with Ubuntu 20.04

To install the latest/current versions of erlang (23.0.2) and elixir (1.10.3), follow the instructions below:

Install asdf ( full instructions https://asdf-vm.com/#/core-manage-asdf-vm):

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.7.8

Add the following two lines in your ~/.bashrc file:

# Add asdf version manager 
. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash

Reload/Source your bash file with

source ~/.bashrc

Install the erlang plugin

asdf plugin add erlang

If you get the following warnings:

...
Extracting source code
Building Erlang/OTP 23.0.2 (asdf_23.0.2), please wait...
WARNING: It appears that a required development package 'libssl-dev' is not installed.
WARNING: It appears that a required development package 'automake' is not installed.
WARNING: It appears that a required development package 'autoconf' is not installed.
WARNING: It appears that a required development package 'libncurses5-dev' is not installed.
Configure failed.
...

Install the missing packages:

sudo apt install libssl-dev automake autoconf libncurses5-dev

Install latest erlang version:

asdf install erlang latest
...
Erlang/OTP 23.0.2 (asdf_23.0.2) has been successfully built
...

Set it up globally (if you want):

asdf global erlang 23.0.2

Add elixir plugin:

asdf plugin add elixir

Install latest elixir version (1.10.3):

asdf install elixir latest

Set it up globally:

asdf global elixir 1.10.3-otp-23

Finally you can also install the latest Phoenix version (1.5.3):

mix archive.install hex phx_new 1.5.3

WiFi, Raspberry Pi 4 B, Ubuntu 20.04

After installing an image of the Ubuntu server on the Raspberry 4, the wifi is not automatically configured after the initial book.

In order to be able to use the WiFi follow the steps described below for setting up your wifi in your SD card, and then reboot your raspberry (make sure that the indentation in the yaml file is correct, and also your WiFi access point is enclosed in quotes):

https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#3-wifi-or-ethernet

Get a list of your Route53 subdomains using aws cli docker image

Problem

You would like to have a list of your subdomains for a specific domain (hosted zone), that are hosted in Amazon’s Route 53.

Solution

You can install the aws cli docker image from here https://github.com/cgswong/docker-aws if you don’t want to install the aws cli in your computer.

You can afterwards start the container with:

docker run -it cgswong/aws:latest

Then configure it by running the following and adding your credentials and zone:

efe9881d4fd:/tmp# aws configure
 AWS Access Key ID [None]: aws_access_key_id
 AWS Secret Access Key [None]: aws_secret_access_key
 Default region name [None]: eu-central-1
 Default output format [None]:

Then run the first command to get a list of the hosted zones and get the id of the hosted zone you want to find the subdomains for:

3efe9881d4fd:/tmp# aws route53 list-hosted-zones
{
    "HostedZones": [
        {
            "ResourceRecordSetCount": 2, 
            "CallerReference": "RISWorkflow-RD:xxxxx", 
            "Config": {
                "Comment": "HostedZone created by Route53 Registrar", 
                "PrivateZone": false
            }, 
            "Id": "/hostedzone/HOSTEDZONEID", 
            "Name": "domain.net."
        }, 

Then pick the HOSTEDZONEID and run the following to get a list of subdomains for that domain:

3efe9881d4fd:/tmp# aws route53 list-resource-record-sets --hosted-zone="HOSTEDZONEID" | grep "Name" | uniq

   "Name": "alpah.domain.com.",                                                                                                                                                                                                                                             
   "Name": "beta.domain.com.",                                                                                                                                                                                                                                       
   "Name": "lamda.domain.com.",
......

Find your public IP address from linux command line

Problem

You would like to find out your public IP from the command line without using an online service

Solution

Use dig like the following line (taken from https://www.cyberciti.biz/faq/how-to-find-my-public-ip-address-from-command-line-on-a-linux/):

dig +short myip.opendns.com @resolver1.opendns.com

you could also add it as an alias:

alias myip=”dig +short myip.opendns.com @resolver1.opendns.com”