Advertisement
valdur55

leak-analyzer.sh

Feb 8th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.65 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. pid=$(pgrep -f mon.py)
  4. reader='Hewlett-Packard Company HP USB Smart Card Keyboard'
  5. logfile='/home/valdur55/0-mem-minimal-leak.log'
  6. tmpfolder='/tmp/minimal-leak'
  7.  
  8. function readmem(){
  9.     grep rw-p /proc/$1/maps  | sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p' | while read start stop; do gdb --batch --pid $1 -ex "dump memory $tmpfolder/$1-$start-$stop.dump 0x$start 0x$stop"; done
  10. }
  11.  
  12. function analyze(){
  13.     for f in /tmp/minimal-leak/*.dump ; do count=$(strings $f| grep $1 -c) ; echo "$f ; $count" | grep -v " ; 0" >> $logfile ; done;
  14.  
  15. }
  16.  
  17. mkdir -p $tmpfolder
  18. date >> $logfile
  19. readmem $pid
  20. analyze $reader
  21.  
  22. rm $tmpfolder/*.dump
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement