On Mon, Nov 17, 2008 at 11:39:51AM -0500, Benjamin Smedberg wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I've done some google searches but haven't found an example script for how
> to record the amount of CPU time used by a process.
>
> I'm trying to profile a build system by tracing how many and what kinds of
> processes are started. I want to record the following information about
> every process within a process tree:
>
> real start time
> real end time
> CPU time used
> working directory
> executable
> command line (argv)
>
> Collecting the real start time/end time/cwd/exectable is fairly simple, I
> think I've got it.
>
> I was thinking that CPU time could be calculated by using vtimestamp:
>
> collect the vtimestamp at the start and the end of each LWP, and total them
> to get the CPU time for the process. However, I'm having trouble with the
> proc:::lwp-start probe: it seems to fire in the context of the parent
> process, not in the context of the new thread that's starting:
>
> bsmedberg $ sudo dtrace -s ../process-tree.d -q 32254
> proc:::lwp-start
> pid: 32254
> tid: 111341864
> vtimestamp: 96036509
> proc:::create
> pid: 32254
> args[0]->pr_pid: 43113
> proc:::lwp-create
^^^^^^^^^^
lwp-create is fired from the creating thread. lwp-start is fired from the
new thread.
> pid: 32254
> tid: 111341864
> args[1]->pr_pid: 73060628
> args[0]->pr_lwpid: 74125832
> vtimestamp: 95792715
> proc:::exec-success
> pid: 43113
> ppid: 32254
> cwd: obj
> curpsinfo->pr_fname: cat
> proc:::exit
> pid: 43113
> proc:::lwp-exit
> pid: 43113
> tid: 74125832
> vtimestamp: 3361917
>
> This means I can't simply use lwp-start and lwp-exit and do vtimestamp math,
> because the vtimestamp of the lwp-create probe is the vtimestamp of the
> shell thread, not the new thread!
>
> Does anyone have an example script or suggestion how to record the amount of
> CPU time a process uses?
>
> Note: This is MacOS.
>
> - --BDS
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.5 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFJIZ5WSSwGp5sTYNkRAhlnAJ9hMuv00eCD6DSWYFy8BMNPHxTGqgCg4nLa
> y3C4zIILmCKS/SFoxjZdUX4=
> =R4OP
> -----END PGP SIGNATURE-----
> _______________________________________________
> dtrace-discuss mailing list
> [email protected]
_______________________________________________
dtrace-discuss mailing list
[email protected]