diff --git a/jps/jps-builders-6/src/org/jetbrains/jps/javac/ExternalJavacProcess.java b/jps/jps-builders-6/src/org/jetbrains/jps/javac/ExternalJavacProcess.java index 60167055c1fd..f745254e7675 100644 --- a/jps/jps-builders-6/src/org/jetbrains/jps/javac/ExternalJavacProcess.java +++ b/jps/jps-builders-6/src/org/jetbrains/jps/javac/ExternalJavacProcess.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.javac; import io.netty.bootstrap.Bootstrap; @@ -71,7 +71,7 @@ public class ExternalJavacProcess { * @param args: SessionUUID, host, port, */ public static void main(String[] args) { - //myGlobalStart = System.currentTimeMillis(); + //myGlobalStart = System.nanoTime(); UUID uuid = null; String host = null; int port = -1; @@ -106,10 +106,10 @@ public class ExternalJavacProcess { final ExternalJavacProcess process = new ExternalJavacProcess(keepRunning); try { - //final long connectStart = System.currentTimeMillis(); + //final long connectStart = System.nanoTime(); if (process.connect(host, port)) { - //final long connectEnd = System.currentTimeMillis(); - //System.err.println("Connected in " + (connectEnd - connectStart) + " ms; since start: " + (connectEnd - myGlobalStart)); + //final long connectEnd = System.nanoTime(); + //System.err.println("Connected in " + TimeUnit.NANOSECONDS.toMillis(connectEnd - connectStart) + " ms; since start: " + TimeUnit.NANOSECONDS.toMillis(connectEnd - myGlobalStart)); process.myConnectFuture.channel().writeAndFlush( JavacProtoUtil.toMessage(uuid, JavacProtoUtil.createRequestAckResponse()) ); @@ -147,8 +147,8 @@ public class ExternalJavacProcess { Collection sourcePath, Map> outs, final CanceledStatus canceledStatus) { - final long compileStart = System.currentTimeMillis(); - //System.err.println("Compile start; since global start: " + (compileStart - myGlobalStart)); + final long compileStart = System.nanoTime(); + //System.err.println("Compile start; since global start: " + TimeUnit.NANOSECONDS.toMillis(compileStart - myGlobalStart)); final DiagnosticOutputConsumer diagnostic = new DiagnosticOutputConsumer() { @Override public void javaFileLoaded(File file) { @@ -198,9 +198,9 @@ public class ExternalJavacProcess { return JavacProtoUtil.toMessage(sessionId, JavacProtoUtil.createFailure(e.getMessage(), e)); } finally { - final long compileEnd = System.currentTimeMillis(); - System.err.println("Compiled in " + (compileEnd - compileStart) + " ms"); - //System.err.println("Compiled in " + (compileEnd - compileStart) + " ms; since global start: " + (compileEnd - myGlobalStart)); + final long compileEnd = System.nanoTime(); + System.err.println("Compiled in " + TimeUnit.NANOSECONDS.toMillis(compileEnd - compileStart) + " ms"); + //System.err.println("Compiled in " + TimeUnit.NANOSECONDS.toMillis(compileEnd - compileStart) + " ms; since global start: " + TimeUnit.NANOSECONDS.toMillis(compileEnd - myGlobalStart)); } } @@ -314,15 +314,15 @@ public class ExternalJavacProcess { public void stop() { try { - //final long stopStart = System.currentTimeMillis(); - //System.err.println("Exiting. Since global start " + (stopStart - myGlobalStart)); + //final long stopStart = System.nanoTime(); + //System.err.println("Exiting. Since global start " + TimeUnit.NANOSECONDS.toMillis(stopStart - myGlobalStart)); final ChannelFuture future = myConnectFuture; if (future != null) { future.channel().close().await(); } myEventLoopGroup.shutdownGracefully(0, 15, TimeUnit.SECONDS).await(); - //final long stopEnd = System.currentTimeMillis(); - //System.err.println("Stop completed in " + (stopEnd - stopStart) + "ms; since global start: " + ((stopEnd - myGlobalStart))); + //final long stopEnd = System.nanoTime(); + //System.err.println("Stop completed in " + TimeUnit.NANOSECONDS.toMillis(stopEnd - stopStart) + "ms; since global start: " + TimeUnit.NANOSECONDS.toMillis(stopEnd - myGlobalStart)); System.exit(0); } catch (Throwable e) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildMain.java b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildMain.java index 74945a143016..eaa3f778684d 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildMain.java +++ b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildMain.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.cmdline; import com.intellij.openapi.diagnostic.Logger; @@ -73,7 +59,7 @@ public class BuildMain { public static void main(String[] args) { try { - final long processStart = System.currentTimeMillis(); + final long processStart = System.nanoTime(); final String startMessage = "Build process started. Classpath: " + System.getProperty("java.class.path"); System.out.println(startMessage); LOG.info(StringUtil.repeatSymbol('=', 50)); @@ -85,7 +71,7 @@ public class BuildMain { final File systemDir = new File(FileUtil.toCanonicalPath(args[SYSTEM_DIR_ARG])); Utils.setSystemRoot(systemDir); - final long connectStart = System.currentTimeMillis(); + final long connectStart = System.nanoTime(); // IDEA-123132, let's try again for (int attempt = 0; attempt < 3; attempt++) { try { @@ -120,7 +106,7 @@ public class BuildMain { final boolean success = future.isSuccess(); if (success) { - LOG.info("Connection to IDE established in " + (System.currentTimeMillis() - connectStart) + " ms"); + LOG.info("Connection to IDE established in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - connectStart) + " ms"); final String projectPathToPreload = System.getProperty(PRELOAD_PROJECT_PATH, null); final String globalsPathToPreload = System.getProperty(PRELOAD_CONFIG_PATH, null); @@ -172,7 +158,7 @@ public class BuildMain { JpsServiceManager.getInstance().getExtensions(PreloadedDataExtension.class).forEach(ext-> ext.preloadData(data)); - LOG.info("Pre-loaded process ready in " + (System.currentTimeMillis() - processStart) + " ms"); + LOG.info("Pre-loaded process ready in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - processStart) + " ms"); } catch (Throwable e) { LOG.info("Failed to pre-load project " + projectPathToPreload, e); diff --git a/jps/jps-builders/src/org/jetbrains/jps/cmdline/JpsModelLoaderImpl.java b/jps/jps-builders/src/org/jetbrains/jps/cmdline/JpsModelLoaderImpl.java index 509909ac62a4..68d6ce473e43 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/cmdline/JpsModelLoaderImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/cmdline/JpsModelLoaderImpl.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.cmdline; import com.intellij.openapi.diagnostic.Logger; @@ -22,6 +8,7 @@ import org.jetbrains.jps.model.JpsModel; import org.jetbrains.jps.model.serialization.JpsSerializationManager; import java.io.IOException; +import java.util.concurrent.TimeUnit; public class JpsModelLoaderImpl implements JpsModelLoader { private static final Logger LOG = Logger.getInstance(JpsModelLoaderImpl.class); @@ -42,14 +29,14 @@ public class JpsModelLoaderImpl implements JpsModelLoader { @Override public JpsModel loadModel() throws IOException { - final long start = System.currentTimeMillis(); + final long start = System.nanoTime(); LOG.info("Loading model: project path = " + myProjectPath + ", global options path = " + myGlobalOptionsPath); final JpsModel model = JpsSerializationManager.getInstance().loadModel(myProjectPath, myGlobalOptionsPath, myLoadUnloadedModules); if (myModelInitializer != null) { myModelInitializer.run(model); } - final long loadTime = System.currentTimeMillis() - start; - LOG.info("Model loaded in " + loadTime + " ms"); + final long loadTime = System.nanoTime() - start; + LOG.info("Model loaded in " + TimeUnit.NANOSECONDS.toMillis(loadTime) + " ms"); LOG.info("Project has " + model.getProject().getModules().size() + " modules, " + model.getProject().getLibraryCollection().getLibraries().size() + " libraries"); return model; } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java index 550cdbdf641f..3506d18cedc7 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.incremental; import com.intellij.openapi.diagnostic.Logger; @@ -721,7 +721,7 @@ public class IncProjectBuilder { } private void clearOutputs(CompileContext context) throws ProjectBuildException { - final long cleanStart = System.currentTimeMillis(); + final long cleanStart = System.nanoTime(); final MultiMap> rootsToDelete = MultiMap.createSet(); final Set allSourceRoots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY); @@ -833,7 +833,7 @@ public class IncProjectBuilder { myAsyncTasks.add(FileUtil.asyncDelete(filesToDelete)); } } - LOG.info("Cleaned output directories in " + (System.currentTimeMillis() - cleanStart) + " ms"); + LOG.info("Cleaned output directories in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - cleanStart) + " ms"); } private static boolean isEmpty(File outputRoot) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildTargetSourcesState.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildTargetSourcesState.java index d786958709e2..a022fc04b9f9 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildTargetSourcesState.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildTargetSourcesState.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.incremental.storage; import com.google.gson.Gson; @@ -37,6 +37,7 @@ import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; import static org.jetbrains.jps.incremental.storage.MurmurHashingService.HASH_SIZE; import static org.jetbrains.jps.incremental.storage.MurmurHashingService.getStringHash; @@ -93,7 +94,7 @@ public class BuildTargetSourcesState implements BuildListener { public void reportSourcesState() { if (reportStateUnavailable()) return; - long start = System.currentTimeMillis(); + long start = System.nanoTime(); Map> targetTypeHashMap = loadCurrentTargetState(); List> buildTargets; @@ -124,7 +125,7 @@ public class BuildTargetSourcesState implements BuildListener { catch (IOException e) { LOG.warn("Unable to save sources state", e); } - LOG.info("Build target sources report took: " + (System.currentTimeMillis() - start) + " ms"); + LOG.info("Build target sources report took: " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start) + " ms"); } public void clearSourcesState() { diff --git a/jps/jps-builders/src/org/jetbrains/jps/javac/ExternalJavacManager.java b/jps/jps-builders/src/org/jetbrains/jps/javac/ExternalJavacManager.java index dd97179ee717..c6236265947e 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/javac/ExternalJavacManager.java +++ b/jps/jps-builders/src/org/jetbrains/jps/javac/ExternalJavacManager.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.javac; import com.intellij.execution.process.*; @@ -492,16 +492,16 @@ public class ExternalJavacManager extends ProcessAdapter { public synchronized long getIdleTime() { final long idleSince = myIdleSince; - return idleSince <= 0L? 0L : (System.currentTimeMillis() - idleSince); + return idleSince == -42L? 0L : TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - idleSince); } public synchronized void unlock() { - myIdleSince = System.currentTimeMillis(); + myIdleSince = System.nanoTime(); myIsBusy = false; } public synchronized boolean lock() { - myIdleSince = 0L; + myIdleSince = -42L; return !myIsBusy && (myIsBusy = true); } diff --git a/jps/model-serialization/src/org/jetbrains/jps/TimingLog.java b/jps/model-serialization/src/org/jetbrains/jps/TimingLog.java index 8c9663b42e3a..fc7c8f3aedbd 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/TimingLog.java +++ b/jps/model-serialization/src/org/jetbrains/jps/TimingLog.java @@ -1,23 +1,11 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.EmptyRunnable; +import java.util.concurrent.TimeUnit; + public class TimingLog { public static final Logger LOG = Logger.getInstance(TimingLog.class); @@ -25,7 +13,7 @@ public class TimingLog { if (!LOG.isDebugEnabled()) { return EmptyRunnable.INSTANCE; } - final long start = System.currentTimeMillis(); - return () -> LOG.debug(name + " in " + (System.currentTimeMillis() - start) + "ms"); + final long start = System.nanoTime(); + return () -> LOG.debug(name + " in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start) + "ms"); } } diff --git a/jps/model-serialization/testSrc/org/jetbrains/jps/model/serialization/JpsProjectSerializationTest.java b/jps/model-serialization/testSrc/org/jetbrains/jps/model/serialization/JpsProjectSerializationTest.java index 7c8a27bb6ec2..628dfa156891 100644 --- a/jps/model-serialization/testSrc/org/jetbrains/jps/model/serialization/JpsProjectSerializationTest.java +++ b/jps/model-serialization/testSrc/org/jetbrains/jps/model/serialization/JpsProjectSerializationTest.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.model.serialization; import com.intellij.openapi.application.PathManager; @@ -25,6 +25,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import static com.intellij.testFramework.assertions.Assertions.assertThat; @@ -290,10 +291,10 @@ public class JpsProjectSerializationTest extends JpsSerializationTestCase { } public void testLoadIdeaProject() { - long start = System.currentTimeMillis(); + long start = System.nanoTime(); loadProjectByAbsolutePath(PathManager.getHomePath()); assertTrue(myProject.getModules().size() > 0); System.out.println("JpsProjectSerializationTest: " + myProject.getModules().size() + " modules, " + myProject.getLibraryCollection().getLibraries().size() + " libraries and " + - JpsArtifactService.getInstance().getArtifacts(myProject).size() + " artifacts loaded in " + (System.currentTimeMillis() - start) + "ms"); + JpsArtifactService.getInstance().getArtifacts(myProject).size() + " artifacts loaded in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start) + "ms"); } } diff --git a/jps/standalone-builder/src/org/jetbrains/jps/build/Standalone.java b/jps/standalone-builder/src/org/jetbrains/jps/build/Standalone.java index b5e38b8170fe..f97c3d4a2e80 100644 --- a/jps/standalone-builder/src/org/jetbrains/jps/build/Standalone.java +++ b/jps/standalone-builder/src/org/jetbrains/jps/build/Standalone.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.build; import com.intellij.openapi.util.Disposer; @@ -24,6 +24,7 @@ import org.jetbrains.jps.service.SharedThreadPool; import java.io.File; import java.util.*; +import java.util.concurrent.TimeUnit; import static org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope; @@ -130,7 +131,7 @@ public class Standalone { } ConsoleMessageHandler consoleMessageHandler = new ConsoleMessageHandler(); - long start = System.currentTimeMillis(); + long start = System.nanoTime(); try { runBuild(loader, dataStorageRoot, !incremental, modulesSet, allModules, artifactsList, allArtifacts, true, consoleMessageHandler); @@ -139,7 +140,7 @@ public class Standalone { System.err.println("Internal error: " + t.getMessage()); t.printStackTrace(); } - System.out.println("Build finished in " + Utils.formatDuration(System.currentTimeMillis() - start)); + System.out.println("Build finished in " + Utils.formatDuration(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start))); return consoleMessageHandler.hasErrors() ? 1 : 0; }