RES: CPU utilization
Fabrício de Novaes Kucinskis
fabricio.kucinskis at inpe.br
Thu Jul 12 16:10:16 UTC 2018
Hi Mathew and Joel,
On the past, I’ve used the following code to get individual task usage and monitor tasks behavior through time. It’s completely based on rtems_cpu_usage_report_with_plugin and I know it’s not the best way to do it, but worked for me 😊.
Regards,
Fabrício.
/**
* Returns the task usage in us. If the taskId is zero, returns the time since boot.
* Code based on ‘rtems_cpu_usage_report_with_plugin’.
**/
uint64_t TasksStatusList::GetCpuUsagePerTask(const rtems_id &taskId)
{
if (taskId == 0)
{
struct timespec uptime;
struct timespec total;
rtems_clock_get_uptime(&uptime);
_Timespec_Subtract(&CPU_usage_Uptime_at_last_reset, &uptime, &total);
uint64_t totalCpuUsageInUs = (total.tv_sec * static_cast<uint64_t>(1000000)) + (total.tv_nsec / static_cast<uint64_t>(1000));
return totalCpuUsageInUs;
}
else
{
Objects_Information *ptObjInformation = NULL;
Thread_Control *ptThread = NULL;
Thread_CPU_usage_t timeRan;
for (uint32_t i = 1; i <= OBJECTS_APIS_LAST; i++)
{
if (!_Objects_Information_table[i])
{
continue; // that’s ugly, but it works
}
ptObjInformation = _Objects_Information_table[i][1];
if (ptObjInformation != NULL)
{
for (uint32_t j = 1; j <= ptObjInformation->maximum; j++)
{
ptThread = reinterpret_cast<Thread_Control *>(ptObjInformation->local_table[j]);
if (ptThread == NULL)
{
continue; // still ugly, still works
}
// if the caller task asks for its own cpu usage, the time since the last context switch will not be computed
if (ptThread->Object.id == taskId)
{
timeRan = ptThread->cpu_time_used;
uint64_t cpuUsageInUs = (_Timestamp_Get_seconds(&timeRan) * static_cast<uint64_t>(1000000)) + (_Timestamp_Get_nanoseconds(&timeRan) / static_cast<uint64_t>(1000));
return cpuUsageInUs;
}
}
}
}
// if the rtemsId doesn’t exist...
return 0;
}
}
De: users [mailto:users-bounces at rtems.org] Em nome de Joel Sherrill
Enviada em: quinta-feira, 12 de julho de 2018 11:37
Para: Mathew Benson <mbenson at windhoverlabs.com>
Cc: RTEMS <rtems-users at rtems.org>
Assunto: Re: CPU utilization
On Tue, Jul 10, 2018 at 2:30 PM, Mathew Benson < <mailto:mbenson at windhoverlabs.com> mbenson at windhoverlabs.com> wrote:
What would be the recommend way to read CPU utilization? Am I correct in saying, the best way would be to call rtems_cpu_usage_report_with_plugin()? Its ill advised to access the private symbols utilized by the rtems_cpu_usage_report_with_plugin() call directly, right? Is there another function that I can call to return a structure rather than parsing it with the rtems_printer plugin? I haven't dug into the rtems_printer object yet, but I'm assuming I could use it and parse a string sent to it.
Yes. You could use the printer_object passed in to parse it.
There isn't a call to get this information (yet) and similarly, there isn't an
API to get the stack usage.
Proposals and code welcomed. :)
--joel
--
Mathew Benson
CEO | Chief Engineer
Windhover Labs, LLC
832-640-4018
<https://drive.google.com/a/windhoverlabs.com/uc?id=1cLDczWESrU667xKgEJlFhHa2yjq5UVhJ&export=download>
<http://www.windhoverlabs.com> www.windhoverlabs.com
_______________________________________________
users mailing list
<mailto:users at rtems.org> users at rtems.org
<http://lists.rtems.org/mailman/listinfo/users> http://lists.rtems.org/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20180712/16e50201/attachment-0002.html>
More information about the users
mailing list