diff --git a/.gitignore b/.gitignore index 256db9f..7f36e7f 100644 --- a/.gitignore +++ b/.gitignore @@ -58,10 +58,19 @@ doc/**/*.pdf build src/03-led-controller/led-controller -src/04-multiprocessing/process +src/04-multiprocessing/multiprocessing src/04-multiprocessing/cgroups src/04-multiprocessing/max-cpu src/05-optimization/ex01/basic src/05-optimization/ex01/optimized src/05-optimization/ex02/optimized src/05-optimization/ex02/basic + +src/05-optimization/ex03/ApacheAccessLogAnalyzer.d +src/05-optimization/ex03/ApacheAccessLogAnalyzer.o +src/05-optimization/ex03/HostCounter.d +src/05-optimization/ex03/HostCounter.o +src/05-optimization/ex03/main.d +src/05-optimization/ex03/main.d +src/05-optimization/ex03/perf.data +src/05-optimization/ex03/read-apache-logs \ No newline at end of file diff --git a/doc/lab05-optimization/command-after-optimization.png b/doc/lab05-optimization/command-after-optimization.png new file mode 100644 index 0000000..91bf305 Binary files /dev/null and b/doc/lab05-optimization/command-after-optimization.png differ diff --git a/doc/lab05-optimization/main.typ b/doc/lab05-optimization/main.typ index 9d95ba6..553f67c 100644 --- a/doc/lab05-optimization/main.typ +++ b/doc/lab05-optimization/main.typ @@ -7,26 +7,6 @@ In this laboratory, the usage of `perf` as tool is experimented. == Exercise 1 -``` -Performance counter stats for './ex1': - - 40609.10 msec task-clock # 1.000 CPUs utilized - 22 context-switches # 0.542 /sec - 0 cpu-migrations # 0.000 /sec - 48867 page-faults # 1.203 K/sec - 33136692484 cycles # 0.816 GHz - 1671194529 instructions # 0.05 insn per cycle - 269592231 branches # 6.639 M/sec - 1013366 branch-misses # 0.38% of all branches - - 40.618926728 seconds time elapsed - - 39.901620000 seconds user - 0.296158000 seconds sys - -``` -This program has done 22 context-switches and has 40.6s elapsed. - #task([ Measure the performance of the ex1 ],[ @@ -238,16 +218,6 @@ The same test was done with the `-01` compiler flag and there is almost no diffe == Exercise 3 -```bash -$ perf record --call-graph dwarf -e cpu-clock -F 75 ./read-apache-logs access_log_NASA_Jul95_samples -Couldn't synthesize bpf events. -Processing log file access_log_NASA_Jul95_samples -Found 14867 unique Hosts/IPs -[ perf record: Woken up 335 times to write data ] -[ perf record: Captured and wrote 83.687 MB perf.data (10269 samples) ] - -``` - The only line were there is a comparison of 2 element with the `==` operator is : ```c bool HostCounter::isNewHost(std::string hostname) @@ -256,7 +226,7 @@ bool HostCounter::isNewHost(std::string hostname) } ``` -The program check if the host is already in the vector. It shows that this operation on `vector` is slow. +The program check if the host is already in the vector. It shows that this operation on `vector` is slow. As the output shows below: ``` # time ./read-apache-logs access_log_NASA_Jul95_samples @@ -268,4 +238,42 @@ sys 0m 0.12s ``` -This collections library need to be transform in `set` collections to be faster. \ No newline at end of file +This collections library need to be transform in `set` collections to be faster. + + +#figure( + image("command-after-optimization.png"), + caption:[`perf` report after optimization] +) + +After changing the collection, the result can be observe by doing the report in @command-opti. The execution time has been significantly reduced as the output below: + + +``` +# time ./read-apache-logs access_log_NASA_Jul95_samples +Processing log file access_log_NASA_Jul95_samples +Found 14867 unique Hosts/IPs +real 0m 1.55s +user 0m 1.36s +sys 0m 0.10s +``` + +The performance of the `set` are really higher. It makes a huge gap with the vector with 2m15s. + + +Finally, if the whole log file is read with 2 millions of inputs: +``` +# time ./read-apache-logs access_log_NASA_Jul95 +askljdalksjda +Processing log file access_log_NASA_Jul95 +Found 81983 unique Hosts/IPs +real 0m 14.76s +user 0m 13.90s +sys 0m 0.68s +``` + + +#task([Measure interruption latency and jitter], [ + The hardware approach is chosen with an oscilloscop and a square-wave generator. + Fist, the generator toggle a pin of the processor. The routine interruption starts. Then, another pin make a pulse and it is meassured by an oscilloscope. The latency is the delay between the generator rising edge and the rising edge of the pulse inside the interruption. The jitter can be measured by repeating the measure of the latency. Finally, it appears the variation of the latency which is the jitter. +]) diff --git a/solutions/06_optimization/ex03/HostCounter.cpp b/solutions/06_optimization/ex03/HostCounter.cpp index 99a5d5b..bb78079 100644 --- a/solutions/06_optimization/ex03/HostCounter.cpp +++ b/solutions/06_optimization/ex03/HostCounter.cpp @@ -16,7 +16,7 @@ void HostCounter::notifyHost(std::string hostname) // add the host in the list if not already in if(isNewHost(hostname)) { - myHosts.push_back(hostname); + myHosts.insert(hostname); } } diff --git a/solutions/06_optimization/ex03/HostCounter.h b/solutions/06_optimization/ex03/HostCounter.h index d627d02..955e516 100644 --- a/solutions/06_optimization/ex03/HostCounter.h +++ b/solutions/06_optimization/ex03/HostCounter.h @@ -1,6 +1,6 @@ #include -#include +#include class HostCounter { @@ -18,5 +18,5 @@ class HostCounter // check if host is already in the list bool isNewHost(std::string hostname); - std::vector< std::string > myHosts; + std::set< std::string > myHosts; }; diff --git a/src/05-optimization/ex03/HostCounter.cpp b/src/05-optimization/ex03/HostCounter.cpp index 99a5d5b..f4ddfcd 100644 --- a/src/05-optimization/ex03/HostCounter.cpp +++ b/src/05-optimization/ex03/HostCounter.cpp @@ -8,7 +8,7 @@ HostCounter::HostCounter() bool HostCounter::isNewHost(std::string hostname) { - return std::find(myHosts.begin(), myHosts.end(), hostname) == myHosts.end(); + return myHosts.find(hostname) == myHosts.end(); } void HostCounter::notifyHost(std::string hostname) @@ -16,7 +16,7 @@ void HostCounter::notifyHost(std::string hostname) // add the host in the list if not already in if(isNewHost(hostname)) { - myHosts.push_back(hostname); + myHosts.insert(hostname); } } diff --git a/src/05-optimization/ex03/HostCounter.h b/src/05-optimization/ex03/HostCounter.h index d627d02..955e516 100644 --- a/src/05-optimization/ex03/HostCounter.h +++ b/src/05-optimization/ex03/HostCounter.h @@ -1,6 +1,6 @@ #include -#include +#include class HostCounter { @@ -18,5 +18,5 @@ class HostCounter // check if host is already in the list bool isNewHost(std::string hostname); - std::vector< std::string > myHosts; + std::set< std::string > myHosts; };