def _add_cpu_usage(self, cur_read):
        """Compute cpu usage based on cpu time spent compared to elapsed time
        """

        for executor_id, cur_data in cur_read.items():
            if executor_id in self.executors_prev_read:
                prev_data = self.executors_prev_read[executor_id]
                prev_stats = prev_data['statistics']
                cur_stats = cur_data['statistics']
                # from sum of current cpus time subtract previous sum
                cpus_time_diff_s = cur_stats['cpus_user_time_secs']
                cpus_time_diff_s += cur_stats['cpus_system_time_secs']
                cpus_time_diff_s -= prev_stats['cpus_user_time_secs']
                cpus_time_diff_s -= prev_stats['cpus_system_time_secs']
                ts_diff = cur_stats['timestamp'] - prev_stats['timestamp']
                if ts_diff != 0:
                    cur_stats['cpus_utilisation'] = cpus_time_diff_s / ts_diff

            self.executors_prev_read[executor_id] = cur_read[executor_id]
Compute cpu usage based on cpu time spent compared to elapsed time
        
src/collectors/mesos/mesos.py