SlideShare a Scribd company logo
1 of 81
Download to read offline
http://xkcd.com/224/
Perl
 Code Profiling
Memory Profiling
    Perl 5
    Perl 6

 Tim Bunce - SkyCon’12
Devel::NYTProf
Perl Source Code Profiler


    Tim Bunce - SkyCon’12
Devel::DProf Is Broken
$ perl -we 'print "sub s$_ { sqrt(42) for 1..100 };
 s$_({});n" for 1..1000' > x.pl

$ perl -d:DProf x.pl

$ dprofpp -r
  Total Elapsed Time =    0.108 Seconds
           Real Time =    0.108 Seconds
  Exclusive Times
  %Time ExclSec CumulS #Calls sec/call Csec/c   Name
   9.26   0.010 0.010       1   0.0100 0.0100   main::s76
   9.26   0.010 0.010       1   0.0100 0.0100   main::s323
   9.26   0.010 0.010       1   0.0100 0.0100   main::s626
   9.26   0.010 0.010       1   0.0100 0.0100   main::s936
   0.00       - -0.000      1        -      -   main::s77
   0.00       - -0.000      1        -      -   main::s82
Profiling 101
  The Basics
What To Measure?

              CPU Time   Real Time


Subroutines
                 ?          ?
Statements
                 ?          ?
Devel::NYTProf
   Does it all
Running NYTProf
   perl -d:NYTProf ...
   perl -MDevel::NYTProf ...


Configure profiler via the NYTPROF env var
   perldoc Devel::NYTProf for the details


To profile code that’s invoked elsewhere:
   PERL5OPT=-d:NYTProf
   NYTPROF=file=/tmp/nytprof.out:addpid=1:...
Reporting: KCachegrind
• KCachegrind call graph - new and cool
   - contributed by C. L. Kao.
   - requires KCachegrind

  $ nytprofcg   # generates nytprof.callgraph
  $ kcachegrind # load the file via the gui
KCachegrind
Reporting: HTML
• HTML report
   -   page per source file, annotated with times and links
   -   subroutine index table with sortable columns
   -   interactive Treemap of subroutine times
   -   generates Graphviz dot file of call graph
   -   -m (--minimal) faster generation but less detailed

$ nytprofhtml # writes HTML report in ./nytprof/...
$ nytprofhtml --file=/tmp/nytprof.out.793 --open
Summary




                             Links to annotated
                                source code




Link to sortable table
      of all subs
                          Timings for perl builtins
Color coding based on        Overall time spent in and below this sub
Median Average Deviation
relative to rest of this file               (in + below)




Time between starting this perl
statement and starting the next.
So includes overhead of calls to
           perl subs.               Timings for each location calling into,
                                          or out of, the subroutine
Treemap showing relative
                 proportions of exclusive time




                                  Boxes represent subroutines
                                   Colors only used to show
                                packages (and aren’t pretty yet)




Hover over box to see details
                                          Click to drill-down one level
                                              in package hierarchy
Calls between packages
Calls to/from/within package
Questions?
                                   For more details see
Slides: http://www.slideshare.net/Tim.Bunce/develnytprof-v4-at-yapceu-201008-4906467
         Screencast: http://blip.tv/timbunce/devel-nytprof-yapc-asia-2012-6376582
Perl Memory Use
   Tim Bunce @ SkyCon’12
Ouch!
$ perl some_script.pl
Out of memory!
$

$ perl some_script.pl
Killed.
$

$ perl some_script.pl
$
Someone shouts: "Hey! My process has been killed!"

$ perl some_script.pl
[...later...] "Umm, what's taking so long?"
Process Memory
$ perl -e 'system("cat /proc/$$/stat")'   # $$ = pid
4752 (perl) S 4686 4752 4686 34816 4752 4202496 536 0 0 0 0 0 0 0 20 0 1 0 62673440 123121664 440
18446744073709551615 4194304 4198212 140735314078128 140735314077056 140645336670206 0 0 134 0
18446744071579305831 0 0 17 10 0 0 0 0 0 0 0 0 0 0 4752 111 111 111

$ perl -e 'system("cat /proc/$$/statm")'
30059 441 346 1 0 160 0

$ perl -e 'system("ps -p $$ -o vsz,rsz,sz,size")'
   VSZ   RSZ    SZ    SZ
120236 1764 30059    640

$ perl -e 'system("top -b -n1 -p $$")'
...
  PID USER      PR NI VIRT RES SHR S %CPU %MEM       TIME+ COMMAND
13063 tim       20   0 117m 1764 1384 S 0.0 0.1     0:00.00 perl

$ perl -e 'system("cat /proc/$$/status")'
...
VmPeak:!   120236 kB
VmSize:!   120236 kB <- total (code, libs, stack, heap etc.)
VmHWM:!      1760 kB
VmRSS:!      1760 kB <- how much of the total is resident in physical memory
VmData:!      548 kB <- data (heap)
VmStk:!        92 kB <- stack
VmExe:!         4 kB <- code
VmLib:!      4220 kB <- libs, including libperl.so
VmPTE:!        84 kB
VmPTD:!        28 kB
VmSwap:!        0 kB
...
                                                         Further info on unix.stackexchange.com
C Program Code       int main(...) { ... }
  Read-only Data       eg “String constants”
 Read-write Data      un/initialized variables
       Heap



                           (not to scale!)



 Shared Lib Code      
Shared Lib R/O Data    repeated for each lib
Shared Lib R/W Data   //



     C Stack           (not the perl stack)
      System
$ perl -e 'system("cat /proc/$$/maps")'
address                   perms ... pathname
00400000-00401000         r-xp ...   /.../perl-5.NN.N/bin/perl
00601000-00602000         rw-p ...   /.../perl-5.NN.N/bin/perl

0087f000-008c1000           rw-p ...     [heap]



7f858cba1000-7f8592a32000 r--p ...       /usr/lib/locale/locale-archive-rpm

7f8592c94000-7f8592e1a000   r-xp   ...   /lib64/libc-2.12.so
7f8592e1a000-7f859301a000   ---p   ...   /lib64/libc-2.12.so
7f859301a000-7f859301e000   r--p   ...   /lib64/libc-2.12.so
7f859301e000-7f859301f000   rw-p   ...   /lib64/libc-2.12.so
7f859301f000-7f8593024000   rw-p   ...

...other libs...

7f8593d1b000-7f8593e7c000   r-xp   ...   /.../lib/5.NN.N/x86_64-linux/CORE/libperl.so
7f8593e7c000-7f859407c000   ---p   ...   /.../lib/5.NN.N/x86_64-linux/CORE/libperl.so
7f859407c000-7f8594085000   rw-p   ...   /.../lib/5.NN.N/x86_64-linux/CORE/libperl.so
7f85942a6000-7f85942a7000   rw-p   ...


7fff61284000-7fff6129a000 rw-p ...       [stack]

7fff613fe000-7fff61400000 r-xp ...   [vdso]
ffffffffff600000-ffffffffff601000 r-xp ... [vsyscall]
$ perl -e 'system("cat /proc/$$/smaps")' # note ‘smaps’ not ‘maps’

address                   perms ...   pathname
...

7fb00fbc1000-7fb00fd22000 r-xp ... /.../5.10.1/x86_64-linux/CORE/libperl.so
Size:               1412 kB   <- size of executable code in libperl.so
Rss:                 720 kB   <- amount that's currently in physical memory
Pss:                 364 kB
Shared_Clean:        712 kB
Shared_Dirty:          0 kB
Private_Clean:         8 kB
Private_Dirty:         0 kB
Referenced:          720 kB
Anonymous:             0 kB
AnonHugePages:         0 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB

... repeated for every segment ...
... repeated for every segment ...
Memory Pages
✦   Process view:
     ✦   Single large memory space. Simple.
✦   Operating System view:
     ✦   Memory is divided into pages
     ✦   Pages are loaded to physical memory on demand
     ✦   Mapping can change without the process knowing
C Program Code
  Read-only Data      Memory is divided into pages
                       Page size is typically 4KB
 Read-write Data
       Heap

                      ← Page ‘resident’ in physical
                        memory
                      ← Page not resident



                         RSS “Resident Set Size”
                      is how much process memory is
 Shared Lib Code      currently in physical memory
Shared Lib R/O Data
Shared Lib R/W Data



     C Stack
      System
Key Point


✦   Don’t use Resident Set Size (RSS)
      ✦   It can shrink even while the process size grows.
✦   Heap size or Total memory size is a good indicator.
The Heap
Heap
       ← Your perl stuff goes here




       •   Heap is managed by malloc()
       •   Memory freed is rarely returned to
           the operating system
       •   Heap grows but rarely shrinks
Perl Data Anatomy
Integer
 (IV)


String
 (PV)


Number
with a
string



          Head Body Data   Illustrations from illguts
Array
(IV)




Hash
(HV)
Glob (GV)   Symbol Table (Stash)




Sub (CV)




              lots of tiny chunks!
Devel::Peek
•   Gives you a textual view of data
    $ perl -MDevel::Peek -e '%a = (42 => "Hello World!"); Dump(%a)'
    SV = IV(0x1332fd0) at 0x1332fe0
      REFCNT = 1
      FLAGS = (TEMP,ROK)
      RV = 0x1346730
      SV = PVHV(0x1339090) at 0x1346730
        REFCNT = 2
        FLAGS = (SHAREKEYS)
        ARRAY = 0x1378750 (0:7, 1:1)
        KEYS = 1
        FILL = 1
        MAX = 7
        Elt "42" HASH = 0x73caace8
        SV = PV(0x1331090) at 0x1332de8
          REFCNT = 1
          FLAGS = (POK,pPOK)
          PV = 0x133f960 "Hello World!"0
          CUR = 12                           <= length in use
          LEN = 16                           <= amount allocated
Devel::Size
•   Gives you a measure of the size of a data structure
    $ perl -MDevel::Size=total_size -le 'print total_size( 0 )'
    24

    $ perl -MDevel::Size=total_size -le 'print total_size( [] )'
    64

    $ perl -MDevel::Size=total_size -le 'print total_size( {} )'
    120

    $ perl -MDevel::Size=total_size -le 'print total_size( [ 1..100 ] )'
    3264

•   Is very fast, and accurate for most simple data types.
•   Has limitations and bugs, but is the best tool we have.
Memory Profiling
What?

✦   Track memory size over time?
✦   See where memory is allocated and freed?
✦   Experiments with Devel::NYTProf
✦   Turned out to not seem useful
Space in Hiding
✦   Perl tends to consume extra memory to save time
✦   This can lead to surprises, for example:
      ✦   sub foo {
              my $var = "X" x 10_000_000;
          }
          foo();      # ~20MB still used after return!

      ✦   sub bar{
              my $var = "X" x 10_000_000;
              bar($_[0]-1) if $_[0]; # recurse
          }
          bar(50);    # ~1GB still used after return!
My Plan
The Plan
✦   Extend Devel::Size
✦   Add a C-level callback hook
✦   Add some kind of "data path name" for the callback to use
✦   Add a function to Devel::Size to return the size of everything
✦   Stream the data to disk
✦   Write tools to visualize the data
✦   Add multi-phase scan
      1. scan symbol tables, skip where ref count > 1
      2. process the skipped items
      3. scan arenas for other values (e.g. leaks)
✦   Write tool to compare two sets of data
The Status
✓   Add a C-level callback hook
✓   Add some kind of "data path name" for the callback to use
✓   Add a function to Devel::Size to return the size of everything.
✓   Stream the data to disk
✓   Write tools to visualize the data

      •   Will become a separate distribution
      •   “Devel::SizeMeGraph”?
      •   Source repo available by Sunday
      •   Ready to demonstrate
Demonstration
Questions?
                               For more details see
Full slides: http://www.slideshare.net/Tim.Bunce/perl-memory-use-yapcasia2012
Screencast: http://blip.tv/timbunce/perl-memory-use-and-devel-sizeme-at-yapc-
                                asia-2012-6381282

                          Tim.Bunce@pobox.com
                          http://blog.timbunce.org
                                 @timbunce
Perl
A Summary of the Onions



      Tim Bunce – SkyCon’12
2007
-   Perl 5 isn’t the new kid on the block
    -   Perl is 25 years old
    -   Perl 5 is 18 years old
-   A mature language with a mature culture
From “The State of the Onion 10” by Larry Wall, 2006
-   Perl is 25 years old
-   Perl 5 is 18 years old
-   Perl 6 was conceived 12 years ago
-   Perl 6 “Rakudo Star” is 2 years old
“CPAN is my language,
       Perl is my VM”
-   Vast library of free code modules on “CPAN”
-   Over 5,100 active authors (making releases)
-   Over 26,000 distributions (110,000 modules)
-   ~1,000 uploads per month (by ~500 authors)
-   ~250 new distributions per month
-   Automated smoke testing for all uploads
search.cpan.org / metacpan.org
Dependency Analysis available for all Modules
      http://deps.cpantesters.org/?module=Moose;perl=latest
Automated Smoke Testing




http://matrix.cpantesters.org/?dist=Moose%202.0603
Perl 5 Development
- 5.10 – 2007
- 5.12 – 2010
- 5.14 – 2011
- 5.16 – 2012
- 5.17.4 latest monthly development release
- 5.18 – due May 2013
Perl 5 New Features

- Refactored internals
 	

     many fixes, more speed, less memory
- New language features (state, say, //, autodie, ...)
- Language feature management
- Unicode 6.1 and many new Unicode features
- Many powerful new regex features
        See http://www.slideshare.net/rjbs/whats-new-in-perl-v510-v516
http://xkcd.com/208/
Demo
                Regexp::Debuger
See http://www.youtube.com/watch?v=zcSFIUiMgAs
A Culture of Testing
-2002: Perl 5.8.0 had 26,725 core tests
	

    +41,666 more for bundled libraries etc.
-2007: Perl 5.10.0 has 78,883 core tests
	

    +109,427
-2010: Perl 5.11.5 has 191,008 core tests
	

    +167,015
-2012: Perl 5.16.0 has 262,370 core tests
       +261,776
Perl 6
Another member of the Perl language family
Learn it once, use it many times. Learn as
you go.       Many acceptable levels of
competence. Multiple ways to say the same
thing. No shame in borrowing. Indeterminate
dimensionality. Local ambiguity is okay.
         Natural Language
Punctuation by prosody and inflection.
         Principles in Perl
Disambiguation by number, case and word
order. Topicalization. Discourse structure.
Pronominalization. No theoretical axes to
grind. Style not enforced except by peer
pressure. Cooperative design. “Inevitable”
Divergence.     http://www.wall.org/~larry/natural.html
Timeline
2000: Perl 6 conceived (after a smashed coffee mug)
2001-2004: Initial design docs
2005: First prototype, pugs (in Haskell)
2005+ Continual radical evolution (the whirlpool)
2010: 1st Rakudo Star release
2012: 17th Rakudo Star release
   Mostly implemented in Perl6 (>60% and rising)
“If we'd done Perl 6 on a schedule, you'd have it by
now. And it would be crap.”
    —Larry Wall, 2002


“Do it right.” and “It's ready when it's ready.”
    Freedom to explore deeply and change


“Truly radical and far-reaching improvements over
the past few years.”
“We've spent a decade stealing the very best ideas
from the best programming languages, and making
them simple and practical for mortal developers to
use.”
   —Damian Conway
“Should be called Perl 8 or Perl 9”




“feedback at many levels from multiple implementations”
Multiple Implementations
 Two main implementations:
     Rakudo - built on Parrot Compiler Toolchain
     Niecza - targeting the CLR (.NET and Mono)
 Plus: STD, viv, Perlito, Pugs and others
 Work on a JVM implementation is starting


 All sharing a common test suite

                See http://perl6.org/compilers
Some Perl 6 Features
Rich set of operators and meta-operators
Rich type system
Rich object system, including roles/traits
A full Meta Object Protocol
Multiple dispatch using types and expressive signatures
Gradual typing
Lazy lists and iterators, with controllable eagerness
Deep introspection
Native Call Interface
Representational polymorphism
Powerful matching and parsing with subclassable grammars
Series and Reduction
‣   say 1, 2, 4 ... 1024;
    1 2 4 8 16 32 64 128 256 512 1024

‣   my @fib = 1, 1, *+* ... *;   # infinite
    say @fib[^10]; # 0..9
    1 1 2 3 5 8 13 21 34 55 89

‣   say [*] 1..10; # reduction, use any operator
    3628800

‣   sub postfix:<!>($n) { [*] 1..$n }
    say 10!
    3628800
Multiple Dispatch
‣   multi fact(0) { 1 }
    multi fact($n) { $n * fact($n – 1) }

‣   multi fib(0) { 0 }
    multi fib(1) { 1 }
    multi fib($n) { fib($n – 1) + fib($n – 2) }

‣   multi quicksort([]) { () }
    multi quicksort([$pivot, *@rest]) {
        my @before = @rest.grep(* < $pivot);
        my @after = @rest.grep(* >= $pivot);
        (quicksort(@before), $pivot, quicksort(@after))
    }
Native Call Interface
sub PQexecPrepared(
     - OpaquePointer $conn,
       Str $statement_name,
       Int $n_params,
       CArray[Str] $param_values,
       CArray[int] $param_length,
       CArray[int] $param_formats,
       Int $resultFormat)

 -    returns OpaquePointer
      is native('libpq')
      { ... }

Also supports structures and callbacks.
my @suits   = < ♣ ♢ ♡ ♠ >;
my @ranks   = 2..10, < J Q K A >;

# concatenate each rank with each suit
my @deck = @ranks X~ @suits;

# create hash of card to points value
my %points = @deck Z (    (2..10, 10, 10, 10, 11)
                       X+ (0,0,0,0) );

# grab five cards from the deck
my @hand = @deck.pick(5);

# display my hand
say ~@hand;

# tell me how many points it's worth
say [+] %points{@hand};
@xyz»++                 # increment all elements of @xyz

@x = @a »min« @b        # @x is smallest of @a and @b

$mean = ([+] @a) / @a            # calculate mean of @a

$sumsq = [+] (@x »**» 2)         # sum of squares of @x

$fact = [*] 1..$n                # $n factorial

for %hash.kv -> $k, $v { say "$k: $v" }
Example Module
      JSON::Tiny




   https://github.com/moritz/json
module JSON::Tiny;

proto to-json($) is export {*}
multi to-json(Real:D $d) { ~$d }
multi to-json(Bool:D $d) { $d ?? 'true' !! 'false'; }
multi to-json(Str:D $d) {
    '"'
    ~ $d.trans(['"', '',     "b", "f", "n", "r", "t"]
            => ['"', '', 'b', 'f', 'n', 'r', 't'])
            .subst(/<-[c32..c126]>/, { ord(~$_).fmt('u%04x') }, :g)
    ~ '"'
}
multi to-json(Positional:D $d) {
  return '[ ' ~ $d.map(&to-json).join(', ') ~ ' ]';
}
multi to-json(Hash:D $d) {
  return '{ '~ $d.map({ to-json(.key)~' : '~to-json(.value) }).join(', ')~ ' }';
}
multi to-json(Any:U $) { 'null' }
multi to-json(Any:D $s) { die "Can't serialize an object of type "~$s.WHAT.perl}



use JSON::Tiny::Actions;
use JSON::Tiny::Grammar;

sub from-json($text) is export {
    my $a = JSON::Tiny::Actions.new();
    my $o = JSON::Tiny::Grammar.parse($text, :actions($a));
    return $o.ast;
}
grammar JSON::Tiny::Grammar;

rule   TOP         {   ^ [   <object> | <array> ] $ }
rule   object      {   '{'   ~ '}' <pairlist>     }
rule   pairlist    {   <?>   <pair> * % ,              }
rule   pair        {   <?>   <string> ':' <value>     }
rule   array       {   '['   ~ ']' <arraylist>    }
rule   arraylist   {   <?>   <value>* % [ , ]        }

proto token value {*};
token value:sym<number> {
    '-'?
    [ 0 | <[1..9]> <[0..9]>* ]
    [ . <[0..9]>+ ]?
    [ <[eE]> [+|-]? <[0..9]>+ ]?
}
token value:sym<true>     { <sym>          };
token value:sym<false>    { <sym>          };
token value:sym<null>     { <sym>          };
token value:sym<object> { <object>         };
token value:sym<array>    { <array>        };
token value:sym<string> { <string>         }

token string                    { " ~ " ( <str> |  <str_escape> )* }
token str                       { <-["tn]>+ }
token str_escape                { <["/bfnrt]> | u <xdigit>**4 }
class JSON::Tiny::Actions;

method TOP($/)       { make $/.values.[0].ast };

method object($/)     { make $<pairlist>.ast.hash }
method pairlist($/) { make $<pair>>>.ast.flat }
method pair($/)       { make $<string>.ast => $<value>.ast }
method array($/)      { make $<arraylist>.ast }
method arraylist($/) { make [$<value>>>.ast] }
method string($/) {
    make $0.elems == 1
        ?? ($0[0].<str> || $0[0].<str_escape>).ast
        !! join '', $0.list.map({ (.<str> || .<str_escape>).ast });
}
method value:sym<number>($/) { make +$/.Str }
method value:sym<string>($/) { make $<string>.ast }
method value:sym<true>($/)    { make Bool::True }
method value:sym<false>($/) { make Bool::False }
method value:sym<null>($/)    { make Any }
method value:sym<object>($/) { make $<object>.ast }
method value:sym<array>($/) { make $<array>.ast }
method str($/)                { make ~$/ }
method str_escape($/) {
    if $<xdigit> {
        make chr(:16($<xdigit>.join));
    } else {
        my %h = '' => "", '/' => "/", 'b' => "b", 'n' => "n",
                  't' => "t", 'f' => "f", 'r' => "r", '"' => """;
        make %h{~$/};
    }
}
Perl 6

Already full of awesome
Hundreds of examples on http://rosettacode.org
Developers happy to stay in stealth mode for now
Get ahead of the revolution: http://perl6.org
In Summary...
Perl
has a massive library of reusable code
has a culture of best practice and testing
has a happy welcoming growing community
has a great future in Perl 5 and Perl 6
is a great language for getting your job done
   for the last 25 years, and the next 25!
Questions?
See also http://www.slideshare.net/Tim.Bunce/perl-myths-200909


                       http://perlmonks.org
                      http://search.cpan.org
                  http://rakudo.org/how-to-help
                     http://blog.timbunce.org
                            @timbunce
http://xkcd.com/519/

More Related Content

What's hot

Devel::NYTProf 2009-07 (OUTDATED, see 201008)
Devel::NYTProf 2009-07 (OUTDATED, see 201008)Devel::NYTProf 2009-07 (OUTDATED, see 201008)
Devel::NYTProf 2009-07 (OUTDATED, see 201008)Tim Bunce
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in PerlLaurent Dami
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011CodeIgniter Conference
 
Perl Dist::Surveyor 2011
Perl Dist::Surveyor 2011Perl Dist::Surveyor 2011
Perl Dist::Surveyor 2011Tim Bunce
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueGleicon Moraes
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLitecharsbar
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scriptingTony Fabeen
 
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksHow to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksCarlos Sanchez
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queueBrandon Lamb
 
Using ngx_lua in UPYUN
Using ngx_lua in UPYUNUsing ngx_lua in UPYUN
Using ngx_lua in UPYUNCong Zhang
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteAllen Wittenauer
 
Roll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and LuaRoll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and LuaJon Moore
 
Programming Hive Reading #4
Programming Hive Reading #4Programming Hive Reading #4
Programming Hive Reading #4moai kids
 
Fluentd unified logging layer
Fluentd   unified logging layerFluentd   unified logging layer
Fluentd unified logging layerKiyoto Tamura
 
Hadoop 20111117
Hadoop 20111117Hadoop 20111117
Hadoop 20111117exsuns
 
Lua tech talk
Lua tech talkLua tech talk
Lua tech talkLocaweb
 

What's hot (20)

Devel::NYTProf 2009-07 (OUTDATED, see 201008)
Devel::NYTProf 2009-07 (OUTDATED, see 201008)Devel::NYTProf 2009-07 (OUTDATED, see 201008)
Devel::NYTProf 2009-07 (OUTDATED, see 201008)
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
 
Perl Dist::Surveyor 2011
Perl Dist::Surveyor 2011Perl Dist::Surveyor 2011
Perl Dist::Surveyor 2011
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLite
 
High Performance tDiary
High Performance tDiaryHigh Performance tDiary
High Performance tDiary
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
 
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksHow to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queue
 
Using ngx_lua in UPYUN
Using ngx_lua in UPYUNUsing ngx_lua in UPYUN
Using ngx_lua in UPYUN
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell Rewrite
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
Roll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and LuaRoll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and Lua
 
Programming Hive Reading #4
Programming Hive Reading #4Programming Hive Reading #4
Programming Hive Reading #4
 
Fluentd unified logging layer
Fluentd   unified logging layerFluentd   unified logging layer
Fluentd unified logging layer
 
Tuning Solr for Logs
Tuning Solr for LogsTuning Solr for Logs
Tuning Solr for Logs
 
Hadoop 20111117
Hadoop 20111117Hadoop 20111117
Hadoop 20111117
 
Top Node.js Metrics to Watch
Top Node.js Metrics to WatchTop Node.js Metrics to Watch
Top Node.js Metrics to Watch
 
Lua tech talk
Lua tech talkLua tech talk
Lua tech talk
 

Similar to Perl at SkyCon'12

Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing DaeHyung Lee
 
Perly Parallel Processing of Fixed Width Data Records
Perly Parallel Processing of Fixed Width Data RecordsPerly Parallel Processing of Fixed Width Data Records
Perly Parallel Processing of Fixed Width Data RecordsWorkhorse Computing
 
Speed up R with parallel programming in the Cloud
Speed up R with parallel programming in the CloudSpeed up R with parallel programming in the Cloud
Speed up R with parallel programming in the CloudRevolution Analytics
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPkatzgrau
 
Driver Debugging Basics
Driver Debugging BasicsDriver Debugging Basics
Driver Debugging BasicsBala Subra
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceJesse Vincent
 
Tips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software EngineeringTips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software Engineeringjtdudley
 
Hadoop Performance Optimization at Scale, Lessons Learned at Twitter
Hadoop Performance Optimization at Scale, Lessons Learned at TwitterHadoop Performance Optimization at Scale, Lessons Learned at Twitter
Hadoop Performance Optimization at Scale, Lessons Learned at TwitterDataWorks Summit
 
What we can learn from Rebol?
What we can learn from Rebol?What we can learn from Rebol?
What we can learn from Rebol?lichtkind
 
Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Ilya Haykinson
 
Servers and Processes: Behavior and Analysis
Servers and Processes: Behavior and AnalysisServers and Processes: Behavior and Analysis
Servers and Processes: Behavior and Analysisdreamwidth
 
Hadoop Summit 2015: Performance Optimization at Scale, Lessons Learned at Twi...
Hadoop Summit 2015: Performance Optimization at Scale, Lessons Learned at Twi...Hadoop Summit 2015: Performance Optimization at Scale, Lessons Learned at Twi...
Hadoop Summit 2015: Performance Optimization at Scale, Lessons Learned at Twi...Alex Levenson
 
Using R on High Performance Computers
Using R on High Performance ComputersUsing R on High Performance Computers
Using R on High Performance ComputersDave Hiltbrand
 
Tips
TipsTips
Tipsmclee
 
You know, for search. Querying 24 Billion Documents in 900ms
You know, for search. Querying 24 Billion Documents in 900msYou know, for search. Querying 24 Billion Documents in 900ms
You know, for search. Querying 24 Billion Documents in 900msJodok Batlogg
 

Similar to Perl at SkyCon'12 (20)

Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing
 
Perly Parallel Processing of Fixed Width Data Records
Perly Parallel Processing of Fixed Width Data RecordsPerly Parallel Processing of Fixed Width Data Records
Perly Parallel Processing of Fixed Width Data Records
 
Inferno Scalable Deep Learning on Spark
Inferno Scalable Deep Learning on SparkInferno Scalable Deep Learning on Spark
Inferno Scalable Deep Learning on Spark
 
Speed up R with parallel programming in the Cloud
Speed up R with parallel programming in the CloudSpeed up R with parallel programming in the Cloud
Speed up R with parallel programming in the Cloud
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMP
 
Driver Debugging Basics
Driver Debugging BasicsDriver Debugging Basics
Driver Debugging Basics
 
Osd ctw spark
Osd ctw sparkOsd ctw spark
Osd ctw spark
 
Nyt Prof 200910
Nyt Prof 200910Nyt Prof 200910
Nyt Prof 200910
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret Sauce
 
Tips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software EngineeringTips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software Engineering
 
Hadoop Performance Optimization at Scale, Lessons Learned at Twitter
Hadoop Performance Optimization at Scale, Lessons Learned at TwitterHadoop Performance Optimization at Scale, Lessons Learned at Twitter
Hadoop Performance Optimization at Scale, Lessons Learned at Twitter
 
What we can learn from Rebol?
What we can learn from Rebol?What we can learn from Rebol?
What we can learn from Rebol?
 
Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4
 
Servers and Processes: Behavior and Analysis
Servers and Processes: Behavior and AnalysisServers and Processes: Behavior and Analysis
Servers and Processes: Behavior and Analysis
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
myHadoop 0.30
myHadoop 0.30myHadoop 0.30
myHadoop 0.30
 
Hadoop Summit 2015: Performance Optimization at Scale, Lessons Learned at Twi...
Hadoop Summit 2015: Performance Optimization at Scale, Lessons Learned at Twi...Hadoop Summit 2015: Performance Optimization at Scale, Lessons Learned at Twi...
Hadoop Summit 2015: Performance Optimization at Scale, Lessons Learned at Twi...
 
Using R on High Performance Computers
Using R on High Performance ComputersUsing R on High Performance Computers
Using R on High Performance Computers
 
Tips
TipsTips
Tips
 
You know, for search. Querying 24 Billion Documents in 900ms
You know, for search. Querying 24 Billion Documents in 900msYou know, for search. Querying 24 Billion Documents in 900ms
You know, for search. Querying 24 Billion Documents in 900ms
 

More from Tim Bunce

Perl6 DBDI YAPC::EU 201008
Perl6 DBDI YAPC::EU 201008Perl6 DBDI YAPC::EU 201008
Perl6 DBDI YAPC::EU 201008Tim Bunce
 
Perl 6 DBDI 201007 (OUTDATED, see 201008)
Perl 6 DBDI 201007 (OUTDATED, see 201008)Perl 6 DBDI 201007 (OUTDATED, see 201008)
Perl 6 DBDI 201007 (OUTDATED, see 201008)Tim Bunce
 
DBI Advanced Tutorial 2007
DBI Advanced Tutorial 2007DBI Advanced Tutorial 2007
DBI Advanced Tutorial 2007Tim Bunce
 
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Tim Bunce
 
Perl Myths 200909
Perl Myths 200909Perl Myths 200909
Perl Myths 200909Tim Bunce
 
DashProfiler 200807
DashProfiler 200807DashProfiler 200807
DashProfiler 200807Tim Bunce
 
DBI for Parrot and Perl 6 Lightning Talk 2007
DBI for Parrot and Perl 6 Lightning Talk 2007DBI for Parrot and Perl 6 Lightning Talk 2007
DBI for Parrot and Perl 6 Lightning Talk 2007Tim Bunce
 
Perl Myths 200802 with notes (OUTDATED, see 200909)
Perl Myths 200802 with notes (OUTDATED, see 200909)Perl Myths 200802 with notes (OUTDATED, see 200909)
Perl Myths 200802 with notes (OUTDATED, see 200909)Tim Bunce
 

More from Tim Bunce (8)

Perl6 DBDI YAPC::EU 201008
Perl6 DBDI YAPC::EU 201008Perl6 DBDI YAPC::EU 201008
Perl6 DBDI YAPC::EU 201008
 
Perl 6 DBDI 201007 (OUTDATED, see 201008)
Perl 6 DBDI 201007 (OUTDATED, see 201008)Perl 6 DBDI 201007 (OUTDATED, see 201008)
Perl 6 DBDI 201007 (OUTDATED, see 201008)
 
DBI Advanced Tutorial 2007
DBI Advanced Tutorial 2007DBI Advanced Tutorial 2007
DBI Advanced Tutorial 2007
 
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
 
Perl Myths 200909
Perl Myths 200909Perl Myths 200909
Perl Myths 200909
 
DashProfiler 200807
DashProfiler 200807DashProfiler 200807
DashProfiler 200807
 
DBI for Parrot and Perl 6 Lightning Talk 2007
DBI for Parrot and Perl 6 Lightning Talk 2007DBI for Parrot and Perl 6 Lightning Talk 2007
DBI for Parrot and Perl 6 Lightning Talk 2007
 
Perl Myths 200802 with notes (OUTDATED, see 200909)
Perl Myths 200802 with notes (OUTDATED, see 200909)Perl Myths 200802 with notes (OUTDATED, see 200909)
Perl Myths 200802 with notes (OUTDATED, see 200909)
 

Recently uploaded

Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 

Recently uploaded (20)

Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 

Perl at SkyCon'12

  • 2. Perl Code Profiling Memory Profiling Perl 5 Perl 6 Tim Bunce - SkyCon’12
  • 3. Devel::NYTProf Perl Source Code Profiler Tim Bunce - SkyCon’12
  • 4. Devel::DProf Is Broken $ perl -we 'print "sub s$_ { sqrt(42) for 1..100 }; s$_({});n" for 1..1000' > x.pl $ perl -d:DProf x.pl $ dprofpp -r Total Elapsed Time = 0.108 Seconds Real Time = 0.108 Seconds Exclusive Times %Time ExclSec CumulS #Calls sec/call Csec/c Name 9.26 0.010 0.010 1 0.0100 0.0100 main::s76 9.26 0.010 0.010 1 0.0100 0.0100 main::s323 9.26 0.010 0.010 1 0.0100 0.0100 main::s626 9.26 0.010 0.010 1 0.0100 0.0100 main::s936 0.00 - -0.000 1 - - main::s77 0.00 - -0.000 1 - - main::s82
  • 5. Profiling 101 The Basics
  • 6. What To Measure? CPU Time Real Time Subroutines ? ? Statements ? ?
  • 7. Devel::NYTProf Does it all
  • 8. Running NYTProf perl -d:NYTProf ... perl -MDevel::NYTProf ... Configure profiler via the NYTPROF env var perldoc Devel::NYTProf for the details To profile code that’s invoked elsewhere: PERL5OPT=-d:NYTProf NYTPROF=file=/tmp/nytprof.out:addpid=1:...
  • 9. Reporting: KCachegrind • KCachegrind call graph - new and cool - contributed by C. L. Kao. - requires KCachegrind $ nytprofcg # generates nytprof.callgraph $ kcachegrind # load the file via the gui
  • 11. Reporting: HTML • HTML report - page per source file, annotated with times and links - subroutine index table with sortable columns - interactive Treemap of subroutine times - generates Graphviz dot file of call graph - -m (--minimal) faster generation but less detailed $ nytprofhtml # writes HTML report in ./nytprof/... $ nytprofhtml --file=/tmp/nytprof.out.793 --open
  • 12.
  • 13. Summary Links to annotated source code Link to sortable table of all subs Timings for perl builtins
  • 14.
  • 15. Color coding based on Overall time spent in and below this sub Median Average Deviation relative to rest of this file (in + below) Time between starting this perl statement and starting the next. So includes overhead of calls to perl subs. Timings for each location calling into, or out of, the subroutine
  • 16.
  • 17. Treemap showing relative proportions of exclusive time Boxes represent subroutines Colors only used to show packages (and aren’t pretty yet) Hover over box to see details Click to drill-down one level in package hierarchy
  • 20. Questions? For more details see Slides: http://www.slideshare.net/Tim.Bunce/develnytprof-v4-at-yapceu-201008-4906467 Screencast: http://blip.tv/timbunce/devel-nytprof-yapc-asia-2012-6376582
  • 21. Perl Memory Use Tim Bunce @ SkyCon’12
  • 22. Ouch! $ perl some_script.pl Out of memory! $ $ perl some_script.pl Killed. $ $ perl some_script.pl $ Someone shouts: "Hey! My process has been killed!" $ perl some_script.pl [...later...] "Umm, what's taking so long?"
  • 24. $ perl -e 'system("cat /proc/$$/stat")' # $$ = pid 4752 (perl) S 4686 4752 4686 34816 4752 4202496 536 0 0 0 0 0 0 0 20 0 1 0 62673440 123121664 440 18446744073709551615 4194304 4198212 140735314078128 140735314077056 140645336670206 0 0 134 0 18446744071579305831 0 0 17 10 0 0 0 0 0 0 0 0 0 0 4752 111 111 111 $ perl -e 'system("cat /proc/$$/statm")' 30059 441 346 1 0 160 0 $ perl -e 'system("ps -p $$ -o vsz,rsz,sz,size")' VSZ RSZ SZ SZ 120236 1764 30059 640 $ perl -e 'system("top -b -n1 -p $$")' ... PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 13063 tim 20 0 117m 1764 1384 S 0.0 0.1 0:00.00 perl $ perl -e 'system("cat /proc/$$/status")' ... VmPeak:! 120236 kB VmSize:! 120236 kB <- total (code, libs, stack, heap etc.) VmHWM:! 1760 kB VmRSS:! 1760 kB <- how much of the total is resident in physical memory VmData:! 548 kB <- data (heap) VmStk:! 92 kB <- stack VmExe:! 4 kB <- code VmLib:! 4220 kB <- libs, including libperl.so VmPTE:! 84 kB VmPTD:! 28 kB VmSwap:! 0 kB ... Further info on unix.stackexchange.com
  • 25. C Program Code int main(...) { ... } Read-only Data eg “String constants” Read-write Data un/initialized variables Heap (not to scale!) Shared Lib Code Shared Lib R/O Data repeated for each lib Shared Lib R/W Data // C Stack (not the perl stack) System
  • 26. $ perl -e 'system("cat /proc/$$/maps")' address perms ... pathname 00400000-00401000 r-xp ... /.../perl-5.NN.N/bin/perl 00601000-00602000 rw-p ... /.../perl-5.NN.N/bin/perl 0087f000-008c1000 rw-p ... [heap] 7f858cba1000-7f8592a32000 r--p ... /usr/lib/locale/locale-archive-rpm 7f8592c94000-7f8592e1a000 r-xp ... /lib64/libc-2.12.so 7f8592e1a000-7f859301a000 ---p ... /lib64/libc-2.12.so 7f859301a000-7f859301e000 r--p ... /lib64/libc-2.12.so 7f859301e000-7f859301f000 rw-p ... /lib64/libc-2.12.so 7f859301f000-7f8593024000 rw-p ... ...other libs... 7f8593d1b000-7f8593e7c000 r-xp ... /.../lib/5.NN.N/x86_64-linux/CORE/libperl.so 7f8593e7c000-7f859407c000 ---p ... /.../lib/5.NN.N/x86_64-linux/CORE/libperl.so 7f859407c000-7f8594085000 rw-p ... /.../lib/5.NN.N/x86_64-linux/CORE/libperl.so 7f85942a6000-7f85942a7000 rw-p ... 7fff61284000-7fff6129a000 rw-p ... [stack] 7fff613fe000-7fff61400000 r-xp ... [vdso] ffffffffff600000-ffffffffff601000 r-xp ... [vsyscall]
  • 27. $ perl -e 'system("cat /proc/$$/smaps")' # note ‘smaps’ not ‘maps’ address perms ... pathname ... 7fb00fbc1000-7fb00fd22000 r-xp ... /.../5.10.1/x86_64-linux/CORE/libperl.so Size: 1412 kB <- size of executable code in libperl.so Rss: 720 kB <- amount that's currently in physical memory Pss: 364 kB Shared_Clean: 712 kB Shared_Dirty: 0 kB Private_Clean: 8 kB Private_Dirty: 0 kB Referenced: 720 kB Anonymous: 0 kB AnonHugePages: 0 kB Swap: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB ... repeated for every segment ... ... repeated for every segment ...
  • 28. Memory Pages ✦ Process view: ✦ Single large memory space. Simple. ✦ Operating System view: ✦ Memory is divided into pages ✦ Pages are loaded to physical memory on demand ✦ Mapping can change without the process knowing
  • 29. C Program Code Read-only Data Memory is divided into pages Page size is typically 4KB Read-write Data Heap ← Page ‘resident’ in physical memory ← Page not resident RSS “Resident Set Size” is how much process memory is Shared Lib Code currently in physical memory Shared Lib R/O Data Shared Lib R/W Data C Stack System
  • 30. Key Point ✦ Don’t use Resident Set Size (RSS) ✦ It can shrink even while the process size grows. ✦ Heap size or Total memory size is a good indicator.
  • 32. Heap ← Your perl stuff goes here • Heap is managed by malloc() • Memory freed is rarely returned to the operating system • Heap grows but rarely shrinks
  • 33. Perl Data Anatomy Integer (IV) String (PV) Number with a string Head Body Data Illustrations from illguts
  • 35. Glob (GV) Symbol Table (Stash) Sub (CV) lots of tiny chunks!
  • 36. Devel::Peek • Gives you a textual view of data $ perl -MDevel::Peek -e '%a = (42 => "Hello World!"); Dump(%a)' SV = IV(0x1332fd0) at 0x1332fe0 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x1346730 SV = PVHV(0x1339090) at 0x1346730 REFCNT = 2 FLAGS = (SHAREKEYS) ARRAY = 0x1378750 (0:7, 1:1) KEYS = 1 FILL = 1 MAX = 7 Elt "42" HASH = 0x73caace8 SV = PV(0x1331090) at 0x1332de8 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x133f960 "Hello World!"0 CUR = 12 <= length in use LEN = 16 <= amount allocated
  • 37. Devel::Size • Gives you a measure of the size of a data structure $ perl -MDevel::Size=total_size -le 'print total_size( 0 )' 24 $ perl -MDevel::Size=total_size -le 'print total_size( [] )' 64 $ perl -MDevel::Size=total_size -le 'print total_size( {} )' 120 $ perl -MDevel::Size=total_size -le 'print total_size( [ 1..100 ] )' 3264 • Is very fast, and accurate for most simple data types. • Has limitations and bugs, but is the best tool we have.
  • 39. What? ✦ Track memory size over time? ✦ See where memory is allocated and freed? ✦ Experiments with Devel::NYTProf ✦ Turned out to not seem useful
  • 40. Space in Hiding ✦ Perl tends to consume extra memory to save time ✦ This can lead to surprises, for example: ✦ sub foo { my $var = "X" x 10_000_000; } foo(); # ~20MB still used after return! ✦ sub bar{ my $var = "X" x 10_000_000; bar($_[0]-1) if $_[0]; # recurse } bar(50); # ~1GB still used after return!
  • 42. The Plan ✦ Extend Devel::Size ✦ Add a C-level callback hook ✦ Add some kind of "data path name" for the callback to use ✦ Add a function to Devel::Size to return the size of everything ✦ Stream the data to disk ✦ Write tools to visualize the data ✦ Add multi-phase scan 1. scan symbol tables, skip where ref count > 1 2. process the skipped items 3. scan arenas for other values (e.g. leaks) ✦ Write tool to compare two sets of data
  • 43. The Status ✓ Add a C-level callback hook ✓ Add some kind of "data path name" for the callback to use ✓ Add a function to Devel::Size to return the size of everything. ✓ Stream the data to disk ✓ Write tools to visualize the data • Will become a separate distribution • “Devel::SizeMeGraph”? • Source repo available by Sunday • Ready to demonstrate
  • 45. Questions? For more details see Full slides: http://www.slideshare.net/Tim.Bunce/perl-memory-use-yapcasia2012 Screencast: http://blip.tv/timbunce/perl-memory-use-and-devel-sizeme-at-yapc- asia-2012-6381282 Tim.Bunce@pobox.com http://blog.timbunce.org @timbunce
  • 46. Perl A Summary of the Onions Tim Bunce – SkyCon’12
  • 47. 2007
  • 48. - Perl 5 isn’t the new kid on the block - Perl is 25 years old - Perl 5 is 18 years old - A mature language with a mature culture
  • 49. From “The State of the Onion 10” by Larry Wall, 2006
  • 50. - Perl is 25 years old - Perl 5 is 18 years old - Perl 6 was conceived 12 years ago - Perl 6 “Rakudo Star” is 2 years old
  • 51. “CPAN is my language, Perl is my VM” - Vast library of free code modules on “CPAN” - Over 5,100 active authors (making releases) - Over 26,000 distributions (110,000 modules) - ~1,000 uploads per month (by ~500 authors) - ~250 new distributions per month - Automated smoke testing for all uploads
  • 53. Dependency Analysis available for all Modules http://deps.cpantesters.org/?module=Moose;perl=latest
  • 55. Perl 5 Development - 5.10 – 2007 - 5.12 – 2010 - 5.14 – 2011 - 5.16 – 2012 - 5.17.4 latest monthly development release - 5.18 – due May 2013
  • 56. Perl 5 New Features - Refactored internals many fixes, more speed, less memory - New language features (state, say, //, autodie, ...) - Language feature management - Unicode 6.1 and many new Unicode features - Many powerful new regex features See http://www.slideshare.net/rjbs/whats-new-in-perl-v510-v516
  • 58. Demo Regexp::Debuger See http://www.youtube.com/watch?v=zcSFIUiMgAs
  • 59. A Culture of Testing -2002: Perl 5.8.0 had 26,725 core tests +41,666 more for bundled libraries etc. -2007: Perl 5.10.0 has 78,883 core tests +109,427 -2010: Perl 5.11.5 has 191,008 core tests +167,015 -2012: Perl 5.16.0 has 262,370 core tests +261,776
  • 60. Perl 6 Another member of the Perl language family
  • 61. Learn it once, use it many times. Learn as you go. Many acceptable levels of competence. Multiple ways to say the same thing. No shame in borrowing. Indeterminate dimensionality. Local ambiguity is okay. Natural Language Punctuation by prosody and inflection. Principles in Perl Disambiguation by number, case and word order. Topicalization. Discourse structure. Pronominalization. No theoretical axes to grind. Style not enforced except by peer pressure. Cooperative design. “Inevitable” Divergence. http://www.wall.org/~larry/natural.html
  • 62. Timeline 2000: Perl 6 conceived (after a smashed coffee mug) 2001-2004: Initial design docs 2005: First prototype, pugs (in Haskell) 2005+ Continual radical evolution (the whirlpool) 2010: 1st Rakudo Star release 2012: 17th Rakudo Star release Mostly implemented in Perl6 (>60% and rising)
  • 63. “If we'd done Perl 6 on a schedule, you'd have it by now. And it would be crap.” —Larry Wall, 2002 “Do it right.” and “It's ready when it's ready.” Freedom to explore deeply and change “Truly radical and far-reaching improvements over the past few years.”
  • 64. “We've spent a decade stealing the very best ideas from the best programming languages, and making them simple and practical for mortal developers to use.” —Damian Conway
  • 65. “Should be called Perl 8 or Perl 9” “feedback at many levels from multiple implementations”
  • 66. Multiple Implementations Two main implementations: Rakudo - built on Parrot Compiler Toolchain Niecza - targeting the CLR (.NET and Mono) Plus: STD, viv, Perlito, Pugs and others Work on a JVM implementation is starting All sharing a common test suite See http://perl6.org/compilers
  • 67. Some Perl 6 Features Rich set of operators and meta-operators Rich type system Rich object system, including roles/traits A full Meta Object Protocol Multiple dispatch using types and expressive signatures Gradual typing Lazy lists and iterators, with controllable eagerness Deep introspection Native Call Interface Representational polymorphism Powerful matching and parsing with subclassable grammars
  • 68. Series and Reduction ‣ say 1, 2, 4 ... 1024; 1 2 4 8 16 32 64 128 256 512 1024 ‣ my @fib = 1, 1, *+* ... *; # infinite say @fib[^10]; # 0..9 1 1 2 3 5 8 13 21 34 55 89 ‣ say [*] 1..10; # reduction, use any operator 3628800 ‣ sub postfix:<!>($n) { [*] 1..$n } say 10! 3628800
  • 69. Multiple Dispatch ‣ multi fact(0) { 1 } multi fact($n) { $n * fact($n – 1) } ‣ multi fib(0) { 0 } multi fib(1) { 1 } multi fib($n) { fib($n – 1) + fib($n – 2) } ‣ multi quicksort([]) { () } multi quicksort([$pivot, *@rest]) { my @before = @rest.grep(* < $pivot); my @after = @rest.grep(* >= $pivot); (quicksort(@before), $pivot, quicksort(@after)) }
  • 70. Native Call Interface sub PQexecPrepared( - OpaquePointer $conn, Str $statement_name, Int $n_params, CArray[Str] $param_values, CArray[int] $param_length, CArray[int] $param_formats, Int $resultFormat) - returns OpaquePointer is native('libpq') { ... } Also supports structures and callbacks.
  • 71. my @suits = < ♣ ♢ ♡ ♠ >; my @ranks = 2..10, < J Q K A >; # concatenate each rank with each suit my @deck = @ranks X~ @suits; # create hash of card to points value my %points = @deck Z ( (2..10, 10, 10, 10, 11) X+ (0,0,0,0) ); # grab five cards from the deck my @hand = @deck.pick(5); # display my hand say ~@hand; # tell me how many points it's worth say [+] %points{@hand};
  • 72. @xyz»++ # increment all elements of @xyz @x = @a »min« @b # @x is smallest of @a and @b $mean = ([+] @a) / @a # calculate mean of @a $sumsq = [+] (@x »**» 2) # sum of squares of @x $fact = [*] 1..$n # $n factorial for %hash.kv -> $k, $v { say "$k: $v" }
  • 73. Example Module JSON::Tiny https://github.com/moritz/json
  • 74. module JSON::Tiny; proto to-json($) is export {*} multi to-json(Real:D $d) { ~$d } multi to-json(Bool:D $d) { $d ?? 'true' !! 'false'; } multi to-json(Str:D $d) {     '"'     ~ $d.trans(['"', '', "b", "f", "n", "r", "t"]             => ['"', '', 'b', 'f', 'n', 'r', 't'])             .subst(/<-[c32..c126]>/, { ord(~$_).fmt('u%04x') }, :g)     ~ '"' } multi to-json(Positional:D $d) {   return '[ ' ~ $d.map(&to-json).join(', ') ~ ' ]'; } multi to-json(Hash:D $d) { return '{ '~ $d.map({ to-json(.key)~' : '~to-json(.value) }).join(', ')~ ' }'; } multi to-json(Any:U $) { 'null' } multi to-json(Any:D $s) { die "Can't serialize an object of type "~$s.WHAT.perl} use JSON::Tiny::Actions; use JSON::Tiny::Grammar; sub from-json($text) is export {     my $a = JSON::Tiny::Actions.new();     my $o = JSON::Tiny::Grammar.parse($text, :actions($a));     return $o.ast; }
  • 75. grammar JSON::Tiny::Grammar; rule TOP { ^ [ <object> | <array> ] $ } rule object { '{' ~ '}' <pairlist> } rule pairlist { <?> <pair> * % , } rule pair { <?> <string> ':' <value> } rule array { '[' ~ ']' <arraylist> } rule arraylist { <?> <value>* % [ , ] } proto token value {*}; token value:sym<number> {     '-'?     [ 0 | <[1..9]> <[0..9]>* ]     [ . <[0..9]>+ ]?     [ <[eE]> [+|-]? <[0..9]>+ ]? } token value:sym<true> { <sym> }; token value:sym<false> { <sym> }; token value:sym<null> { <sym> }; token value:sym<object> { <object> }; token value:sym<array> { <array> }; token value:sym<string> { <string> } token string { " ~ " ( <str> | <str_escape> )* } token str { <-["tn]>+ } token str_escape { <["/bfnrt]> | u <xdigit>**4 }
  • 76. class JSON::Tiny::Actions; method TOP($/) { make $/.values.[0].ast }; method object($/) { make $<pairlist>.ast.hash } method pairlist($/) { make $<pair>>>.ast.flat } method pair($/) { make $<string>.ast => $<value>.ast } method array($/) { make $<arraylist>.ast } method arraylist($/) { make [$<value>>>.ast] } method string($/) {     make $0.elems == 1         ?? ($0[0].<str> || $0[0].<str_escape>).ast         !! join '', $0.list.map({ (.<str> || .<str_escape>).ast }); } method value:sym<number>($/) { make +$/.Str } method value:sym<string>($/) { make $<string>.ast } method value:sym<true>($/) { make Bool::True } method value:sym<false>($/) { make Bool::False } method value:sym<null>($/) { make Any } method value:sym<object>($/) { make $<object>.ast } method value:sym<array>($/) { make $<array>.ast } method str($/) { make ~$/ } method str_escape($/) {     if $<xdigit> {         make chr(:16($<xdigit>.join));     } else {         my %h = '' => "", '/' => "/", 'b' => "b", 'n' => "n", 't' => "t", 'f' => "f", 'r' => "r", '"' => """;         make %h{~$/};     } }
  • 77. Perl 6 Already full of awesome Hundreds of examples on http://rosettacode.org Developers happy to stay in stealth mode for now Get ahead of the revolution: http://perl6.org
  • 79. Perl has a massive library of reusable code has a culture of best practice and testing has a happy welcoming growing community has a great future in Perl 5 and Perl 6 is a great language for getting your job done for the last 25 years, and the next 25!
  • 80. Questions? See also http://www.slideshare.net/Tim.Bunce/perl-myths-200909 http://perlmonks.org http://search.cpan.org http://rakudo.org/how-to-help http://blog.timbunce.org @timbunce