ADD cpu logger
This commit is contained in:
		| @@ -22,3 +22,7 @@ Test sensor libraries : | |||||||
| ```terminal | ```terminal | ||||||
| mbed test -m DISCO_H747I -t GCC_ARM -n advdembsof_library-tests-sensors-hdc1000 --compile --run | mbed test -m DISCO_H747I -t GCC_ARM -n advdembsof_library-tests-sensors-hdc1000 --compile --run | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
|  | # Some questions | ||||||
|  | ## If you print CPU statistics at the end of every major cycle (in the super-loop), what CPU usage do you observe? How can you explain the observed CPU uptime? | ||||||
|  | We observe a 100% usage because on each CPU cycle it compare if time is done.  | ||||||
| @@ -14,6 +14,7 @@ | |||||||
|         "platform.stdio-baud-rate": 115200, |         "platform.stdio-baud-rate": 115200, | ||||||
|         "platform.default-serial-baud-rate": 115200, |         "platform.default-serial-baud-rate": 115200, | ||||||
|         "platform.stdio-buffered-serial": true, |         "platform.stdio-buffered-serial": true, | ||||||
|  |         "platform.all-stats-enabled": true, | ||||||
|         "target.printf_lib":"minimal-printf", |         "target.printf_lib":"minimal-printf", | ||||||
|         "platform.minimal-printf-enable-floating-point": true, |         "platform.minimal-printf-enable-floating-point": true, | ||||||
|         "platform.minimal-printf-set-floating-point-max-decimals": 2 |         "platform.minimal-printf-set-floating-point-max-decimals": 2 | ||||||
|   | |||||||
| @@ -54,13 +54,13 @@ static constexpr std::chrono::milliseconds kDisplayTask2Period 				 = 1600ms; | |||||||
| static constexpr std::chrono::milliseconds kDisplayTask2Delay 				 = 1200ms; | static constexpr std::chrono::milliseconds kDisplayTask2Delay 				 = 1200ms; | ||||||
| static constexpr std::chrono::milliseconds kDisplayTask2ComputationTime   	 = 100ms; | static constexpr std::chrono::milliseconds kDisplayTask2ComputationTime   	 = 100ms; | ||||||
|  |  | ||||||
| // TODO: implement the constructor |  | ||||||
|  |  | ||||||
| BikeSystem::BikeSystem() : | BikeSystem::BikeSystem() : | ||||||
| 	_gearDevice(_timer), | 	_gearDevice(_timer), | ||||||
|     _pedalDevice(_timer), |     _pedalDevice(_timer), | ||||||
|     _resetDevice(_timer), |     _resetDevice(_timer), | ||||||
| 	_speedometer(_timer) | 	_speedometer(_timer), | ||||||
|  |     _cpuLogger(_timer) | ||||||
| { | { | ||||||
|  |  | ||||||
| } | } | ||||||
| @@ -70,13 +70,9 @@ void BikeSystem::start() { | |||||||
|  |  | ||||||
|     init(); |     init(); | ||||||
|  |  | ||||||
|     // TODO: implement the super-loop based for implementing the appropriate schedule |  | ||||||
|     // Done |  | ||||||
|     while (true) { |     while (true) { | ||||||
|         auto startTime = _timer.elapsed_time(); |         auto startTime = _timer.elapsed_time(); | ||||||
|  |  | ||||||
|         // TODO: implement calls to different tasks based on computed schedule |  | ||||||
|         // Done |  | ||||||
|         gearTask();				// 100ms :    0ms ->  100ms |         gearTask();				// 100ms :    0ms ->  100ms | ||||||
|         speedDistanceTask();	// 200ms :  100ms ->  300ms |         speedDistanceTask();	// 200ms :  100ms ->  300ms | ||||||
|         displayTask1();			// 200ms :  300ms ->  500ms |         displayTask1();			// 200ms :  300ms ->  500ms | ||||||
| @@ -106,6 +102,10 @@ void BikeSystem::start() { | |||||||
|             break; |             break; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         #if !defined(MBED_TEST_MODE) | ||||||
|  |         	_cpuLogger.printStats(); | ||||||
|  |         #endif | ||||||
|  |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -144,7 +144,8 @@ void BikeSystem::gearTask() { | |||||||
|     _currentGearSize = _gearDevice.getCurrentGearSize(); |     _currentGearSize = _gearDevice.getCurrentGearSize(); | ||||||
|  |  | ||||||
|     _taskLogger.logPeriodAndExecutionTime( |     _taskLogger.logPeriodAndExecutionTime( | ||||||
|         _timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime); |         _timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime | ||||||
|  |     ); | ||||||
| } | } | ||||||
|  |  | ||||||
| void BikeSystem::speedDistanceTask() { | void BikeSystem::speedDistanceTask() { | ||||||
| @@ -159,7 +160,8 @@ void BikeSystem::speedDistanceTask() { | |||||||
|     _traveledDistance = _speedometer.getDistance(); |     _traveledDistance = _speedometer.getDistance(); | ||||||
|  |  | ||||||
|     _taskLogger.logPeriodAndExecutionTime( |     _taskLogger.logPeriodAndExecutionTime( | ||||||
|         _timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime); |         _timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime | ||||||
|  |     ); | ||||||
| } | } | ||||||
|  |  | ||||||
| void BikeSystem::temperatureTask() { | void BikeSystem::temperatureTask() { | ||||||
|   | |||||||
| @@ -27,6 +27,7 @@ | |||||||
| // from advembsof | // from advembsof | ||||||
| #include "display_device.hpp" | #include "display_device.hpp" | ||||||
| #include "task_logger.hpp" | #include "task_logger.hpp" | ||||||
|  | #include "cpu_logger.hpp" | ||||||
|  |  | ||||||
| // from common | // from common | ||||||
| #include "sensor_device.hpp" | #include "sensor_device.hpp" | ||||||
| @@ -93,6 +94,9 @@ class BikeSystem { | |||||||
|  |  | ||||||
|     // used for logging task info |     // used for logging task info | ||||||
|     advembsof::TaskLogger _taskLogger; |     advembsof::TaskLogger _taskLogger; | ||||||
|  |  | ||||||
|  |     // cpu logger to measure cpu usage | ||||||
|  |     advembsof::CPULogger _cpuLogger; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| }  // namespace static_scheduling | }  // namespace static_scheduling | ||||||
		Reference in New Issue
	
	Block a user