[cig-commits] r8042 - in short/3D/PyLith/trunk/pylith: . problems
utils
brad at geodynamics.org
brad at geodynamics.org
Thu Sep 27 15:13:13 PDT 2007
Author: brad
Date: 2007-09-27 15:13:12 -0700 (Thu, 27 Sep 2007)
New Revision: 8042
Added:
short/3D/PyLith/trunk/pylith/utils/profiling.py
Modified:
short/3D/PyLith/trunk/pylith/Makefile.am
short/3D/PyLith/trunk/pylith/PyLithApp.py
short/3D/PyLith/trunk/pylith/problems/Formulation.py
Log:
Added simple memory and CPU time logging using ps shell command and journal.
Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am 2007-09-27 21:27:43 UTC (rev 8041)
+++ short/3D/PyLith/trunk/pylith/Makefile.am 2007-09-27 22:13:12 UTC (rev 8042)
@@ -102,6 +102,7 @@
utils/ObjectBin.py \
utils/PetscManager.py \
utils/importing.py \
+ utils/profiling.py \
utils/testarray.py
Modified: short/3D/PyLith/trunk/pylith/PyLithApp.py
===================================================================
--- short/3D/PyLith/trunk/pylith/PyLithApp.py 2007-09-27 21:27:43 UTC (rev 8041)
+++ short/3D/PyLith/trunk/pylith/PyLithApp.py 2007-09-27 22:13:12 UTC (rev 8042)
@@ -73,23 +73,32 @@
"""
Run the application.
"""
+ from pylith.utils.profiling import resourceUsageString
+
self.petsc.initialize()
+ self._debug.log(resourceUsageString())
# Create mesh (adjust to account for interfaces (faults) if necessary)
interfaces = None
if "interfaces" in dir(self.problem):
interfaces = self.problem.interfaces.bin
mesh = self.mesher.create(interfaces)
+ self._debug.log(resourceUsageString())
# Setup problem, verify configuration, and then initialize
self.problem.preinitialize(mesh)
+ self._debug.log(resourceUsageString())
+
self.problem.verifyConfiguration()
+
self.problem.initialize()
+ self._debug.log(resourceUsageString())
# Run problem and cleanup
self.problem.run(self)
+ self._debug.log(resourceUsageString())
+
self.problem.finalize()
-
self.petsc.finalize()
return
@@ -104,6 +113,9 @@
self.mesher = self.inventory.mesher
self.problem = self.inventory.problem
self.petsc = self.inventory.petsc
+
+ import journal
+ self._debug = journal.debug(self.name)
return
Modified: short/3D/PyLith/trunk/pylith/problems/Formulation.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Formulation.py 2007-09-27 21:27:43 UTC (rev 8041)
+++ short/3D/PyLith/trunk/pylith/problems/Formulation.py 2007-09-27 22:13:12 UTC (rev 8042)
@@ -18,6 +18,8 @@
from pyre.components.Component import Component
+from pylith.utils.profiling import resourceUsageString
+
# Formulation class
class Formulation(Component):
"""
@@ -156,19 +158,23 @@
"""
from pylith.topology.FieldsManager import FieldsManager
self.fields = FieldsManager(self.mesh)
+ self._debug.log(resourceUsageString())
self._info.log("Initializing integrators.")
for integrator in self.integrators:
integrator.initialize()
+ self._debug.log(resourceUsageString())
self._info.log("Initializing constraints.")
for constraint in self.constraints:
constraint.initialize()
+ self._debug.log(resourceUsageString())
self._info.log("Setting up solution output.")
for output in self.output.bin:
output.open(self.mesh)
output.writeTopology()
+ self._debug.log(resourceUsageString())
self._info.log("Creating solution field.")
solnName = self.solnField['name']
@@ -180,6 +186,7 @@
self.fields.allocate(solnName)
for constraint in self.constraints:
constraint.setConstraints(self.fields.getSolution())
+ self._debug.log(resourceUsageString())
return
@@ -216,6 +223,9 @@
Component._configure(self)
self.solver = self.inventory.solver
self.output = self.inventory.output
+
+ import journal
+ self._debug = journal.debug(self.name)
return
@@ -224,12 +234,14 @@
Reform Jacobian matrix for operator.
"""
self._info.log("Reforming Jacobian of operator.")
+ self._debug.log(resourceUsageString())
import pylith.utils.petsc as petsc
petsc.mat_setzero(self.jacobian)
for integrator in self.integrators:
integrator.timeStep(dt)
integrator.integrateJacobian(self.jacobian, t+dt, self.fields)
petsc.mat_assemble(self.jacobian)
+ self._debug.log(resourceUsageString())
return
Added: short/3D/PyLith/trunk/pylith/utils/profiling.py
===================================================================
--- short/3D/PyLith/trunk/pylith/utils/profiling.py 2007-09-27 21:27:43 UTC (rev 8041)
+++ short/3D/PyLith/trunk/pylith/utils/profiling.py 2007-09-27 22:13:12 UTC (rev 8042)
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/utils/profile.py
+
+# ----------------------------------------------------------------------
+def resourceUsage():
+ """
+ Get CPU time (hh:mm:ss) and memory use (MB).
+ """
+
+ try:
+ import os
+ import commands
+ cmd = "ps -p %d -o cputime,rss" % os.getpid()
+ info = commands.getoutput(cmd).split()
+ cputime = info[2]
+ memory = float(info[3])/1024.0
+ except:
+ cputime = "n/a"
+ memory = 0
+ return (cputime, memory)
+
+
+# ----------------------------------------------------------------------
+def resourceUsageString():
+ """
+ Get CPU time and memory usage as a string.
+ """
+ return "CPU time: %s, Memory usage: %.2f MB" % resourceUsage()
+
+
+# End of file
Property changes on: short/3D/PyLith/trunk/pylith/utils/profiling.py
___________________________________________________________________
Name: svn:executable
+ *
More information about the cig-commits
mailing list