Line | Branch | Exec | Source |
---|---|---|---|
1 | |||
2 | /*************************************** | ||
3 | Auteur : Pierre Aubert | ||
4 | Mail : pierre.aubert@lapp.in2p3.fr | ||
5 | Licence : CeCILL-C | ||
6 | ****************************************/ | ||
7 | |||
8 | #include <unistd.h> | ||
9 | #include <iostream> | ||
10 | #include "PProfiler.h" | ||
11 | |||
12 | #define PROFILER_INDEX_someFunctionToProfile 0lu | ||
13 | |||
14 | ///Some function to profile | ||
15 | /** @param[out] prof : Profiler to be used (we are not obliged to pass the PProfiler, but it simplifies the function call) | ||
16 | */ | ||
17 | 800 | void someFunctionToProfile(PProfiler & prof){ | |
18 | 800 | prof.start(PROFILER_INDEX_someFunctionToProfile); | |
19 | //Let's do some stuff | ||
20 | 800 | usleep(1000); | |
21 | 800 | prof.stop(PROFILER_INDEX_someFunctionToProfile); | |
22 | 800 | } | |
23 | |||
24 | ///Test the PProfiler | ||
25 | /** @return true on success, false otherwise | ||
26 | */ | ||
27 | 1 | bool testProfiler(){ | |
28 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | PProfiler prof; |
29 | 1 | bool b(true); | |
30 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
|
1 | b &= prof.addFunction("someFunctionToProfile") == PROFILER_INDEX_someFunctionToProfile; |
31 | |||
32 | 1 | size_t nbLoop(10lu), nbCallPerLoop(40lu); | |
33 |
2/2✓ Branch 0 (17→10) taken 10 times.
✓ Branch 1 (17→18) taken 1 times.
|
11 | for(size_t i(0lu); i < nbLoop; ++i){ //Let's simulate some calls in a soft |
34 |
1/1✓ Branch 0 (10→11) taken 10 times.
|
10 | prof.print(); |
35 |
1/1✓ Branch 0 (11→12) taken 10 times.
|
10 | prof.reset(PROFILER_INDEX_someFunctionToProfile); //If we want to reset only this function |
36 |
2/2✓ Branch 0 (15→13) taken 400 times.
✓ Branch 1 (15→16) taken 10 times.
|
410 | for(size_t j(0lu); j < nbCallPerLoop; ++j){ //Let's simulate some calls in a soft |
37 |
1/1✓ Branch 0 (13→14) taken 400 times.
|
400 | someFunctionToProfile(prof); |
38 | } | ||
39 | } | ||
40 |
1/1✓ Branch 0 (18→19) taken 1 times.
|
1 | prof.print(); |
41 |
1/1✓ Branch 0 (19→20) taken 1 times.
|
1 | prof.reset(); //If we want to reset all functions of the PProfiler |
42 |
3/3✓ Branch 0 (20→21) taken 1 times.
✓ Branch 2 (21→22) taken 1 times.
✓ Branch 4 (22→23) taken 1 times.
|
1 | std::cout << "testProfiler : end profiling : b = " << b << std::endl; |
43 |
1/1✓ Branch 0 (23→24) taken 1 times.
|
1 | PProfiler prof2(prof); |
44 |
1/1✓ Branch 0 (24→25) taken 1 times.
|
1 | prof2.print(); |
45 |
1/1✓ Branch 0 (25→26) taken 1 times.
|
1 | PProfiler prof3; |
46 |
1/1✓ Branch 0 (26→27) taken 1 times.
|
1 | prof3 = prof; |
47 |
2/2✓ Branch 0 (29→30) taken 1 times.
✓ Branch 2 (30→31) taken 1 times.
|
1 | prof3.rename(PROFILER_INDEX_someFunctionToProfile, "renamedFunction"); |
48 |
1/1✓ Branch 0 (33→34) taken 1 times.
|
1 | prof3.print(); |
49 | |||
50 |
3/3✓ Branch 0 (34→35) taken 1 times.
✓ Branch 2 (35→36) taken 1 times.
✓ Branch 4 (36→37) taken 1 times.
|
1 | std::cout << "testProfiler : b = " << b << std::endl; |
51 | 1 | return true; | |
52 | 1 | } | |
53 | |||
54 | ///Test the PProfiler | ||
55 | /** @return true on success, false otherwise | ||
56 | */ | ||
57 | 1 | bool testProfilerCsv(){ | |
58 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | PProfiler prof; |
59 | 1 | bool b(true); | |
60 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
|
1 | b &= prof.addFunction("someFunctionToProfile", 0lu) == PROFILER_INDEX_someFunctionToProfile; |
61 |
1/1✓ Branch 0 (9→10) taken 1 times.
|
1 | prof.printCsvHeader(); |
62 | 1 | size_t nbLoop(10lu), nbCallPerLoop(40lu); | |
63 |
2/2✓ Branch 0 (18→11) taken 10 times.
✓ Branch 1 (18→19) taken 1 times.
|
11 | for(size_t i(0lu); i < nbLoop; ++i){ //Let's simulate some calls in a soft |
64 |
2/2✓ Branch 0 (14→12) taken 400 times.
✓ Branch 1 (14→15) taken 10 times.
|
410 | for(size_t j(0lu); j < nbCallPerLoop; ++j){ //Let's simulate some calls in a soft |
65 |
1/1✓ Branch 0 (12→13) taken 400 times.
|
400 | someFunctionToProfile(prof); |
66 | } | ||
67 |
1/1✓ Branch 0 (15→16) taken 10 times.
|
10 | prof.printCsv(); |
68 |
1/1✓ Branch 0 (16→17) taken 10 times.
|
10 | prof.reset(PROFILER_INDEX_someFunctionToProfile); //If we want to reset only this function |
69 | } | ||
70 |
3/3✓ Branch 0 (19→20) taken 1 times.
✓ Branch 2 (20→21) taken 1 times.
✓ Branch 4 (21→22) taken 1 times.
|
1 | std::cout << "testProfilerCsv : end profiling : b = " << b << std::endl; |
71 |
3/3✓ Branch 0 (22→23) taken 1 times.
✓ Branch 2 (23→24) taken 1 times.
✓ Branch 4 (24→25) taken 1 times.
|
1 | std::cout << "testProfilerCsv : b = " << b << std::endl; |
72 | 1 | return true; | |
73 | 1 | } | |
74 | |||
75 | ///Test the PFunctionPerf | ||
76 | /** @return true on success, false otherwise | ||
77 | */ | ||
78 | 1 | bool testPFunctionPerf(){ | |
79 |
3/3✓ Branch 0 (4→5) taken 1 times.
✓ Branch 2 (5→6) taken 1 times.
✓ Branch 4 (11→12) taken 1 times.
|
3 | PFunctionPerf fct("Some Function"), fct2; |
80 |
1/1✓ Branch 0 (14→15) taken 1 times.
|
1 | fct2 = fct; |
81 | 1 | bool b(true); | |
82 |
2/2✓ Branch 0 (15→16) taken 1 times.
✓ Branch 2 (16→17) taken 1 times.
|
1 | b &= fct.getName() == fct2.getName(); |
83 |
3/3✓ Branch 0 (18→19) taken 1 times.
✓ Branch 2 (19→20) taken 1 times.
✓ Branch 4 (20→21) taken 1 times.
|
1 | std::cout << "testPFunctionPerf : b = " << b << std::endl; |
84 | 1 | return true; | |
85 | 1 | } | |
86 | |||
87 | |||
88 | 1 | int main(int argc, char** argv){ | |
89 | 1 | bool b(true); | |
90 | 1 | b &= testProfiler(); | |
91 | 1 | b &= testProfilerCsv(); | |
92 | 1 | b &= testPFunctionPerf(); | |
93 | 1 | std::cout << "Final : b = " << b << std::endl; | |
94 | 1 | return b - 1; | |
95 | } | ||
96 | |||
97 | |||
98 |