Wednesday, February 8, 2017

How to find the memory consumption of a particular process

How to measure actual memory usage of an application or process ?
How to find how much a specific process use ?
Just run pmem.sh script with a process name ! such as..

$ ./pmem.sh chrome
chrome's memory usage : 60.9 %

As you can see, you can find out what percentage does the process use of all memory.

$ cat pmem.sh
#!/bin/bash

if [ "$1" == "" ]; then
   echo "Please enter process name"
   exit 0
fi

p_count=`ps -eo comm | grep -wc "$1"`

if [ "$p_count" == "0" ]; then
   echo "Error: '$1' process don't exist"
   exit 0
fi


mem_usage=`ps -eo pmem,comm | grep -we "$1" | awk -F" " '{print  $1}' | paste -sd+ | bc`
echo "$1's memory usage : $mem_usage %"

exit 0

Wednesday, July 1, 2015

Virtual Box : SSH (How to login to a guest OS)

Virtual Box : SSH (How to login to a guest OS)

<1> Install SSH
Sure, you have to install a ‘ssh’ service on a guest OS

$ sudo apt-get install -y openssh-server

<2> Change VBox setting

# A guest OS name : my_ubuntu
# Host port       : 3022
# Guest port      : 22
#
# Sure, you can change port number as below
# $ emacs /etc/ssh/sshd_config
# $ service ssh restart

$ VBoxManage modifyvm my_ubuntu --natpf1 "ssh,tcp,,3022,,22"

# You can check VBox settings as below
$ VBoxManage showvminfo myserver | grep 'Rule'

<3> SSH into the guest OS on Virtual Box

# Even if network is unreachable, no problem
$ ssh -p 3022 user@127.0.0.1

* Referense page

solvedstack

Saturday, May 30, 2015

Cscope & Emacs ( simple integration)

Cscope & Emacs ( simple integration)

Installation cscope

# os           :  ubuntu 13.10
# emacs  :  24.3.1
# cscope :  15.8b

Dowload cscope

$ tar zxvf cscope-X.Y.tar.gz
$ cd cscope-X.Y
$ ./configure
$ sudo make install

Cscope & Emacs configuration

$ cd contrib/xcscope
$ sudo cp cscope-indexer /usr/local/bin
$ cp xcscope.el ~/.emacs.d/

# cscope configuration for emacs 
$ echo '(load-file "~/.emacs.d/xcscope.el")' >> ~/.emacs

Create index file and set initial dir

# get ready to browse your source code.
# if you installed cscope, run emacs and work some commands by following.
M-x cscope-index-file <RET>
# and then enter your workspace path 
# or in order to detailedly collect cscope information, separately create cscope.files and cscope.out as below  
$ rm -rf cscope.files cscope.out
$ find . \( -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.s' -o -name '*.S' \) -print > cscope.files
$ cscope -b -i cscope.files

M-x cscope-set-initial-directory <RET>
# or run this command to assign your workspace path to it
C-c s a 

Cscope commands on emacs

# most-used
C-c s d     Find global definition.
C-c s c     Find functions calling a function.
C-c s C     Find called functions (list functions called from a function).
C-c s s     Find symbol.
C-c s u     Return the point from where you jumped.

# other commands
C-c s g     Find global definition (alternate binding).
C-c s G     Find global definition without prompting.
C-c s t     Find text string.
C-c s e     Find egrep pattern.
C-c s f     Find a file.
C-c s i     Find files #including a file.
C-c s a     Set initial directory which has a index file (cscope.out).

Tuesday, February 10, 2015

Ubuntu Server 14.04 Network Bonding ( a simple expedient )

Ubuntu Server 14.04 Network Bonding ( a simple expedient )

Simple Ubuntu 14.04 Bonding

Just do it as below if you want to create or delete network bonding

<1> ifdown -a –exclude=lo
<2> edit network interfaces file (/etc/network/interfaces)
<3> service networking restart
<4> Done

< Using >
1. bond-mode ‘IEEE 802.3ad’
2. ifenslave (version 2.4ubnutu1)
3. service networking (13.10)

Create bonding

1) Install ifenslave

:> sudo apt-get install ifenslave

2) Restore 13.10 networking (instead of networking 14.04)

:> git clone https://github.com/metral/restore_networking.git
:> cd restore_networking/
:> ./restore_networking.sh

3) Bring network interfaces down

:> ifdown -a --exclude=lo

4) Edit /etc/network/interfaces file

:> emacs /etc/network/interfaces

auto lo eth0 eth1 eth2
iface lo inet loopback
iface eth0 inet manual
iface eth1 inet manual # bond-slave
        bond-master bond0
iface eth2 inet manual # bond-slave
        bond-master bond0

auto bond0
iface bond0 inet static
        address 192.168.1.105
        netmask 255.255.255.0
        gateway 192.168.1.1
        dns-nameservers  8.8.8.8
        bond-mode 802.3ad
        bond-slaves none # There is no need to declare bond-slaves
        bond-xmit_hash_policy layer3+4
        bond-miimon 100
        bond-updelay 200
        bond-downdelay 200
        bond-lacp-rate 1

5) Restart service networking

:> service networking restart 

Check bonding

:> cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer3+4 (1)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 200
Down Delay (ms): 200

802.3ad info
LACP rate: fast
Min links: 0
Aggregator selection policy (ad_select): stable
Active Aggregator Info:
    Aggregator ID: 1
    Number of ports: 1
    Actor Key: 17
    Partner Key: 1
    Partner Mac Address: 00:00:00:00:00:00

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 18:bx:cc:xx:xx:xx
Aggregator ID: 1
Slave queue ID: 0

Slave Interface: eth2 # isn't used and connected with LAN (even if it ware so, no matter)
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 18:bd:23:xx:xx:xx
Aggregator ID: 2
Slave queue ID: 0

Delete bonding

1) Remove bonding (module from kernel)

:> rmmod bonding

2) Bring network interfaces down

:> ifdown -a --exclude=lo

3) Edit /etc/network/interfaces file

:> emacs /etc/network/interfaces 

auto lo eth0 eth1 eth2
iface lo inet loopback
iface eth0 inet manual
iface eth1 inet static
        address 192.168.1.105
        netmask 255.255.255.0
        gateway 192.168.1.1
        dns-nameservers 8.8.8.8
iface eth2 inet manual

4) Restart service networking

:> service networking restart

Troubleshooting

After you set or unset ‘bonding’ , if ethernet not work.

  1. Check ‘/run/network/ifstate’ file
  2. Try to do “ifdown -a –exclude=lo && ifup -a –exclude=lo”
  3. Check LAN connector & port
  4. Check “route”

1) Check /run/network/ifstate

# ifup, ifdown commands work depending on /run/network/ifstate file
# and /etc/network/interfaces file.
# So if there are network interfaces which aren't written in /run/network/ifstate 
# file, the commands cannot perfectly work. 
# /run/network/ifstate file should have all network interfaces like this 

eth0=eth0
eth1=eth1
eth2=eth2
lo=lo

2) Try to bring down & up network interfaces

:> ifdown -a --exclude=lo && ifup -a --exclude=lo 

3) Check LAN connector & port

Check or change your LAN connector and port.
# There are sufficient cases of poor LAN connetor or port.

4) Check route

:> route

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 bond0
192.168.1.0     *               255.255.255.0   U     0      0        0 bond0

# As above this shuould be printed (if you only use bond interface)
# But output of command 'route' might not be like this.
#
# 1. Even a few minutes later, if it wasn't printed
#    check your hub or switch and try to replace port.
#
# 2. Even though bond0 has correct gateway like 192.168.1.1 
#    if your ethernet is unstable, 
#    check whether there's network interface which has IP address 
#    that use same extended network prefix.

Saturday, January 10, 2015

GIT Rebase in contributing opensource.

Simply introduce GIT Rebase command comparing GIT Merge

If you've been contributing linux-perf ..
1. origin = my remote repository
2. upstream = linux-perf remote repository
3. origin/master = to follow one branch of 'upstream'

If you’ve been working in ‘origin/master’ but ‘upstream’ is updated so you need to update your remote and local repository.
If you do..
After you make yours newest, you can do as below.
(ex> ‘git fetch upstream perf/core’ )

1) git rebase

$ git fetch upstream perf/core
$ git rebase upstream/perf/core (on 'master' branch)
# Contents of your commit is added on top of the newest commit history.

Saturday, October 4, 2014

In specific directory, how to copy-on-write like snapshot.

In the general , it is the method that make hard-link
and can do copy-on-write by two ways.

<1> Make hard-link

$ cp -al one_folder hard_linked_folder

<2> Simply, there are two ways to use copy-on-write.

<2-1> cowdancer

The way demonstrate copy-on-write in only a shell session.

$ sudo apt-get install cowdancer

Invoke cow-shell and it start a shell session that will protect the i-node below the current directory.

$ cd hard_linked_folder
$ cow-shell
 # Invoking /bin/bash (it is output)

And then, if you write any files in ‘hard_linked_folder’, copy-on-write coincide with it.
If you want to finish the situation, by ‘exit’ you can quit it.

$ exit

<2-2> fl-cow

This one can do copy-on-write when a specific program write some in the folder ‘hard_linked_folder’.

$ sudo apt-get install fl-cow

This one is more easy than cowdancer.
Just run a program you want to monitor with ‘cow‘.

$ cow program
$ cow utserver # it is a example.
               # utserver is utorrent server.
               # If utserver modify some in the folder,
               # fl-cow will protect the i-node
               # to preserve original files.

You can check whether the program is run with ‘fl-cow’ or not.

$ lsof | grep cow

If you can’t see anything, run the program with ‘cow’ again.

Tuesday, September 23, 2014

How to simply send patch to linux kernel

Title2

If you simply wanna send a patch linux kernel source tree, follow the process below.

<1> Find which source tree you want to contribute in the site https://git.kernel.org
(If you want to contribute to ‘tools/perf’, recommend the branch perf/core in ‘tip’ source tree below.. )

$ git clone -b perf/core git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core

(Even though you want to find other source tree, you can’t find it.
Find in ‘MAINTAINERS’ file or ask mailing list for the sub project you want “what is the source tree and branch in it ?”.)

<2> After you modify source code, check your commit.

$ git add -A && git commit -s && git show

<3> You can make a patch file.

$ git format-patch -1

<4> Check your patch.

$ scripts/checkpatch.pl 0001-modify-something.patch

<5> Get maintainer email address to which you send your patch.

$ scripts/get_maintainer.pl 0001-modify-something.patch

<6> If there isn’t the problems, send email to maintainer and kernel mailing list.

$ git send-email --to "email@address" --cc "some@address" //format
$ git send-email --to "Arnaldo Carvalho de Melo <acme@kernel.org>"\ 
> --cc "linux-kernel@vger.kernel.org" \
> --cc "linux-perf-users@vger.kernel.org"\
> 0001-modify-something.patch