linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Monitoring a program
@ 2004-03-01 18:22 Llfrg
  2004-03-01 21:38 ` John T. Williams
  2004-03-01 22:34 ` Glynn Clements
  0 siblings, 2 replies; 7+ messages in thread
From: Llfrg @ 2004-03-01 18:22 UTC (permalink / raw)
  To: linux-c-programming

Hi,

I would like to monitor a program execution. I intend to have a program (or daemon) that, whenever the target program (whose name is to be passed as a paramenter) starts (i.e when ps -C progname returns any process), gets statistics like cpu usage and store them on a file, finishing when the target program finishes. What would be an efficient way to do that?

Thanks,
Leonardo.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Monitoring a program
  2004-03-01 18:22 Llfrg
@ 2004-03-01 21:38 ` John T. Williams
  2004-03-01 22:50   ` John T. Williams
  2004-03-01 22:34 ` Glynn Clements
  1 sibling, 1 reply; 7+ messages in thread
From: John T. Williams @ 2004-03-01 21:38 UTC (permalink / raw)
  To: Llfrg, linux-c-programming

Let me see if I understand what you are trying to do.  Lets pretend the
target program is ls.
Whenever ls is run by any user you would like you daemon to store
statistical information about the execution of ls.

You might have to get this information from the kernels process table.
While executing the information you want is available in the procfs, however
when the process completes the information disappears.  It has been awhile
since I took my OS class, so I'm not sure if the information is still
available in the kernel's data structures or not.  I believe it would be
until another process with the same pid runs, but there is a good chance
that I'm wrong.

Depending on what you are trying to accomplish there may be better/easier
ways to accomplish your goal.

--
John

----- Original Message ----- 
From: <Llfrg@aol.com>
To: <linux-c-programming@vger.kernel.org>
Sent: Monday, March 01, 2004 1:22 PM
Subject: Monitoring a program


> Hi,
>
> I would like to monitor a program execution. I intend to have a program
(or daemon) that, whenever the target program (whose name is to be passed as
a paramenter) starts (i.e when ps -C progname returns any process), gets
statistics like cpu usage and store them on a file, finishing when the
target program finishes. What would be an efficient way to do that?
>
> Thanks,
> Leonardo.
> -
> To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Monitoring a program
  2004-03-01 18:22 Llfrg
  2004-03-01 21:38 ` John T. Williams
@ 2004-03-01 22:34 ` Glynn Clements
  1 sibling, 0 replies; 7+ messages in thread
From: Glynn Clements @ 2004-03-01 22:34 UTC (permalink / raw)
  To: Llfrg; +Cc: linux-c-programming


Llfrg@aol.com wrote:

> I would like to monitor a program execution. I intend to have a
> program (or daemon) that, whenever the target program (whose name is
> to be passed as a paramenter) starts (i.e when ps -C progname returns
> any process), gets statistics like cpu usage and store them on a file,
> finishing when the target program finishes. What would be an efficient
> way to do that?

Suitable mechanisms include:

1. Modifying the target program to log its own statistics.

2. Modifying some other user-space component, (e.g. the loader or
libc) to recognise when the target program is being run and call your
monitoring code.

3. Modifying the kernel, e.g. extending the existing process
accounting mechanism to record additional information. Or at least
forcing the information to remain around long enough to be recorded.

Unsuitable mechanisms include continuously polling the process list in
the hope that you can catch a process running the target program and
attach to it with ptrace() before it terminates.

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Monitoring a program
  2004-03-01 21:38 ` John T. Williams
@ 2004-03-01 22:50   ` John T. Williams
  0 siblings, 0 replies; 7+ messages in thread
From: John T. Williams @ 2004-03-01 22:50 UTC (permalink / raw)
  To: John T. Williams, Llfrg, linux-c-programming



Have you considered using the 'time' program?

You could do something like (say the target program is ls again)


time ls 2>> statfile

the only problem is that you wouldn't see anything sent to stderr while the
program was executing
if you want your users to be unaware of this you could do something like

mv /bin/ls /bin/ls.bk

then make the file

/bin/ls
----------------------------------------
#!/bin/bash
time ls 2>> statfile
----------------end file---------------
----- Original Message ----- 
From: "John T. Williams" <jowillia@vt.edu>
To: <Llfrg@aol.com>; <linux-c-programming@vger.kernel.org>
Sent: Monday, March 01, 2004 4:38 PM
Subject: Re: Monitoring a program


> Let me see if I understand what you are trying to do.  Lets pretend the
> target program is ls.
> Whenever ls is run by any user you would like you daemon to store
> statistical information about the execution of ls.
>
> You might have to get this information from the kernels process table.
> While executing the information you want is available in the procfs,
however
> when the process completes the information disappears.  It has been awhile
> since I took my OS class, so I'm not sure if the information is still
> available in the kernel's data structures or not.  I believe it would be
> until another process with the same pid runs, but there is a good chance
> that I'm wrong.
>
> Depending on what you are trying to accomplish there may be better/easier
> ways to accomplish your goal.
>
> --
> John
>
> ----- Original Message ----- 
> From: <Llfrg@aol.com>
> To: <linux-c-programming@vger.kernel.org>
> Sent: Monday, March 01, 2004 1:22 PM
> Subject: Monitoring a program
>
>
> > Hi,
> >
> > I would like to monitor a program execution. I intend to have a program
> (or daemon) that, whenever the target program (whose name is to be passed
as
> a paramenter) starts (i.e when ps -C progname returns any process), gets
> statistics like cpu usage and store them on a file, finishing when the
> target program finishes. What would be an efficient way to do that?
> >
> > Thanks,
> > Leonardo.
> > -
> > To unsubscribe from this list: send the line "unsubscribe
> linux-c-programming" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
> -
> To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Monitoring a program
@ 2004-03-02  0:02 Llfrg
  0 siblings, 0 replies; 7+ messages in thread
From: Llfrg @ 2004-03-02  0:02 UTC (permalink / raw)
  To: linux-c-programming

Yes John, what I am trying to do is quite like your description. Only that instead of a simple program like ls, the target program would be scientific applications that take several seconds/minutes/hours executing, so that I would like to collect statistics periodically (i.e. every 0.1 second) and store it on a log file for future use (in a way similar to the vmstat command). I believe such information is not available after the execution (if it is, even better!). I would like to know ways of doing it with minimal effect on the target application performance.

John wrote:

>
Let me see if I understand what you are trying to do.  Lets pretend the
target program is ls.
Whenever ls is run by any user you would like you daemon to store
statistical information about the execution of ls.

You might have to get this information from the kernels process table.
While executing the information you want is available in the procfs, however
when the process completes the information disappears.  It has been awhile
since I took my OS class, so I'm not sure if the information is still
available in the kernel's data structures or not.  I believe it would be
until another process with the same pid runs, but there is a good chance
that I'm wrong.

Depending on what you are trying to accomplish there may be better/easier
ways to accomplish your goal.

--
John
>

Thanks,
Leonardo


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Monitoring a program
       [not found] <183D9E9B.3D6733E9.0000FADF@aol.com>
@ 2004-03-02  2:39 ` John T. Williams
  0 siblings, 0 replies; 7+ messages in thread
From: John T. Williams @ 2004-03-02  2:39 UTC (permalink / raw)
  To: Llfrg, linux-c-programming

I'm not sure what you mean by every part of the execution.

however you could do a very simple program in that record the exicution time
of its child process.

----------------main.c-------------------------------
#include <sys/times.h>
#include <sys/param.h>
#include <wait.h>

char* prog = "/bin/bash";
char* arglist[] = {
 "bash",
 0
};


int main () {
 int pid, status;
 struct tms systime;
 time_t point[2];
 int elaps;
 int ktime;
 int utime;
 int ttime;
 int itime;

 time(&point[0]);
 if( (pid = fork()) == 0 ) {
  execv(prog, arglist);
  printf("execv error\n");
  _exit(0);
 }

 wait(&status);
 time(&point[1]);
 times(&systime);


 elaps = point[1] - point[0];
 ktime = systime.tms_cstime / HZ;
 utime = systime.tms_cutime / HZ;
 ttime = ktime + utime;
       itime = elaps - ttime;

 printf("total time for of exicution: %i\n", ttime);
 printf("time in kernel for process:  %i\n", ktime);
 printf("time in user space:          %i\n", utime);
 printf("idile time:                  %i\n", itime);
 printf("total elaps time:            %i\n", elaps);


}
-------------End main.c--------------------------------












----- Original Message ----- 
From: <Llfrg@aol.com>
To: ""John T. Williams"" <jtwilliams@vt.edu>
Sent: Monday, March 01, 2004 7:21 PM
Subject: Re: Monitoring a program


> Ok, but I would like to have specific information on every part of the
execution, not only the total time. The objective of all this is to have a
profiling tool that measures performance of parallel programs. I wish to
find out load imbalance on different processors at different times on the
execution of parallel programs. I intend to run the profiling program on
every node and then compare their statistics.
>
> Thanks,
> Leonardo.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Monitoring a program
@ 2004-03-02 12:12 Llfrg
  0 siblings, 0 replies; 7+ messages in thread
From: Llfrg @ 2004-03-02 12:12 UTC (permalink / raw)
  To: "John T. Williams"; +Cc: linux-c-programming

By every part of the execution I mean the same kind of report the command <vmstat 1> does. I might even use vmstat, but how could I start it whenever a specific program starts? Is there a way to make vmstat work on intervals lower than one second?

Thanks,
Leonardo.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-03-02 12:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <183D9E9B.3D6733E9.0000FADF@aol.com>
2004-03-02  2:39 ` Monitoring a program John T. Williams
2004-03-02 12:12 Llfrg
  -- strict thread matches above, loose matches on Subject: below --
2004-03-02  0:02 Llfrg
2004-03-01 18:22 Llfrg
2004-03-01 21:38 ` John T. Williams
2004-03-01 22:50   ` John T. Williams
2004-03-01 22:34 ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).