| 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 <thread> | ||
| 11 | #include "PProfiler.h" | ||
| 12 | |||
| 13 | #define PROFILER_INDEX_someFunctionToProfile 0lu | ||
| 14 | |||
| 15 | ///Some function to profile | ||
| 16 | /** @param[out] prof : Profiler to be used (we are not obliged to pass the PProfiler, but it simplifies the function call) | ||
| 17 | * @param threadIndex : index of the current thread | ||
| 18 | */ | ||
| 19 | 3196 | void someFunctionToProfile(PProfiler & prof, size_t threadIndex){ | |
| 20 | 3196 | prof.start(PROFILER_INDEX_someFunctionToProfile, threadIndex); | |
| 21 | //Let's do some stuff | ||
| 22 | 3197 | usleep(1000); | |
| 23 | 3200 | prof.stop(PROFILER_INDEX_someFunctionToProfile, threadIndex); | |
| 24 | 3196 | } | |
| 25 | |||
| 26 | ///Some thread function | ||
| 27 | /** @param[out] prof : Profiler to be used (we are not obliged to pass the PProfiler, but it simplifies the function call) | ||
| 28 | * @param threadIndex : index of the current thread | ||
| 29 | */ | ||
| 30 | 8 | void threadCallFunction(PProfiler & prof, size_t threadIndex){ | |
| 31 | 8 | size_t nbLoop(10lu), nbCallPerLoop(40lu); | |
| 32 |
2/2✓ Branch 0 (8→3) taken 80 times.
✓ Branch 1 (8→9) taken 8 times.
|
88 | for(size_t i(0lu); i < nbLoop; ++i){ //Let's simulate some calls in a soft |
| 33 |
2/2✓ Branch 0 (6→4) taken 3196 times.
✓ Branch 1 (6→7) taken 80 times.
|
3276 | for(size_t j(0lu); j < nbCallPerLoop; ++j){ //Let's simulate some calls in a soft |
| 34 | 3196 | someFunctionToProfile(prof, threadIndex); | |
| 35 | } | ||
| 36 | } | ||
| 37 | 8 | } | |
| 38 | |||
| 39 | ///Test the PProfiler | ||
| 40 | /** @return true on success, false otherwise | ||
| 41 | */ | ||
| 42 | 1 | bool testProfiler(){ | |
| 43 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | PProfiler prof; |
| 44 | 1 | bool b(true); | |
| 45 | 1 | size_t nbThread(4lu); | |
| 46 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
|
1 | b &= prof.addFunction("someFunctionToProfile", nbThread) == PROFILER_INDEX_someFunctionToProfile; |
| 47 | |||
| 48 | 1 | std::vector<std::thread> vecThread; | |
| 49 |
1/1✓ Branch 0 (10→11) taken 1 times.
|
1 | vecThread.resize(nbThread); |
| 50 | |||
| 51 |
2/2✓ Branch 0 (18→12) taken 4 times.
✓ Branch 1 (18→19) taken 1 times.
|
5 | for(size_t i(0lu); i < nbThread; ++i){ |
| 52 |
1/1✓ Branch 0 (13→14) taken 4 times.
|
4 | vecThread[i] = std::thread(threadCallFunction, std::ref(prof), i); |
| 53 | } | ||
| 54 |
2/2✓ Branch 0 (23→20) taken 4 times.
✓ Branch 1 (23→24) taken 1 times.
|
5 | for(size_t i(0lu); i < nbThread; ++i){ |
| 55 |
1/1✓ Branch 0 (21→22) taken 4 times.
|
4 | vecThread[i].join(); |
| 56 | } | ||
| 57 |
1/1✓ Branch 0 (24→25) taken 1 times.
|
1 | prof.print(); |
| 58 |
1/1✓ Branch 0 (25→26) taken 1 times.
|
1 | prof.reset(); //If we want to reset all functions of the PProfiler |
| 59 |
3/3✓ Branch 0 (26→27) taken 1 times.
✓ Branch 2 (27→28) taken 1 times.
✓ Branch 4 (28→29) taken 1 times.
|
1 | std::cout << "testProfiler : end profiling : b = " << b << std::endl; |
| 60 |
1/1✓ Branch 0 (29→30) taken 1 times.
|
1 | PProfiler prof2(prof); |
| 61 |
1/1✓ Branch 0 (30→31) taken 1 times.
|
1 | prof2.print(); |
| 62 |
1/1✓ Branch 0 (31→32) taken 1 times.
|
1 | PProfiler prof3; |
| 63 |
1/1✓ Branch 0 (32→33) taken 1 times.
|
1 | prof3 = prof; |
| 64 |
2/2✓ Branch 0 (35→36) taken 1 times.
✓ Branch 2 (36→37) taken 1 times.
|
1 | prof3.rename(PROFILER_INDEX_someFunctionToProfile, "renamedFunction"); |
| 65 |
1/1✓ Branch 0 (39→40) taken 1 times.
|
1 | prof3.print(); |
| 66 | |||
| 67 |
3/3✓ Branch 0 (40→41) taken 1 times.
✓ Branch 2 (41→42) taken 1 times.
✓ Branch 4 (42→43) taken 1 times.
|
1 | std::cout << "testProfiler : b = " << b << std::endl; |
| 68 | 1 | return true; | |
| 69 | 1 | } | |
| 70 | |||
| 71 | ///Test the PProfiler | ||
| 72 | /** @return true on success, false otherwise | ||
| 73 | */ | ||
| 74 | 1 | bool testProfilerCsv(){ | |
| 75 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | PProfiler prof; |
| 76 | 1 | bool b(true); | |
| 77 | 1 | size_t nbThread(4lu); | |
| 78 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
|
1 | b &= prof.addFunction("someFunctionToProfile", nbThread) == PROFILER_INDEX_someFunctionToProfile; |
| 79 |
1/1✓ Branch 0 (9→10) taken 1 times.
|
1 | prof.printCsvHeader(); |
| 80 | |||
| 81 | 1 | std::vector<std::thread> vecThread; | |
| 82 |
1/1✓ Branch 0 (11→12) taken 1 times.
|
1 | vecThread.resize(nbThread); |
| 83 |
2/2✓ Branch 0 (19→13) taken 4 times.
✓ Branch 1 (19→20) taken 1 times.
|
5 | for(size_t i(0lu); i < nbThread; ++i){ |
| 84 |
1/1✓ Branch 0 (14→15) taken 4 times.
|
4 | vecThread[i] = std::thread(threadCallFunction, std::ref(prof), i); |
| 85 | } | ||
| 86 |
2/2✓ Branch 0 (24→21) taken 4 times.
✓ Branch 1 (24→25) taken 1 times.
|
5 | for(size_t i(0lu); i < nbThread; ++i){ |
| 87 |
1/1✓ Branch 0 (22→23) taken 4 times.
|
4 | vecThread[i].join(); |
| 88 | } | ||
| 89 |
1/1✓ Branch 0 (25→26) taken 1 times.
|
1 | prof.printCsv(); |
| 90 |
3/3✓ Branch 0 (26→27) taken 1 times.
✓ Branch 2 (27→28) taken 1 times.
✓ Branch 4 (28→29) taken 1 times.
|
1 | std::cout << "testProfilerCsv : end profiling : b = " << b << std::endl; |
| 91 |
3/3✓ Branch 0 (29→30) taken 1 times.
✓ Branch 2 (30→31) taken 1 times.
✓ Branch 4 (31→32) taken 1 times.
|
1 | std::cout << "testProfilerCsv : b = " << b << std::endl; |
| 92 | 1 | return true; | |
| 93 | 1 | } | |
| 94 | |||
| 95 | |||
| 96 | 1 | int main(int argc, char** argv){ | |
| 97 | 1 | bool b(true); | |
| 98 | 1 | b &= testProfiler(); | |
| 99 | 1 | b &= testProfilerCsv(); | |
| 100 | 1 | std::cout << "Final : b = " << b << std::endl; | |
| 101 | 1 | return b - 1; | |
| 102 | } | ||
| 103 | |||
| 104 | |||
| 105 |