2012-06-28 17:03:16 -04:00
|
|
|
/*
|
2018-07-31 07:35:16 -04:00
|
|
|
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
|
2012-06-28 17:03:16 -04:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "precompiled.hpp"
|
2014-08-07 12:18:58 -07:00
|
|
|
#include "services/nmtCommon.hpp"
|
2018-04-24 18:06:32 +02:00
|
|
|
#include "utilities/globalDefinitions.hpp"
|
2014-08-07 12:18:58 -07:00
|
|
|
|
2018-09-01 12:02:07 -07:00
|
|
|
#define MEMORY_TYPE_DECLARE_NAME(type, human_readable) \
|
2018-09-04 08:06:31 +02:00
|
|
|
human_readable,
|
2018-09-01 12:02:07 -07:00
|
|
|
|
2014-08-07 12:18:58 -07:00
|
|
|
const char* NMTUtil::_memory_type_names[] = {
|
2018-09-01 12:02:07 -07:00
|
|
|
MEMORY_TYPES_DO(MEMORY_TYPE_DECLARE_NAME)
|
2014-08-07 12:18:58 -07:00
|
|
|
};
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
|
2014-08-07 12:18:58 -07:00
|
|
|
const char* NMTUtil::scale_name(size_t scale) {
|
|
|
|
switch(scale) {
|
2020-08-09 09:20:02 +02:00
|
|
|
case 1: return "";
|
2014-08-07 12:18:58 -07:00
|
|
|
case K: return "KB";
|
|
|
|
case M: return "MB";
|
|
|
|
case G: return "GB";
|
|
|
|
}
|
|
|
|
ShouldNotReachHere();
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-06-28 17:03:16 -04:00
|
|
|
|
2014-08-07 12:18:58 -07:00
|
|
|
size_t NMTUtil::scale_from_name(const char* scale) {
|
|
|
|
assert(scale != NULL, "Null pointer check");
|
2018-04-24 18:06:32 +02:00
|
|
|
if (strcasecmp(scale, "1") == 0 || strcasecmp(scale, "b") == 0) {
|
|
|
|
return 1;
|
|
|
|
} else if (strcasecmp(scale, "kb") == 0 || strcasecmp(scale, "k") == 0) {
|
2014-08-07 12:18:58 -07:00
|
|
|
return K;
|
2018-04-24 18:06:32 +02:00
|
|
|
} else if (strcasecmp(scale, "mb") == 0 || strcasecmp(scale, "m") == 0) {
|
2014-08-07 12:18:58 -07:00
|
|
|
return M;
|
2018-04-24 18:06:32 +02:00
|
|
|
} else if (strcasecmp(scale, "gb") == 0 || strcasecmp(scale, "g") == 0) {
|
2014-08-07 12:18:58 -07:00
|
|
|
return G;
|
2013-09-04 08:55:08 -04:00
|
|
|
} else {
|
2014-08-07 12:18:58 -07:00
|
|
|
return 0; // Invalid value
|
2012-06-28 17:03:16 -04:00
|
|
|
}
|
2014-08-07 12:18:58 -07:00
|
|
|
return K;
|
2012-06-28 17:03:16 -04:00
|
|
|
}
|
|
|
|
|
2021-08-04 12:19:02 +00:00
|
|
|
const char* NMTUtil::tracking_level_to_string(NMT_TrackingLevel lvl) {
|
|
|
|
switch(lvl) {
|
|
|
|
case NMT_unknown: return "unknown"; break;
|
|
|
|
case NMT_off: return "off"; break;
|
|
|
|
case NMT_minimal: return "minimal"; break;
|
|
|
|
case NMT_summary: return "summary"; break;
|
|
|
|
case NMT_detail: return "detail"; break;
|
|
|
|
default: return "invalid"; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the parsed level; NMT_unknown if string is invalid
|
|
|
|
NMT_TrackingLevel NMTUtil::parse_tracking_level(const char* s) {
|
|
|
|
if (s != NULL) {
|
|
|
|
if (strcmp(s, "summary") == 0) {
|
|
|
|
return NMT_summary;
|
|
|
|
} else if (strcmp(s, "detail") == 0) {
|
|
|
|
return NMT_detail;
|
|
|
|
} else if (strcmp(s, "off") == 0) {
|
|
|
|
return NMT_off;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NMT_unknown;
|
|
|
|
}
|