Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - How to get performance metrics from API: (6 Items)
   
How to get performance metrics from API  
I would like to monitor my process's memory utilization and CPU utilization from the C API. There's an extremely limited
 implementation of POSIX getrusage(), but I was unable to find another obvious API for doing this. I'll use /proc/ in 
Linux, but QNX's /proc is very sparse compared to Linux's and doesn't have the information I need.

How would I go about doing this? Thanks!
Re: How to get performance metrics from API  
The getrusage() function should give you the process run times. I'm not sure why it was never extended to provide 
information beyond that.
Memory usage is a much trickier subject, as no single number can encompass the notion of "usage". If you look under /
proc/<PID>/vmstat you will see different numbers corresponding to the amount of virtual address space used, how much of 
it is private as opposed to shared, how much private memory was reserved for the process, etc.
I did add an API to get this information programmatically a couple of years ago, but it looks like it hasn't been part 
of any release yet.

--Elad
________________________________________
From: Jason Tiller(deleted) <community-noreply@qnx.com>
Sent: 11 March 2020 21:55:33
To: ostech-core_os
Subject: How to get performance metrics from API

I would like to monitor my process's memory utilization and CPU utilization from the C API. There's an extremely limited
 implementation of POSIX getrusage(), but I was unable to find another obvious API for doing this. I'll use /proc/ in 
Linux, but QNX's /proc is very sparse compared to Linux's and doesn't have the information I need.

How would I go about doing this? Thanks!



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post120363
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com
Re: How to get performance metrics from API  
I am wondering that the procfs DCMD control codes could not be used to obtain that information?
Re: How to get performance metrics from API  
Not the existing ones, unless you are willing to get all mappings and then accumulate the results.
You can see what these do if you cat '/proc/<pid>/pmap' (per region) and '/proc/<pid>/mappings' (per page).

--Elad
________________________________________
From: Albrecht Uhlmann <community-noreply@qnx.com>
Sent: 12 March 2020 08:00:46
To: ostech-core_os
Subject: Re: How to get performance metrics from API

I am wondering that the procfs DCMD control codes could not be used to obtain that information?



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post120365
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com
Re: How to get performance metrics from API  
Hi, Elad,

Thank you for replying.

> The getrusage() function should give you the process run times. I'm not sure 
> why it was never extended to provide information beyond that.

I would like to receive the usage time for my process's children, as well. getrusage() documentation says this:

"Which process to get the usage for:

    RUSAGE_CHILDREN — get information about resources used by the terminated and waited-for children of the current 
process. If the child is never waited for (e.g., if the parent has SA_NOCLDWAIT set, or sets SIGCHLD to SIG_IGN), the 
resource information for the child process is discarded and isn't included. "

It appears that all children are accumulated into one result - is that correct? There's no way for me to query the usage
 by PID for an individual child?

> Memory usage is a much trickier subject, as no single number can encompass the
>  notion of "usage". If you look under /proc/<PID>/vmstat you will see different 
> numbers corresponding to the amount of virtual address space used, how much of
>  it is private as opposed to shared, how much private memory was reserved for 
> the process, etc.

I'm not looking for a precise measurement but a coarse method to show the change in memory allocation over time. I'm 
trying to show trends (memory leakage) and perhaps spikes (large changes in allocation) in applications that are 
effectively daemons and are always running. In this scenario, I'm writing something akin to Unix 'init' and spawning 
child processes at startup that I then want to monitor.

The getrusage has some conflicting info. It describes various members of the struct:

"ru_idrss
    An “integral” value indicating the amount of memory in use by a process while the process is running. This value 
is the sum of the resident set sizes of the process running when a clock tick occurs. The value is given in pages times 
clock ticks. It doesn't take sharing into account. See the Caveats section, below."

Then in the Caveats it says:

"Only the timeval fields of struct rusage are supported."

Caveats then goes on to describe the inner workings of some other fields... but I can't tell if they're actually 
supported or not.

Is ru_idrss something I could use?

Thanks again,

---Jason
Re: How to get performance metrics from API  
You're right, there isn't a universally portable C API for monitoring process memory and CPU utilization. However, for 
Linux you can definitely leverage the /proc filesystem.

Here's how to monitor your process's memory utilization and CPU utilization on Linux using /proc:

1. Memory Utilization:

    a. Read the contents of the virtual memory statistic file /proc/self/statm. This file contains information about the
 memory usage of the process.

2. CPU Utilization:

    a. You can't access your process's specific CPU utilization from /proc. However, you can get system-wide CPU usage 
statistics by reading files like /proc/stat or /proc/loadavg.

Monitor Linux Process Memory Usage Using C/C++: https://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-
runtime-using-c

For a more comprehensive approach that might involve fetching data from various sources and platforms, consider using 
B2B data providers and their APIs. B2B data providers offer business data that can be integrated into your application 
using APIs (Application Programming Interfaces).  This data can include business contact information, firmography data, 
and even industry trends, depending on the provider.  By leveraging B2B data APIs, you can enrich your application with 
valuable business insights and potentially improve your application's functionality.  See this article for more details 
on using B2B data integration APIs: B2B Data Integration APIs for Your App: https://www.globaldatabase.com/why-use-b2b-
data-providers-apis-when-building-your-app