Back to home page

Project CMSSW displayed by LXR

 
 

    


Warning, /Utilities/ReleaseScripts/scripts/cmssmap is written in an unsupported language. File is not indexed.

0001 #!/usr/bin/env perl 
0002 #
0003 #
0004 # Script to present, in a simpler format, the smap numbers for a given
0005 # from /proc/<pid>/smaps. The script is run as:
0006 #
0007 # cmssmap <pid>
0008 #
0009 # where <pid> is the unix process id of the process to examine.
0010 #
0011 # Peter Elmer, Princeton University                       13 July, 2008
0012 #
0013 #############################################################################
0014 
0015   #
0016   # Options
0017   #
0018   use Getopt::Long;
0019   my $brieffmt;
0020   my $unused;
0021   my $noheader;
0022   GetOptions("brief|b" => \$brieffmt,
0023              "noheader|n" => \$noheader,
0024              "unused|u" => \$unused);
0025 
0026   #
0027   # Find the appropriate file in /proc
0028   #
0029   $thepid = shift; chomp($thepid);
0030   # (Should check that a pid was provided)
0031   $procsmaps = "/proc/".$thepid."/smaps";
0032   # (Should check that the file exists)
0033  
0034   #
0035   # Get SCRAM runtime envvars in order to simply printout
0036   #
0037   $baserel = $ENV{CMSSW_BASE};
0038   $testrel = $ENV{CMSSW_RELEASE_BASE};
0039   $scramarch = $ENV{SCRAM_ARCH};
0040   $cmspath = $ENV{CMS_PATH};
0041   $baselibdir = $baserel."/lib/".$scramarch."/";
0042   $testlibdir = $testrel."/lib/".$scramarch."/";
0043   $basebindir = $baserel."/bin/".$scramarch."/";
0044   $testbindir = $testrel."/bin/".$scramarch."/";
0045  
0046   #
0047   # Parse the smaps file and print
0048   #
0049   open(PROCSMAPS,"$procsmaps");
0050   if ($unused && !$noheader) {
0051     printf("%8s  %8s  %8s  %s\n", "SIZE", "RSS", "UNUSED", "NAME");
0052   } else {
0053     printf("%8s  %8s  %s\n", "SIZE", "RSS", "NAME");
0054   }
0055   while ($line = <PROCSMAPS>) {
0056     ($a1,$a2,$a3,$a4,$a5,$thelib) = split(' ',$line);
0057     if ($brieffmt) {  # Shorten the library paths
0058       # Remove the directory structure for CMSSW and externals for simplicity
0059       $thelib =~ s/$baselibdir//g;
0060       $thelib =~ s/$testlibdir//g;
0061       $thelib =~ s/$basebindir//g;
0062       $thelib =~ s/$testbindir//g;
0063       # These two should be last. There are two to deal with the non-standard
0064       # structure of the SW area at CERN.
0065       $thelib =~ s/$cmspath\/sw\/$scramarch\///g;
0066       $thelib =~ s/$cmspath\/$scramarch\///g;
0067     }
0068     # Now the next 8 entries should be of the form:
0069     #   Size:                 8 kB
0070     #   Rss:                  8 kB
0071     #   Shared_Clean:         0 kB
0072     #   Shared_Dirty:         0 kB
0073     #   Private_Clean:        0 kB
0074     #   Private_Dirty:        8 kB
0075     #   Swap:                 0 kB    (this field only in SLC5 kernels)
0076     #   Pss:                  0 kB    (this field only in SLC5 kernels)
0077     $procsize = <PROCSMAPS>; chomp($procsize);
0078     $procrss  = <PROCSMAPS>; chomp($procrss);
0079     $procshrclean = <PROCSMAPS>; chomp($procshrclean);
0080     $procshrdirty = <PROCSMAPS>; chomp($procshrdirty);
0081     $procprivclean = <PROCSMAPS>; chomp($privclean);
0082     $procprivdirty = <PROCSMAPS>; chomp($procprivdirty);
0083     $procswap = <PROCSMAPS>; chomp($procswap);
0084     $procpss = <PROCSMAPS>; chomp($procpss);
0085     ($a1,$vsize,$a3) = split(' ',$procsize);
0086     ($a1,$rss,$a3) = split(' ',$procrss);
0087     #print $vsize."   ".$rss."    ".$thelib."\n";
0088     if ($unused) {
0089       printf("%7uK  %7uK  %7uK  %s\n", $vsize, $rss, $vsize-$rss, $thelib);
0090     } else {
0091       printf("%7uK  %7uK  %s\n", $vsize, $rss, $thelib);
0092     }
0093   }