21 package org.matsim.core.gbl;
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
26 import java.io.BufferedReader;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.lang.management.ManagementFactory;
30 import java.lang.management.ThreadMXBean;
32 import java.nio.charset.StandardCharsets;
38 public abstract class Gbl {
40 private static final Logger
log = LogManager.getLogger(
Gbl.class);
42 public final static String
ONLYONCE =
" This message given only once.";
44 public final static String
FUTURE_SUPPRESSED =
" Future occurences of this logging statement are suppressed." ;
46 public final static String
SEPARATOR =
"****************************" ;
48 public static final String
CREATE_ROUTING_ALGORITHM_WARNING_MESSAGE =
"This class wants to overwrite createRoutingAlgorithm(), which is no longer possible. Making createRoutingAlgorithm() non-final would not help since, after recent code changes, it is only used during initialization but not in replanning. kai, may'13. Aborting ...";
52 public static final String
ABSORBED_INTO_CORE=
"This execution path is no longer supported. The functionality has been absorbed into the core." ;
53 public static final String
INVALID =
"invalid";
56 long totalMem = Runtime.getRuntime().totalMemory();
57 long freeMem = Runtime.getRuntime().freeMemory();
58 long usedMem = totalMem - freeMem;
59 log.info(
"used RAM: " + usedMem +
"B = " + (usedMem/1024) +
"kB = " + (usedMem/1024/1024) +
"MB" +
60 " free: " + freeMem +
"B = " + (freeMem/1024/1024) +
"MB total: " + totalMem +
"B = " + (totalMem/1024/1024) +
"MB");
64 log.info(
"JVM: " + System.getProperty(
"java.version") +
"; " 65 + System.getProperty(
"java.vm.vendor") +
"; " 66 + System.getProperty(
"java.vm.info") +
"; " 67 + System.getProperty(
"sun.arch.data.model") +
"-bit");
68 log.info(
"OS: " + System.getProperty(
"os.name") +
"; " 69 + System.getProperty(
"os.version") +
"; " 70 + System.getProperty(
"os.arch"));
71 log.info(
"CPU cores: " + Runtime.getRuntime().availableProcessors());
72 log.info(
"max. Memory: " + Runtime.getRuntime().maxMemory() / 1024.0 / 1024.0 +
"MB (" + Runtime.getRuntime().maxMemory() +
"B)");
76 log.info(
"Command: " + System.getProperty(
"sun.java.command"));
88 String revision = null;
90 URL url =
Gbl.class.getResource(resourceFilename);
92 try (BufferedReader reader =
new BufferedReader(
new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) {
93 revision = reader.readLine();
94 date = reader.readLine();
95 }
catch (IOException e) {
98 if (revision == null) {
99 return component +
"-Build: unknown";
101 return component +
"-Build: " + revision +
" (" + date +
")";
104 return component +
"-Build: unknown";
112 public static final void printBuildInfo(String component, String resourceFilename) {
114 log.info(infoString);
125 log.error(
"Did not start measurements.");
131 private static final String
printTimeDiff(
final long later,
final long earlier) {
132 long elapsedTimeMillis = later - earlier;
133 float elapsedTimeSec = elapsedTimeMillis/1000F;
134 float elapsedTimeMin = elapsedTimeMillis/(60*1000F);
135 float elapsedTimeHour = elapsedTimeMillis/(60*60*1000F);
136 float elapsedTimeDay = elapsedTimeMillis/(24*60*60*1000F);
138 return elapsedTimeMillis +
" msecs; " +
139 elapsedTimeSec +
" secs; " +
140 elapsedTimeMin +
" mins; " +
141 elapsedTimeHour +
" hours; " +
142 elapsedTimeDay +
" days ###";
162 private final static ThreadMXBean
tbe = ManagementFactory.getThreadMXBean();
171 if (tbe.isThreadCpuTimeSupported()) {
172 tbe.setThreadCpuTimeEnabled(
true);
183 if (tbe.isThreadCpuTimeEnabled()) {
184 return tbe.getThreadCpuTime(thread.getId()) / 1.0e9;
195 if (tbe.isThreadCpuTimeEnabled()) {
196 log.info(
"Thread performance: Thread=" + thread.getName() +
" cpu-time=" +
getThreadCpuTime(thread) +
"sec");
227 +
"controler.addOverridingModule(new AbstractModule(){\n" 228 +
"@Override public void install() {\n" 229 +
"this.bindMobsim().toProvider(MyMobsimProvider.class) ;\n" 232 +
"See, e.g., the RunMobsimWithMultipleModeVehiclesExample class under tutorial.*. Talk to MZ or KN if you need help. kai, may'15";
234 public final static String
SET_UP_IS_NOW_FINAL =
"controler.setUp() is now final. You should be able to do whatever you need to do with a " 235 +
"ControlerStartupListener. Please talk to MZ or KN if you have difficulties. kai, may'15";
237 public static final String
LOAD_DATA_IS_NOW_FINAL =
"controler.loadData() is now final. If you need this functionality, use ScenarioUtils.loadScenario(...), " 238 +
"then modify the scenario, then pass it into new Controler( scenario ). Talk to MZ or KN if you need help. kai, may'15";
241 +
"possible by inheritance should now be doable by other constructs. See tutorial.programming.* for examples. Please talk" 242 +
"to MZ or KN if you would like to get help. kai, may'15" ;
245 +
"but please check functionality. kai, mar'15" ;
248 +
"needs to sort out if it wants that, or if it just wants to replan the current leg. kai, feb'16" ;
255 return "about to write " + what +
" to: " + filename ;
258 return "about to read " + what +
" from: " + url ;
260 public static String
aboutToRead( String what, String filename ) {
261 return "about to read " + what +
" from: " + filename ;
static final String ONLYONCE
static final void printRunCommand()
static final String LOAD_DATA_IS_NOW_FINAL
static final void startMeasurement()
static void assertNotNull(Object obj, String msg)
static void assertIf(boolean flag)
static final String ABSORBED_INTO_CORE
static final String CONTROLER_IS_NOW_FINAL
static final void printBuildInfo(String component, String resourceFilename)
static final String FUTURE_SUPPRESSED
static final void printRoundTime()
static final String printTime()
static final String SET_UP_IS_NOW_FINAL
static String aboutToRead(String what, URL url)
static final String SEPARATOR
static final String printTimeDiff(final long later, final long earlier)
static final String RETROFIT_CONTROLER
static final String getBuildInfoString()
static long measurementStartTime
static final String NOT_IMPLEMENTED
static void assertNotNull(Object obj)
static final String getBuildInfoString(String component, String resourceFilename)
static final String CREATE_ROUTING_ALGORITHM_WARNING_MESSAGE
static final void printMemoryUsage()
static String aboutToWrite(String what, String filename)
static final void printElapsedTime()
static final void printBuildInfo()
static final ThreadMXBean tbe
static final String WRONG_IMPLEMENTATION
static final void printSystemInfo()
static final String COPY_PASTE_FROM_CORE_NO_LONGER_WORKING
static final void printThreadCpuTime(final Thread thread)
static final String PROBLEM_WITH_ACCESS_EGRESS
static final double getThreadCpuTime(final Thread thread)
static final String INVALID
static String aboutToRead(String what, String filename)
static final boolean enableThreadCpuTimeMeasurement()
static final String RUN_MOB_SIM_NO_LONGER_POSSIBLE
static final void printCurrentThreadCpuTime()