xuchuanyin / workbench

0 stars 0 forks source link

2019-01-11 android nmon #83

Open xuchuanyin opened 5 years ago

xuchuanyin commented 5 years ago

push binary into device

On non-rooted device you can push the binary to /data/local/tmp

adb shell push nmon /data/local/tmp/

set executable permission

adb shell chmod 555 /data/local/tmp/nmon

run

Now you can shell into your device (with adb shell) and execute the command.

cd /data/local/tmp
// if we specify the output folder, it will complain 'changing directory failed'
./nmon -f -t -r test -s 2 -c 200 -m .

adb pull /data/local/tmp/localhost_190111_1715.nmon ./

xuchuanyin commented 5 years ago

install ndk and toochain

install ndk

We use the ndk that downloaded by the AndroidStudio, it lies in /home/xcy/Android/Sdk/ndk-bundle.

install toolchain

this can refer to the Android general documentation(https://developer.android.com/ndk/guides/standalone_toolchain).


/home/xcy/Android/Sdk/ndk-bundle/build/tools/make_standalone_toolchain.py  arm --api 28 --install-dir /home/xcy/Android/Sdk/my-android-toolchain

Add it to env


export TOOL_CHAIN=/home/xcy/Android/Sdk/my-android-toolchain
export PATH=$PATH:$TOOL_CHAIN/bin

use toolchain to build c program and verify it on your Android device

suppose we have a simple helloworld program written in main.c


xcy@uxcy:~/Android/Sdk/my-android-toolchain/bin$ ./arm-linux-androideabi-gcc -static ~/ws/nmon/ctest/main.c -o main

Then push the program main to your Android device and run it to verify.

build our own ncurses

since build nmon will encounter ncurses related problem (header not found), we need to build our own ncurses.

build ncurses to '/home/xcy/ws/nmon/my-ncurses'

ncurses is collection of escape sequence and library of terminal manipulation. To build, apply patch first.

./configure --prefix /home/xcy/ws/nmon/my-ncurses --host arm-linux-androideabi make && install

Note: Here I use ncurses 6.0 (or maybe 5.9...).

some files

copy fstab.h from /home/xcy/Android/aosp/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/sysroot/usr/include/fstab.h and modify it like below (.bk is the original file):


--- fstab.h.bk    2019-01-09 16:03:24.241265901 +0800
+++ fstab.h    2019-01-09 16:05:11.437186080 +0800
@@ -68,11 +68,16 @@

 __BEGIN_DECLS

-extern struct fstab *getfsent (void) __THROW;
-extern struct fstab *getfsspec (__const char *__name) __THROW;
-extern struct fstab *getfsfile (__const char *__name) __THROW;
-extern int setfsent (void) __THROW;
-extern void endfsent (void) __THROW;
+// extern struct fstab *getfsent (void) __THROW;
+// extern struct fstab *getfsspec (__const char *__name) __THROW;
+// extern struct fstab *getfsfile (__const char *__name) __THROW;
+// extern int setfsent (void) __THROW;
+// extern void endfsent (void) __THROW;
+extern struct fstab *getfsent (void) ;
+extern struct fstab *getfsspec (__const char *__name) ;
+extern struct fstab *getfsfile (__const char *__name) ;
+extern int setfsent (void) ;
+extern void endfsent (void) ;

 __END_DECLS

copy ncurses.h from /home/xcy/ws/nmon/my-ncurses/include/ncurses


xcy@uxcy:~/ws/nmon$ ls -lh /home/xcy/ws/nmon/includes
total 88K
-rw-rw-r-- 1 xcy xcy  3340 Jan  9 16:05 fstab.h
-rw-rw-r-- 1 xcy xcy  3115 Jan  9 16:03 fstab.h.bk
-rw-r--r-- 1 xcy xcy 78739 Jan 10 11:36 ncurses.h

xcy@uxcy:~/ws/nmon$ ls -l /home/xcy/ws/nmon/my-ncurses/include/ncurses/
total 348
-rw-r--r-- 1 xcy xcy  6783 Jan  9 17:01 cursesapp.h
-rw-r--r-- 1 xcy xcy 27865 Jan  9 17:01 cursesf.h
-rw-r--r-- 1 xcy xcy 78739 Jan  9 17:01 curses.h
-rw-r--r-- 1 xcy xcy 19709 Jan  9 17:01 cursesm.h
-rw-r--r-- 1 xcy xcy  8617 Jan  9 17:01 cursesp.h
-rw-r--r-- 1 xcy xcy 49546 Jan  9 17:01 cursesw.h
-rw-r--r-- 1 xcy xcy  7312 Jan  9 17:01 cursslk.h
-rw-r--r-- 1 xcy xcy  2891 Jan  9 17:01 eti.h
-rw-r--r-- 1 xcy xcy  9272 Jan  9 17:01 etip.h
-rw-r--r-- 1 xcy xcy 18188 Jan  9 17:01 form.h
-rw-r--r-- 1 xcy xcy 11966 Jan  9 17:01 menu.h
-rw-r--r-- 1 xcy xcy  4151 Jan  9 17:01 nc_tparm.h
-rw-r--r-- 1 xcy xcy  4277 Jan  9 17:01 ncurses_dll.h
lrwxrwxrwx 1 xcy xcy     8 Jan  9 17:01 ncurses.h -> curses.h
-rw-r--r-- 1 xcy xcy  4070 Jan  9 17:01 panel.h
-rw-r--r-- 1 xcy xcy  3478 Jan  9 17:01 termcap.h
-rw-r--r-- 1 xcy xcy  8127 Jan  9 17:01 term_entry.h
-rw-r--r-- 1 xcy xcy 39749 Jan  9 17:01 term.h
-rw-r--r-- 1 xcy xcy 12658 Jan  9 17:01 tic.h
-rw-r--r-- 1 xcy xcy  3107 Jan  9 17:01 unctrl.h

xcy@uxcy:~/ws/nmon$ ls -l /home/xcy/ws/nmon/my-ncurses/lib
total 5364
-rw-r--r-- 1 xcy xcy  115142 Jan  9 17:01 libform.a
-rw-r--r-- 1 xcy xcy  645904 Jan  9 17:01 libform_g.a
-rw-r--r-- 1 xcy xcy   52542 Jan  9 17:01 libmenu.a
-rw-r--r-- 1 xcy xcy  326636 Jan  9 17:01 libmenu_g.a
-rw-r--r-- 1 xcy xcy  570468 Jan  9 17:01 libncurses.a
-rw-r--r-- 1 xcy xcy  124532 Jan  9 17:01 libncurses++.a
-rw-r--r-- 1 xcy xcy 2910580 Jan  9 17:01 libncurses_g.a
-rw-r--r-- 1 xcy xcy  457820 Jan  9 17:01 libncurses++_g.a
-rw-r--r-- 1 xcy xcy   22618 Jan  9 17:01 libpanel.a
-rw-r--r-- 1 xcy xcy  247856 Jan  9 17:01 libpanel_g.a
lrwxrwxrwx 1 xcy xcy      17 Jan  9 17:01 terminfo -> ../share/terminfo

final command

modify nmon.c

modify the nmon source file since I get only small portion of the nmon data, just for your reference as below (_mod.c is the file after modified):


--- lmon16h.c    2019-01-08 11:33:46.633430307 +0800
+++ lmon16h_mod.c    2019-01-11 14:31:38.627088421 +0800
@@ -4785,7 +4785,6 @@
         fprintf(fp,
             "AAA,note2, The T0001-T9999 column is a snapshot number. To work out the actual time; see the ZZZ section at the end\n");
     }
-    fflush(NULL);

     for (i = 1; i <= cpus; i++)
         fprintf(fp,
@@ -4890,7 +4889,8 @@

     fprintf(fp, "\n");
     list_dgroup(p->dk);
-    if(show_jfs) {
+
+    if(false && show_jfs) {
             jfs_load(LOAD);
             fprintf(fp, "JFSFILE,JFS Filespace %%Used %s", hostname);
             for (k = 0; k < jfses; k++) {
@@ -4905,6 +4905,9 @@
         fprintf(fp, "\n");
         jfs_load(UNLOAD);
     }
+
+    fflush(NULL);
+
 #ifdef POWER
     if (proc_lparcfg() && lparcfg.shared_processor_mode != 0
         && power_vm_type == VM_POWERVM) {

compile

arm-linux-androideabi-gcc -I/home/xcy/ws/nmon/my-ncurses/include -I/home/xcy/ws/nmon/includes -o nmon /home/xcy/ws/nmon/lmon16h_mod.c -g -O2 -D GETUSER -Wall -DLARGEMEM -DARM -g -L/home/xcy/ws/nmon/my-ncurses/lib -lncurses

verify

push the nmon program to your Android device and run. Notice that nmon cannot start terminal window so we can only collect the nmon data to file and then check that file for correctness.