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" == "" ]; thenecho"Please enter process name"exit0fi
p_count=`ps -eo comm | grep -wc "$1"`
if [ "$p_count" == "0" ]; thenecho"Error: '$1' process don't exist"exit0fi
mem_usage=`ps -eo pmem,comm | grep -we "$1" | awk -F" "'{print $1}' | paste -sd+ | bc`
echo"$1's memory usage : $mem_usage %"exit0
<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
# 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 itC-c s a
Cscope commands on emacs
# most-usedC-c s dFind global definition.
C-c s cFind functions calling a function.
C-c s CFindcalled functions (list functions called from a function).
C-c s sFindsymbol.
C-c s uReturnthe point from where you jumped.
# other commandsC-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).
:> 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-slavebond-master bond0
iface eth2 inet manual # bond-slavebond-master bond0auto 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: IEEE802.3adDynamic link aggregation
Transmit Hash Policy: layer3+4 (1)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 200
Down Delay (ms): 200802.3adinfo
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:00Slave 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: 0Slave 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
After you set or unset ‘bonding’ , if ethernet not work.
Check ‘/run/network/ifstate’ file
Try to do “ifdown -a –exclude=lo && ifup -a –exclude=lo”
Check LAN connector & port
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
default192.168.1.10.0.0.0 UG 000 bond0
192.168.1.0 * 255.255.255.0 U 000 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.
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.
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-writewhen 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.
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 sitehttps://git.kernel.org (If you want to contribute to ‘tools/perf’, recommend the branch perf/core in ‘tip’ source tree below.. )
(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.