Exemple #1
0
    def test_buf_to_npy_no_memory_leak(self):
        """Ensures we can call buf_to_npy without leaking memory."""
        model = core.MjModel.from_xml_string("<mujoco/>")
        src = model._ptr.contents.name_geomadr
        shape = (model.ngeom, )

        # This uses high water marks to find memory leaks in native code.
        old_max = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
        for _ in xrange(_NUM_CALLS):
            buf = util.buf_to_npy(src, shape)
        del buf
        new_max = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
        growth = new_max - old_max

        if growth > _RSS_GROWTH_TOLERANCE:
            self.fail("RSS grew by {} bytes, exceeding tolerance of {} bytes.".
                      format(growth, _RSS_GROWTH_TOLERANCE))
Exemple #2
0
  def test_buf_to_npy_no_memory_leak(self):
    """Ensures we can call buf_to_npy without leaking memory."""
    model = wrapper.MjModel.from_xml_string("<mujoco/>")
    src = model._ptr.contents.name_geomadr
    shape = (model.ngeom,)

    # This uses high water marks to find memory leaks in native code.
    old_max = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
    for _ in range(_NUM_CALLS):
      buf = util.buf_to_npy(src, shape)
    del buf
    new_max = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
    growth = new_max - old_max

    self.assertLessEqual(
        growth, _RSS_GROWTH_TOLERANCE,
        msg=("The Resident Set Size (RSS) of this process grew by {} bytes, "
             "exceeding the tolerance of {} bytes."
             .format(growth, _RSS_GROWTH_TOLERANCE)))
Exemple #3
0
 def _geoms_buffer(self):
   """Cached recarray containing the full geom buffer."""
   return util.buf_to_npy(super(MjvScene, self).geoms, shape=(self.maxgeom,))
Exemple #4
0
 def _contact_buffer(self):
   """Cached structured array containing the full contact buffer."""
   contact_array = util.buf_to_npy(
       super(MjData, self).contact, shape=(self._model.nconmax,))
   return contact_array
Exemple #5
0
 def _collect_geometries(self):
     # collect geometries structs
     _geoms = util.buf_to_npy(self._scene._ptr.contents.geoms,
                              (self._scene.ngeom, ))
     # parse this geometries into our format
     self._parse_geometries(_geoms)