an3l / my_playground

My playground with python, nginx, docker and server!
0 stars 0 forks source link

PR 215: MDEV - 4476 mytop tracker analysis #11

Open an3l opened 5 years ago

an3l commented 5 years ago

Installing prerequisites and getting started with mytop:

Problem with Term::ReadKey.pm perl module:

anel@ubuntu:~/workspace/mariadb/mariadb-server-10.2$ ./scripts/mytop 
Can't locate Term/ReadKey.pm in @INC (you may need to install the Term::ReadKey module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at ./scripts/mytop line 191.

Install it via CPAN.

Note: there is a link: http://search.cpan.org/search?dist=TermReadKey (scripts/mytop.sh:1887) which should be updated to https://metacpan.org/search?q=dist%3ATermReadKey First configure cpan:

$ sudo perl -MCPAN -e shell
[sudo] password for anel: 
Sorry, we have to rerun the configuration dialog for CPAN.pm due to
some missing parameters. Configuration will be written to
 <</home/anel/.local/share/.cpan/CPAN/MyConfig.pm>>

CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.

Would you like to configure as much as possible automatically? [yes] yes

Autoconfiguration complete.

commit: wrote '/home/anel/.local/share/.cpan/CPAN/MyConfig.pm'

You can re-run configuration any time with 'o conf init' in the CPAN shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v2.18)
Enter 'h' for help.

Install Term::ReadKey:

cpan[1]> install Term::ReadKey 

Problem with DBD::mysql perl module

anel@ubuntu:~/workspace/mariadb/mariadb-server-10.2$ ./scripts/mytop
install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (you may need to install the DBD::mysql module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at (eval 14) line 3.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: DBM, ExampleP, File, Gofer, Mem, Proxy, Sponge.
 at ./scripts/mytop line 254.

Install it:

cpan[1]> install DBD::mysql
Reading '/home/anel/.local/share/.cpan/Metadata'
  Database was generated on Thu, 05 Sep 2019 08:55:18 GMT
Running install for module 'DBD::mysql'
...
Appending installation info to /usr/local/lib/x86_64-linux-gnu/perl/5.26.1/perllocal.pod
  DVEEDEN/DBD-mysql-4.050.tar.gz
  /usr/bin/make install  -- OK

Test again mytop:

$ ./scripts/mytop
Cannot connect to MariaDB server. Please check the:

  * database you specified "test" (default is "test")
  * username you specified "root" (default is "root")
  * password you specified "" (default is "")
  * hostname you specified "localhost" (default is "localhost")
  * port you specified "3306" (default is 3306)
  * socket you specified "" (default is "")

The options my be specified on the command-line or in a ~/.mytop
config file. See the manual (perldoc mytop) for details.

Here's the exact error from DBI. It might help you debug:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Start mysqld, specify the socket on /tmp/mysql.sock:

$ ./scripts/mytop --socket="/tmp/mysql.sock"

MariaDB on localhost (10.2.27-MariaDB-debug)                                                                                                                                                                                                         up 0+00:02:11 [05:15:55]
 Queries: 186.0   qps:    1 Slow:     0.0         Se/In/Up/De(%):    02/00/00/00
 Sorts:     0 qps now:    1 Slow qps: 0.0  Threads:    2 (   1/   0) 00/00/00/00
 Handler: (R/W/U/D)     0/    0/    0/    0        Tmp: R/W/U:    93/   93/    0
 ISAM Key Efficiency: 100.0%  Bps in/out:  38.3/ 3.6k   Now in/out:  22.7/ 3.1k

       Id     User         Host/IP        DB   Time     %    Cmd           State Query
       --     ----         -------        --   ----     -    ---           ----- ----------
        9     anel       localhost informati     24   0.0  Sleep                                                                                                                                                                                                                 
        2 system u                                0   0.0 Daemon InnoDB purge wo                                                                                                                                                                                                 
        1 system u                                0   0.0 Daemon InnoDB purge co                                                                                                                                                                                                 
        3 system u                                0   0.0 Daemon InnoDB purge wo                                                                                                                                                                                                 
        4 system u                                0   0.0 Daemon InnoDB purge wo                                                                                                                                                                                                 
        5 system u                                0   0.0 Daemon InnoDB shutdown                                                                                                                                                                                                 
        8     root       localhost      test      0   0.0  Query            init show full processlist  

Run client/mysql and see the output in mytop.

Task is to check the PR 215 and verify changes!!!

an3l commented 5 years ago

Perlpod Special variables in perl $0->get the name of program being run, diamond operator - similar to cat perlvar perl -X For debugging trepan: install Devel::Trepan and use it like perl -d:Trepan

$ perl -d:Trepan ./scripts/mytop.sh --socket="/tmp/mysql.sock"
-- main::(./scripts/mytop.sh:23 @0x558f738f4b38)
$main::VERSION = "1.91a";
(trepanpl): n                                                                                                                                                                                                                                                                             
-- main::(./scripts/mytop.sh:24 @0x558f73a641b0)
my $path_for_script= dirname($0);
(trepanpl): p $path_for_script                                                                                                                                                                                                                                                            
$DB::D[0] = <undef>
(trepanpl): n                                                                                                                                                                                                                                                                             
-- main::(./scripts/mytop.sh:26 @0x558f73a64000)
$|=1;
(trepanpl): p $path_for_script                                                                                                                                                                                                                                                            
"./scripts"
$DB::D[0] = ./scripts
(trepanpl):      

Note: my_which sub parameter @_ as only argument which can be passed to function can be changed to $_[0], or to use shift. Also there should be default value to handle shift // $SOME_DEFAULT;

Patches and analysis: 1. Monty Added mytop to distribution 2. Feature request - prevent truncating query in mytop 3. Updated mytop to 1.91 4. Change mysql->mariadb 5. Serg MDEV 286 mytop not installed 6. Serg MDEV-3952 Incompatible change in rpm 7. bugs in debian mytop can't be installed 1.9.1-4 8. bugs in debian ansi_quotes 1.9.1-4 9. only source Jeremy z 10. Database independent interface DBI 11. Perl buffering $| 12. more about regexep 13. regexp cheatsheat 14. regexep operators

an3l commented 5 years ago

setpriority(2)which,who,prio has value from -20(highest) : 19(lowest); 0(default), setting the priority use nice(1)

my @variables = Hashes("show variables"); # Hashes() ? not known yet (trepanpl): p @variables
[ [0] { Value 8192, Variable_name "aria_block_size" }, [1] { Value 30, Variable_name "aria_checkpoint_interval"


- [ReadMode terminal](https://metacpan.org/pod/Term::ReadKey) - used `cbreak 3` and `restore 0`
- Line 785: suggest using `cls`.
- I would refactor 922 `open L, "</proc/loadavg"` with newer style `open (my $fh, "<", "/proc/loadavg") or die "Can't open /proc/loadavg \n";` - using bareword (L) old stylish as stated [here](https://perldoc.perl.org/functions/open.html) and [example 1](https://stackoverflow.com/questions/29731665/whats-the-l-in-open-l-logfile), [barewords in diamond operator](https://stackoverflow.com/questions/28208970/why-cant-i-use-a-typeglob-in-the-diamond-operator-in-perl)
- 1182: not needed
- $key = t or u (username based filter) and case key=~ /t/i ; cmd_s/S () ?
an3l commented 4 years ago
$ perl -MDBI -e 'DBI->installed_versions'
  Perl            : 5.026001    (x86_64-linux-gnu-thread-multi)
  OS              : linux   (4.9.0)
  DBI             : 1.64
  DBD::mysql      : 4.050
  DBD::Sponge     : 12.010003
  DBD::Proxy      : install_driver(Proxy) failed: Can't locate RPC/PlClient.pm in @INC (you may need to install the RPC::PlClient module)
  DBD::Mem        : 0.001
  DBD::MariaDB    : 1.21
  DBD::Gofer      : 0.015327
  DBD::File       : 0.44
  DBD::ExampleP   : 12.014311
  DBD::DBM        : 0.08
#Uninstall DBD::MariadDB and DBD::mysql
$ sudo apt install libcpanplus-perl # install cpanplus (perl 5.10)

Uninstalling the module is quite weird https://stackoverflow.com/questions/7777252/uninstall-all-perl-modules-installed-by-cpan

perldoc perllocal # all modules installed
cpanp uninstall DBD::MariaDB; #uninstalling with cpanplus (didn't work)
perldoc perllocal # again showing MariaDB?
#Changing the location of MariaDB.pm file for proper simulating of uninstallation
$ perldoc -l DBD::MariaDB
/usr/local/lib/x86_64-linux-gnu/perl/5.26.1/DBD/MariaDB.pod

$ sudo umount /var/run/mysqld/mysqld.sock
# start mysqld
$ sudo mount --bind /tmp/mysql.sock /var/run/mysqld/mysqld.sock

$ perl -d ./scripts/mytop -S="/tmp/mysql.sock"  --user=anel
  DB<1> w $dsn
  DB<2> r
Watchpoint 0:   $dsn changed:
    old value:  ''
    new value:  'DBI:mysql:database=;mysql_read_default_group=mytop;'
main::(./scripts/mytop:263):    if ($config{socket} and -S $config{socket})
main::(./scripts/mytop:264):    {
MariaDB 10.5.5 on localhost                                                                                                                                                                         load (0.02 0.10 0.15) up 0+00:08:43 [08:31:05]
 Queries: 60.0     qps:    0 Slow:     0.0         Se/In/Up/De(%):    33/00/00/00
 Sorts:      0 qps now:    1 Slow qps: 0.0  Threads:    2 (   1/   0) 25/00/00/00
 Handler: (R/W/U/D)     0/    0/    0/    0        Tmp: R/W/U:   109/  109/    0
 MyISAM Key Cache Efficiency: 100.0%  Bps in/out:  14.2/451.2   Now in/out:  98.0/ 3.7k

       Id     User         Host/IP        DB   Time     %    Cmd           State Query
       --     ----         -------        --   ----     -    ---           ----- ----------
        6     anel       localhost      test    7.8   0.0  Sleep  

Links: https://metacpan.org/pod/DBI#Notation-and-Conventions https://metacpan.org/pod/DBD::mysql https://metacpan.org/pod/DBD::MariaDB # not referencing install_driver() https://metacpan.org/pod/DBI # purly explained method https://home.ubalt.edu/abento/752/dbi/indexwindows.html