Update model memory footprint reporting in mj_printModel.
PiperOrigin-RevId: 831015711 Change-Id: I7cb5aba019ed99e239b6fadbaf162cbd6fd9d9fb
This commit is contained in:
committed by
Copybara-Service
parent
bc83bfb076
commit
414d6d80ac
+35
-15
@@ -349,12 +349,8 @@ static const char* memorySize(size_t nbytes) {
|
|||||||
|
|
||||||
if (nbytes < k) {
|
if (nbytes < k) {
|
||||||
snprintf(message, sizeof(message), "%5zu bytes", nbytes);
|
snprintf(message, sizeof(message), "%5zu bytes", nbytes);
|
||||||
} else if (nbytes < k*k) {
|
|
||||||
snprintf(message, sizeof(message), "%5.1f KB", (double)nbytes / k);
|
|
||||||
} else if (nbytes < k*k*k) {
|
|
||||||
snprintf(message, sizeof(message), "%5.1f MB", (double)nbytes / (k*k));
|
|
||||||
} else {
|
} else {
|
||||||
snprintf(message, sizeof(message), "%5.1f GB", (double)nbytes / (k*k*k));
|
snprintf(message, sizeof(message), "%7.0f KB", (double)nbytes / (k));
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
@@ -371,6 +367,13 @@ static size_t sizeMesh(const mjModel* m) {
|
|||||||
nbytes += sizeof(int) * 3*m->nmeshface; // mesh_facenormal
|
nbytes += sizeof(int) * 3*m->nmeshface; // mesh_facenormal
|
||||||
nbytes += sizeof(int) * 3*m->nmeshface; // mesh_facetexcoord
|
nbytes += sizeof(int) * 3*m->nmeshface; // mesh_facetexcoord
|
||||||
nbytes += sizeof(int) * m->nmeshgraph; // mesh_graph
|
nbytes += sizeof(int) * m->nmeshgraph; // mesh_graph
|
||||||
|
nbytes += sizeof(mjtNum) * 3*m->nmeshpoly; // mesh_polynormal
|
||||||
|
nbytes += sizeof(int) * m->nmeshpoly; // mesh_polyvertadr
|
||||||
|
nbytes += sizeof(int) * m->nmeshpoly; // mesh_polyvertnum
|
||||||
|
nbytes += sizeof(int) * m->nmeshpolyvert; // mesh_polyvert
|
||||||
|
nbytes += sizeof(int) * m->nmeshvert; // mesh_polymapadr
|
||||||
|
nbytes += sizeof(int) * m->nmeshvert; // mesh_polymapnum
|
||||||
|
nbytes += sizeof(int) * m->nmeshpolymap; // mesh_polymap
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,6 +395,21 @@ static size_t sizeSkin(const mjModel* m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return memory footprint of all BVH-related arrays
|
||||||
|
static size_t sizeBVH(const mjModel* m) {
|
||||||
|
size_t nbytes = 0;
|
||||||
|
nbytes += sizeof(int) * m->nbvh; // bvh_depth
|
||||||
|
nbytes += sizeof(int) * 2*m->nbvh; // bvh_child
|
||||||
|
nbytes += sizeof(int) * m->nbvh; // bvh_nodeid
|
||||||
|
nbytes += sizeof(mjtNum) * 6*m->nbvhstatic; // bvh_aabb
|
||||||
|
nbytes += sizeof(int) * m->noct; // oct_depth
|
||||||
|
nbytes += sizeof(int) * 8*m->noct; // oct_child
|
||||||
|
nbytes += sizeof(mjtNum) * 6*m->noct; // oct_aabb
|
||||||
|
nbytes += sizeof(mjtNum) * 8*m->noct; // oct_coeff
|
||||||
|
return nbytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// return whether float_format is a valid format string for a single float
|
// return whether float_format is a valid format string for a single float
|
||||||
static bool validateFloatFormat(const char* float_format) {
|
static bool validateFloatFormat(const char* float_format) {
|
||||||
// check for nullptr;
|
// check for nullptr;
|
||||||
@@ -504,16 +522,18 @@ void mj_printFormattedModel(const mjModel* m, const char* filename, const char*
|
|||||||
|
|
||||||
// memory footprint
|
// memory footprint
|
||||||
fprintf(fp, "MEMORY\n");
|
fprintf(fp, "MEMORY\n");
|
||||||
fprintf(fp, " total %s\n", memorySize(mj_sizeModel(m)));
|
size_t sz_total = mj_sizeModel(m);
|
||||||
if (m->nmesh) {
|
size_t sz_mesh = m->nmesh ? sizeMesh(m) : 0;
|
||||||
fprintf(fp, " meshes %s\n", memorySize(sizeMesh(m)));
|
size_t sz_bvh = (m->nbvh || m->noct) ? sizeBVH(m) : 0;
|
||||||
}
|
size_t sz_tex = m->ntex ? m->ntexdata : 0;
|
||||||
if (m->ntex) {
|
size_t sz_skin = m->nskin ? sizeSkin(m) : 0;
|
||||||
fprintf(fp, " textures %s\n", memorySize(m->ntexdata));
|
size_t sz_other = sz_total - sz_mesh - sz_bvh - sz_tex - sz_skin;
|
||||||
}
|
fprintf(fp, " total %s\n", memorySize(sz_total));
|
||||||
if (m->nskin) {
|
if (sz_mesh) fprintf(fp, " meshes %s\n", memorySize(sz_mesh));
|
||||||
fprintf(fp, " skins %s\n", memorySize(sizeSkin(m)));
|
if (sz_bvh) fprintf(fp, " bvhs %s\n", memorySize(sz_bvh));
|
||||||
}
|
if (sz_tex) fprintf(fp, " textures %s\n", memorySize(sz_tex));
|
||||||
|
if (sz_skin) fprintf(fp, " skins %s\n", memorySize(sz_skin));
|
||||||
|
if (sz_other) fprintf(fp, " other %s\n", memorySize(sz_other));
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user