Format memory warning in human-friendly way.
PiperOrigin-RevId: 486610408 Change-Id: I6beecb12059e69f4407e921d20efc54ce6b3f491
This commit is contained in:
committed by
Copybara-Service
parent
fc24097b92
commit
fd4d47e4a5
@@ -33,6 +33,13 @@
|
||||
#define mjMAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define mjMIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
// thread local macro
|
||||
#ifdef _MSC_VER
|
||||
#define mjTHREADLOCAL __declspec(thread)
|
||||
#else
|
||||
#define mjTHREADLOCAL _Thread_local
|
||||
#endif
|
||||
|
||||
|
||||
//-------------------------- timer macros ----------------------------------------------------------
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "engine/engine_macro.h"
|
||||
//------------------------- cross-platform aligned malloc/free -------------------------------------
|
||||
|
||||
static inline void* mju_alignedMalloc(size_t size, size_t align) {
|
||||
@@ -73,11 +74,6 @@ void mju_clearHandlers(void) {
|
||||
|
||||
typedef void (*callback_fn)(const char*);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define mjTHREADLOCAL __declspec(thread)
|
||||
#else
|
||||
#define mjTHREADLOCAL _Thread_local
|
||||
#endif
|
||||
static mjTHREADLOCAL callback_fn _mjPRIVATE_tls_error_fn = NULL;
|
||||
static mjTHREADLOCAL callback_fn _mjPRIVATE_tls_warning_fn = NULL;
|
||||
|
||||
|
||||
@@ -946,9 +946,30 @@ int mju_str2Type(const char* str) {
|
||||
|
||||
|
||||
|
||||
// return human readable number of bytes using standard letter suffix
|
||||
const char* mju_writeNumBytes(const size_t nbytes) {
|
||||
int i;
|
||||
static mjTHREADLOCAL char message[20];
|
||||
static const char suffix[] = " KMGTPE";
|
||||
for (i=0; i<6; i++) {
|
||||
const size_t bits = (size_t)(1) << (10*(6-i));
|
||||
if (nbytes >= bits && !(nbytes & (bits - 1))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i<6) {
|
||||
mjSNPRINTF(message, "%zu%c", nbytes >> (10*(6-i)), suffix[6-i]);
|
||||
} else {
|
||||
mjSNPRINTF(message, "%zu", nbytes >> (10*(6-i)));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// warning text
|
||||
const char* mju_warningText(int warning, size_t info) {
|
||||
static char str[1000];
|
||||
static mjTHREADLOCAL char str[1000];
|
||||
|
||||
switch (warning) {
|
||||
case mjWARN_INERTIA:
|
||||
@@ -965,7 +986,7 @@ const char* mju_warningText(int warning, size_t info) {
|
||||
case mjWARN_CNSTRFULL:
|
||||
mjSNPRINTF(str,
|
||||
"Insufficient arena memory for the number of constraints generated. "
|
||||
"Increase arena memory allocation above %zu bytes.", info);
|
||||
"Increase arena memory allocation above %s bytes.", mju_writeNumBytes(info));
|
||||
break;
|
||||
|
||||
case mjWARN_VGEOMFULL:
|
||||
|
||||
@@ -87,6 +87,9 @@ MJAPI const char* mju_type2Str(int type);
|
||||
// convert type name to type id (mjtObj)
|
||||
MJAPI int mju_str2Type(const char* str);
|
||||
|
||||
// return human readable number of bytes using standard letter suffix
|
||||
MJAPI const char* mju_writeNumBytes(const size_t nbytes);
|
||||
|
||||
// warning text
|
||||
MJAPI const char* mju_warningText(int warning, size_t info);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user