Open an3l opened 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
setpriority(2)
which,who,prio has value from -20(highest) : 19(lowest); 0(default)
, setting the priority use nice(1)
~/.mytop
to get configurationuse vars qw($opt_foo);
??? it is obsolete anyway !
(--verbose and --noverbose
), see Getopt::Long
(trepanpl): p $dsn # no scoket
"DBI:mysql:database=test;mysql_read_default_group=mytop;host=localhost;port=3306"
p $dsn # with socket
"DBI:mysql:database=test;mysql_read_default_group=mytop;mysql_socket=/tmp/mysql.sock"
# db handle
my $dbh = DBI->connect($dsn, $config{user}, $config{pass},
{ PrintError => 0 });
p $dbh
DBI::db {
Parents DBI::common
public methods (37) : begin_work, clone, column_info, commit, connected, data_sources, disconnect, do, foreign_key_info, get_info, last_insert_id, mysql_async_ready, mysql_async_result, mysql_fd, ping, prepare, prepare_cached, preparse, primary_key, primary_key_info, quote, quote_identifier, rollback, rows, selectall_array, selectall_arrayref, selectall_hashref, selectcol_arrayref, selectrow_array, selectrow_arrayref, selectrow_hashref, statistics_info, table_info, tables, take_imp_data, type_info, type_info_all
private methods (0)
internals: {} (tied to DBI::db)
}
$DB::D[8] = DBI::db=HASH(0x556cfeef43a8)
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 () ?
$ 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
Installing prerequisites and getting started with mytop:
Problem with Term::ReadKey.pm perl module:
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:
Install Term::ReadKey:
Problem with DBD::mysql perl module
Install it:
Test again mytop:
Start
mysqld
, specify the socket on /tmp/mysql.sock:Run client/mysql and see the output in mytop.
Task is to check the PR 215 and verify changes!!!