[R] package / function for monitoring processes?
jim holtman
jholtman at gmail.com
Wed Sep 21 20:31:34 CEST 2011
Here is the function I use:
my.stats <- function (text = "stats", reset = FALSE, oper = "")
{
procTime <- proc.time()[1:3]
if (reset) {
Level <<- 1
Stack[Level, ] <<- c(procTime[3], procTime[1] + procTime[2])
}
if (oper == "push") {
if (Level < MaxLevel)
Level <<- Level + 1
Stack[Level, ] <<- c(procTime[3], procTime[1] + procTime[2])
}
.caller <- sys.calls()
if (length(.caller) == 1)
.caller <- "Rgui"
else .caller <- as.character(.caller[[length(.caller) - 1]])[1]
cat(sprintf("%s (%d) - %s : %s <%.1f %.1f> %.1f : %.1fMB\n",
text, Level, .caller, format(Sys.time(), format = "%H:%M:%S"),
procTime[1] + procTime[2] - Stack[Level, 2], procTime[3] -
Stack[Level, 1], procTime[3], memory.size()))
if ((oper == "pop") && (Level > 1))
Level <<- Level - 1
else if (oper == "reset")
Level <<- 1
invisible(flush.console())
}
Here is an example of its use: inside the <> is the total CPU and
elapsed time to that point.
> my.stats('start')
start (1) - Rgui : 14:29:27 <30.7 20136.7> 20136.7 : 107.8MB
> for (i in 1:1e6) i+1 # consume some CPU
> for (i in 1:10e6) i+1 # consume some CPU
> my.stats('end') # used almost 8 secs of CPU time
end (1) - Rgui : 14:30:24 <38.4 20193.0> 20193.0 : 139.4MB
>
On Tue, Sep 20, 2011 at 9:16 PM, Benjamin Tyner <btyner at gmail.com> wrote:
> Hi
>
> I recall running across a function a while back which would return
> information about running processes (such as their cpu and memory usage),
> but I cannot seem to locate it. Wondering if someone would be kind enough to
> refresh my memory. I vaguely recall it was parsing the output of the 'ps'
> command.
>
> Thanks,
> Ben
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
--
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
More information about the R-help
mailing list