Tuesday, August 25, 2015

operf / oprofile on fedora 21



Using iperf as code to profile
sudo yum install iperf
sudo debuginfo-install iperf

Install oprofile
sudo yum install oprofile

Profile particular pid

[steve@steve-GA-880GMA-UD2H operf]$ pgrep iperf
2807
[steve@steve-GA-880GMA-UD2H operf]$ operf --pid 2807
operf: Press Ctl-c or 'kill -SIGINT 3924' to stop profiling
operf: Profiler started
^C
Profiling done.


[steve@steve-GA-880GMA-UD2H operf]$ opreport -l -dg  |less
CPU: AMD64 family10, speed 3200 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Cycles outside of halt state) with a unit mask of 0x00 (No unit mask) count 100000
vma      samples  %        linenr info                 image name               symbol name
00408700 261      30.9242  Reporter.c:710              iperf                    reporter_handle_packet
...
  004089af 121      46.3602  Reporter.c:814

[steve@steve-GA-880GMA-UD2H operf]$ opannotate --source |less
 * Total samples for file : "/usr/src/debug/iperf-2.0.8/src/Reporter.c"
 * 
 *    402 47.6303
...
    809             } else if (reporthdr->report.mThreadMode == kMode_Server && (packet->packetLen > 0)) {
    810                 int bin;
    811                 // mean min max tests
    812                 stats->tcp.read.cntRead++;
    813                 stats->tcp.read.totcntRead++;
    814                 bin = (int)floor((packet->packetLen -1)/stats->tcp.read.binsize);
    815                 stats->tcp.read.bins[bin]++;
    816                 stats->tcp.read.totbins[bin]++;
    817             } else if (reporthdr->report.mThreadMode == kMode_Client) {


Profile system wide

[steve@steve-GA-880GMA-UD2H operf]$ sudo operf -s
operf: Press Ctl-c or 'kill -SIGINT 4003' to stop profiling
operf: Profiler started
^C* * * * WARNING: Profiling rate was throttled back by the kernel * * * *
The number of samples actually recorded is less than expected, but is
probably still statistically valid.  Decreasing the sampling rate is the
best option if you want to avoid throttling.

Profiling done.


[steve@steve-GA-880GMA-UD2H operf]$ opreport  |less

CPU: AMD64 family10, speed 3200 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Cycles outside of halt state) with a unit mask of 0x00 (No unit mask) count 100000
CPU_CLK_UNHALT...|
  samples|      %|
------------------
   298879 83.0667 iperf
        CPU_CLK_UNHALT...|
          samples|      %|
        ------------------
           286580 95.8850 kallsyms
             6738  2.2544 nf_conntrack
             1279  0.4279 nf_nat_ipv4
              742  0.2483 libpthread-2.20.so
              740  0.2476 nf_conntrack_ipv4
              667  0.2232 iptable_mangle
              634  0.2121 iperf
              533  0.1783 [vdso] (tgid:2807 range:0x7fffd53fc000-0x7fffd53fdfff)

[steve@steve-GA-880GMA-UD2H operf]$ opreport -l -d -g /usr/bin/iperf -f |less
...
004092e0 293       0.0980  /usr/src/debug/iperf-2.0.8/src/Server.cpp:104 /usr/bin/iperf           Server::Run()
  004093d2 2         0.6826  /usr/src/debug/iperf-2.0.8/src/Server.cpp:182
  004093d9 5         1.7065  /usr/src/debug/iperf-2.0.8/src/Server.cpp:179
  004093ec 121      41.2969  /usr/src/debug/iperf-2.0.8/src/Server.cpp:182
  004093f5 2         0.6826  /usr/src/debug/iperf-2.0.8/src/Server.cpp:201
  00409416 12        4.0956  /usr/src/debug/iperf-2.0.8/src/Server.cpp:243
  0040941c 7         2.3891  /usr/src/debug/iperf-2.0.8/src/Server.cpp:244
  00409427 2         0.6826  /usr/src/debug/iperf-2.0.8/src/Server.cpp:248
  00409443 19        6.4846  /usr/src/debug/iperf-2.0.8/src/Server.cpp:178
  00409446 11        3.7543  /usr/src/debug/iperf-2.0.8/src/Server.cpp:178
  00409510 3         1.0239  /usr/src/debug/iperf-2.0.8/src/Server.cpp:259
  00409512 12        4.0956  /usr/src/debug/iperf-2.0.8/src/Server.cpp:259
  00409521 4         1.3652  /usr/src/debug/iperf-2.0.8/src/Server.cpp:260
  0040952d 1         0.3413  /usr/src/debug/iperf-2.0.8/src/Server.cpp:260
  00409538 4         1.3652  /usr/src/debug/iperf-2.0.8/src/Server.cpp:260
  0040953b 14        4.7782  /usr/src/debug/iperf-2.0.8/src/Server.cpp:201
  00409541 19        6.4846  /usr/src/debug/iperf-2.0.8/src/Server.cpp:201
  0040954a 4         1.3652  /usr/src/debug/iperf-2.0.8/src/Server.cpp:201
  004095bb 27        9.2150  /usr/src/debug/iperf-2.0.8/src/Server.cpp:242
  004095c4 24        8.1911  /usr/src/debug/iperf-2.0.8/src/Server.cpp:242

vi /usr/src/debug/iperf-2.0.8/src/Server.cpp
    177         gettimeofday( &watchdog, NULL );
    178         do {
    179             reportstruct->emptyreport=0;
    180 #if HAVE_DECL_SO_TIMESTAMP
    181             // perform read
    182             currLen = recvmsg( mSettings->mSock, &message, 0 );
    183             if (currLen <= 0) {
    184                 // Socket read timeout or read error
    185                 reportstruct->emptyreport=1;
    186                 gettimeofday( &(reportstruct->packetTime), NULL );


[steve@steve-GA-880GMA-UD2H operf]$ opannotate --source |less
...
/* 
 * Total samples for file : "/usr/src/debug/iperf-2.0.8/src/Server.cpp"
 * 
 *    293  0.0814
 */
...
    30  0.0083 :        do {
     5  0.0014 :            reportstruct->emptyreport=0;
               :#if HAVE_DECL_SO_TIMESTAMP
               :            // perform read 
   123  0.0342 :            currLen = recvmsg( mSettings->mSock, &message, 0 );
               :            if (currLen <= 0) {
               :                // Socket read timeout or read error
               :                reportstruct->emptyreport=1;
               :                gettimeofday( &(reportstruct->packetTime), NULL );




Sunday, January 5, 2014

Android development - Fedora 20 and Nexus 7

On Nexus 7

Follow this post to enable USB debugging on the Nexus 7

If you do not see "Developer Options", go into "About device" in Settings and tap on the "Build number" entry seven times, which will unlock "Developer Options".

Then, to get the ADB to recognize the device -

[steve@localhost ~]$ sudo Development/adt-bundle-linux-x86-20131030/sdk/platform-tools/adb devices
List of devices attached
????????????    no permissions


Following this post -

[steve@localhost ~]$ lsusb |grep Nexus
Bus 002 Device 014: ID 18d1:4e42 Google Inc. Nexus 7 (debug)


Edit as below -

[steve@localhost ~]$ cat /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"

[steve@localhost ~]$ sudo chmod a+r /etc/udev/rules.d/51-android.rules
 
Restart udev and adb server -
 
[steve@localhost ~]$ sudo systemctl restart systemd-udevd.service
[steve@localhost ~]$ sudo Development/adt-bundle-linux-x86-20131030/sdk/platform-tools/adb kill-server
 
[steve@localhost ~]$ sudo Development/adt-bundle-linux-x86-20131030/sdk/platform-tools/adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached 
015d3f18d1281012 unauthorized

Authorize the PC on the device, and re-check -

[steve@localhost ~]$ sudo Development/adt-bundle-linux-x86-20131030/sdk/platform-tools/adb devices
List of devices attached 
015d3f18d1281012 device

Monday, December 30, 2013

Compiling qemu on ubuntu 12.04

I hit a seemingly common issue running configure

ERROR: glib-2.12 required to compile QEMU

I tried the usual suspects -

~/qemu-1.7.0$ sudo apt-get install libglib2.0-dev
Reading package lists... Done
Building dependency tree    
Reading state information... Done
libglib2.0-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 72 not upgraded.

to no avail...
After poking through the configure script, I suspected a pkg-config issue.
The export below resolved my issue -

export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig

Monday, September 23, 2013

Headless install of Fedora 19

I need to do a headless install of fedora at work, and want to test the process at home first.
Approach is, use kvm/qemu on my ubuntu machine, and install fedora as a guest

virt-install \

 --name=guest1-fedora19-64 \
 --disk /var/lib/libvirt/images/guest1-fedora19-64.img,size=10 \
 --graphics none \
 --vcpus=1 --ram=2048 \
 --location=/home/steve/Downloads/Fedora-19-x86_64-DVD.iso \
 --network bridge=virbr0 \
 --os-type=linux \
 --os-variant=fedora16 \
 --extra-args="console=ttyS0,115200"


This works well, and anaconda gives me the choice of vnc or text based install

Trying text first -

Worked very smoothly.
After install, added tigervncserver, configured for lxde, disabled firewall, and was able to connect with vncviewer.


Reconnect after restart -

root@steve-GA-880GMA-UD2H:~# virsh list --inactive Id Name State ---------------------------------- - guest1-fedora19-64 shut off root@steve-GA-880GMA-UD2H:~# virsh start guest1-fedora19-64 Domain guest1-fedora19-64 started

root@steve-GA-880GMA-UD2H:~# virsh console guest1-fedora19-64
Connected to domain guest1-fedora19-64 Escape character is ^] [ 0.535212] 00:04: ttyS Fedora release 19 (Schrödinger’s Cat) Kernel 3.9.5-301.fc19.x86_64 on an x86_64 (ttyS0) localhost login:



Then vnc via anaconda

Network was configured automatically
vnc worked fine

and vnc via qemu/kvm

apt-get install virt-viewer

virt-install \

 --name=guest2-fedora19-64 \
 --disk /var/lib/libvirt/images/guest2-fedora19-64.img,size=10 \
 --graphics vnc \
 --vcpus=1 --ram=2048 \
 --location=/home/steve/Downloads/Fedora-19-x86_64-DVD.iso \
 --network bridge=virbr0 \
 --os-type=linux \
 --os-variant=fedora16

Also went smoothly.



UEFI & GPT

The real hardware had some UEFI support, and this led to some extra issues. Enough for another post, later...

Thursday, September 5, 2013

Migrating to grub2

Well, this was also relatively painless. Following the instructions from the FedUp page -

grub2-install /dev/sda
grub2-mkconfig -o /boot/grub2/grub.cfg

Got me a working grub2 system - however, my poor man's install option was lost.
This I corrected as below, adding it's entry in the file below

[steve@aspireone753 ~]$ sudo cat /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

menuentry Fedora-17-x86_64-Live-Desktop {
  set root=(hd0,msdos8)
  linux /isolinux/vmlinuz0 root=UUID=B381-1423 rootfstype=auto rw liveimg quiet  rhgb
  initrd /isolinux/initrd0.img
}

and then re-running 
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

There were some syntax changes from how it was in grub.conf ->

title Fedora-17-x86_64-Live-Desktop.is
  root (hd0,7)
  kernel /isolinux/vmlinuz0 root=UUID=B381-1423 rootfstype=auto rw liveimg quiet  rhgb
  initrd /isolinux/initrd0.img

Note especially the change in partition numbering.

Friday, August 30, 2013

Upgrade Fedora 17 to 19 using FedUp

Whilst a fairly time consuming process, it went very smoothly. The only minor issue I encountered was Chrome not working, but this and a simple solution was documented on the FedUp page.

Dare I tackle a grub update?

Also worth noting... my issue with

rfkill: WLAN soft blocked

occurring randomly some minutes after boot, although not solved... I seem to have found a remedy.
After installing the rfkill util, I'm able to re-enable via the command

rfkill unblock WLAN

Wednesday, October 3, 2012

DNS-323 based home security camera

Quite some time ago, I bought a wireless IP camera from Amazon UK, intending to set it up at home as a DIY security camera. Whilst it was great value for money, the web based user interface was quite limited and basically I wasn't able to do what I wanted.

After some googling, I found out about 'motion', motion detection software, seemingly designed for the job. I figured if I could run 'motion' on my DNS-323, I could make a workable solution.

EasyN FS-613A-M136 Wireless Pan & Tilt IP Camera
Motion

Recently I got around to trying it, and am pleased with the results so far, his how I did it -

Download and install development tools (thanks fonz) necessary to build motion using -

wget http://www.inreto.de/dns323/fun-plug/0.7/oabi/packages/
funpkg -i

for each of the packages below -

autoconf-2.68-oarm-2.txz
automake-1.11.3-oarm-1.txz
binutils-2.22-oarm-3.txz
gcc-4.5_20120202-oarm-1.txz
gcc-solibs-4.5_20120202-oarm-1.txz
libjpeg-8c-oarm-2.txz
linux-libc-headers-2.6.12.0-oarm-2.txz
make-3.81-oarm-2.txz
mpfr-3.1.0-oarm-2.txz
uClibc-0.9.30.3-oarm-1.txz
uClibc-solibs-0.9.30.3-oarm-1.txz

Download motion source, configure, and make -

motion-3.2.12.tar.gz
./configure --without-v4l
make

A small patch afterwards, to get it to link properly -

gcc  -o motion motion.o conf.o draw.o jpegutils.o video.o video2.o video_common.o netcam.o netcam_ftp.o netcam_jpeg.o netcam_wget.o track.o alg.o event.o picture.o rotate.o webhttpd.o webcam.o  -lm  -ljpeg -lpthread

root@dlink-EEF76A:/mnt/HD_b2/tmp/motion-3.2.12# cat motion.conf 
netcam_url http://192.168.0.111:81/videostream.cgi?showlength=1
netcam_userpass admin:password
locate on

framerate 2

And voila -


root@dlink-EEF76A:/mnt/HD_b2/tmp/motion-3.2.12# ./motion -c motion.conf 
[0] Processing thread 0 - config file motion.conf
[0] Motion 3.2.12 Started
[0] Thread 1 is from motion.conf
[1] Thread 1 started
[1] Resizing pre_capture buffer to 1 items


Works nicely!