| 1 | package DashProfiler::UserGuide; | ||
| 2 | use strict; | ||
| 3 | our $VERSION = sprintf("1.%06d", q$Revision: 44 $ =~ /(\d+)/o); | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | DashProfiler::UserGuide - a user guide for the DashProfiler modules | ||
| 8 | |||
| 9 | =head1 INTRODUCTION | ||
| 10 | |||
| 11 | The DashProfiler modules provide an efficient, simple, flexible, and powerful | ||
| 12 | way to collect aggregate timing (performance) information for your code. | ||
| 13 | |||
| 14 | =head1 CONCEPTS | ||
| 15 | |||
| 16 | B<DashProfiler::Core> | ||
| 17 | |||
| 18 | The core of DashProfiler are DashProfiler::Core objects, naturally. | ||
| 19 | |||
| 20 | DashProfiler::Core | ||
| 21 | |||
| 22 | B<DashProfiler> | ||
| 23 | |||
| 24 | The L<DashProfiler> module provides a by-name interface to L<DashProfiler::Core> objects | ||
| 25 | to avoid needing to manage object references yourself. Most DashProfiler::Core | ||
| 26 | instance methods have corresponding DashProfiler static methods that take a profiler name | ||
| 27 | as the first argument. | ||
| 28 | |||
| 29 | DashProfiler | ||
| 30 | | | ||
| 31 | v | ||
| 32 | DashProfiler::Core | ||
| 33 | |||
| 34 | B<DBI::Profile> | ||
| 35 | |||
| 36 | Behind the scenes, DashProfiler::Core uses L<DBI::Profile> to efficiently aggregate timing samples. | ||
| 37 | |||
| 38 | DashProfiler | ||
| 39 | | | ||
| 40 | v | ||
| 41 | DashProfiler::Core --> DBI::Profile | ||
| 42 | |||
| 43 | DBI::Profile aggregates timing samples into a tree structure. | ||
| 44 | |||
| 45 | By default DashProfiler::Core arranges for the samples to be aggregated into a | ||
| 46 | tree with two levels. We refer to these as C<context1> and C<context2>. | ||
| 47 | |||
| 48 | You provide values for these that make the most sense for you and your | ||
| 49 | application. For example, context1 might a type of network service and | ||
| 50 | context2 might be the specific host name being used to provide that service. | ||
| 51 | |||
| 52 | B<DashProfiler::Sample> | ||
| 53 | |||
| 54 | To add timing samples you need to use a Sampler. A Sampler is a code reference | ||
| 55 | that I<when called> creates a new L<DashProfiler::Sample> object and returns a | ||
| 56 | reference to it. Samplers are factories for creating samples. The Sampler code | ||
| 57 | reference is customized (curried) to contain the value for C<context1> to be | ||
| 58 | used for the created DashProfiler::Sample. | ||
| 59 | |||
| 60 | Samplers are created using the prepare() method of DashProfiler::Core or | ||
| 61 | DashProfiler (which is just a by-name wrapper for DashProfiler::Core). | ||
| 62 | |||
| 63 | DashProfiler | ||
| 64 | | | ||
| 65 | v | ||
| 66 | .----------- DashProfiler::Core --> DBI::Profile | ||
| 67 | v ^ | ||
| 68 | sampler code ref -. | | ||
| 69 | sampler code ref ---> DashProfiler::Sample | ||
| 70 | sampler code ref -' | ||
| 71 | |||
| 72 | Each time you call the Sampler code reference you pass it a value for C<context2> to | ||
| 73 | be used for I<this> sample and it returns a new DashProfiler::Sample object | ||
| 74 | containing the relevant information, including the exact time it was created. | ||
| 75 | |||
| 76 | When that DashProfiler::Sample object is destroyed, typically by going out of | ||
| 77 | scope, it adds a timing sample to all the DBI::Profile objects attached to the | ||
| 78 | Core it's associated with. The timing is from object creation to object destruction. | ||
| 79 | |||
| 80 | B<DashProfiler::Import> | ||
| 81 | |||
| 82 | The L<DashProfiler::Import> module lets you create and import customized | ||
| 83 | Sampler code references at load-time as if they were ordinary functions. | ||
| 84 | |||
| 85 | DashProfiler::Import <--- DashProfiler | ||
| 86 | | | | ||
| 87 | | | | ||
| 88 | | v | ||
| 89 | | DashProfiler::Core --> DBI::Profile | ||
| 90 | v ^ | ||
| 91 | sampler function -. | | ||
| 92 | sampler function ---> DashProfiler::Sample | ||
| 93 | sampler function -' | ||
| 94 | |||
| 95 | B<DashProfiler::Auto> | ||
| 96 | |||
| 97 | The L<DashProfiler::Auto> module gives you a simple way to start using DashProfiler. | ||
| 98 | It creates a DashProfiler called 'auto' with a useful default configuration. | ||
| 99 | It also uses L<DashProfiler::Import> to import an auto_profiler() sampler function | ||
| 100 | pre-configured with the name of the source file it's imported into. | ||
| 101 | |||
| 102 | =head2 Where next? | ||
| 103 | |||
| 104 | Experimenting with L<DashProfiler::Auto> is a good place to start. | ||
| 105 | |||
| 106 | =cut |