Commit f1ec86d0 authored by Roman Shevchenko's avatar Roman Shevchenko Committed by intellij-monorepo-bot
Browse files

[tests] less noisy logging in file watcher tests

GitOrigin-RevId: 934035818e9ae1eed84927a7e5ed4f22d1d8c000
parent 0232c2fc
Branches unavailable Tags unavailable
No related merge requests found
Showing with 26 additions and 27 deletions
+26 -27
......@@ -2,7 +2,7 @@
package com.intellij.openapi.vfs.impl.local
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.util.Pair
import com.intellij.openapi.util.io.IoTestUtil.assumeNioSymLinkCreationIsSupported
import com.intellij.openapi.vfs.LocalFileSystem
......@@ -30,7 +30,7 @@ import kotlin.test.assertFalse
@SkipSlowTestLocally
class WatchRootsManagerPerformanceTest : BareTestFixtureTestCase() {
//<editor-fold desc="Set up / tear down">
private val LOG: Logger by lazy { Logger.getInstance(NativeFileWatcherImpl::class.java) }
private val LOG = logger<WatchRootsManagerPerformanceTest>()
@Rule @JvmField val tempDir = TempDirectory()
......
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.vfs.local
import com.intellij.openapi.diagnostic.LogLevel
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.impl.local.FileWatcher
import com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl
import com.intellij.openapi.vfs.impl.local.NativeFileWatcherImpl
import com.intellij.openapi.vfs.local.FileWatcherTestUtil.INTER_RESPONSE_DELAY
import com.intellij.openapi.vfs.local.FileWatcherTestUtil.shutdown
import com.intellij.openapi.vfs.local.FileWatcherTestUtil.startup
......@@ -16,7 +13,10 @@ import com.intellij.testFramework.fixtures.BareTestFixtureTestCase
import com.intellij.testFramework.rules.TempDirectory
import com.intellij.util.TimeoutUtil
import org.assertj.core.api.Assertions.assertThat
import org.junit.*
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import java.io.File
import java.util.concurrent.atomic.AtomicInteger
......@@ -28,7 +28,6 @@ private const val NUM_FILES = 1000
class FileWatcherPerformanceTest : BareTestFixtureTestCase() {
@Rule @JvmField val tempDir: TempDirectory = TempDirectory()
private var tracing: Boolean = false
private lateinit var watcher: FileWatcher
private val events = AtomicInteger(0)
private val resets = AtomicInteger(0)
......@@ -42,17 +41,9 @@ class FileWatcherPerformanceTest : BareTestFixtureTestCase() {
}
@Before fun setUp() {
val logger = Logger.getInstance(NativeFileWatcherImpl::class.java)
tracing = logger.isTraceEnabled
if (tracing) logger.setLevel(LogLevel.WARNING)
watcher = (LocalFileSystem.getInstance() as LocalFileSystemImpl).fileWatcher
}
@After
fun tearDown() {
if (tracing) Logger.getInstance(NativeFileWatcherImpl::class.java).setLevel(LogLevel.TRACE)
}
@Test fun watcherOverhead() {
var unwatchedTime = 0L
var watchedTime = 0L
......@@ -111,4 +102,4 @@ class FileWatcherPerformanceTest : BareTestFixtureTestCase() {
lastCount = newCount
}
}
}
\ No newline at end of file
}
......@@ -4,7 +4,7 @@ package com.intellij.openapi.vfs.local
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.IoTestUtil
......@@ -28,12 +28,9 @@ import com.intellij.openapi.vfs.local.FileWatcherTestUtil.wait
import com.intellij.openapi.vfs.local.FileWatcherTestUtil.watch
import com.intellij.openapi.vfs.newvfs.NewVirtualFile
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.RunAll
import com.intellij.testFramework.VfsTestUtil
import com.intellij.testFramework.*
import com.intellij.testFramework.fixtures.BareTestFixtureTestCase
import com.intellij.testFramework.rules.TempDirectory
import com.intellij.testFramework.runInEdtAndWait
import com.intellij.util.Alarm
import com.intellij.util.TimeoutUtil
import com.intellij.util.concurrency.Semaphore
......@@ -54,7 +51,7 @@ import java.util.concurrent.atomic.AtomicBoolean
class FileWatcherTest : BareTestFixtureTestCase() {
//<editor-fold desc="Set up / tear down">
private val LOG: Logger by lazy { Logger.getInstance(NativeFileWatcherImpl::class.java) }
private val LOG = logger<FileWatcherTest>()
@Rule @JvmField val tempDir = TempDirectory()
......@@ -68,6 +65,7 @@ class FileWatcherTest : BareTestFixtureTestCase() {
private val resetHappened = AtomicBoolean()
@Before fun setUp() {
TestLoggerFactory.enableTraceLogging(testRootDisposable, NativeFileWatcherImpl::class.java, FileWatcherTest::class.java)
LOG.debug("================== setting up " + getTestName(false) + " ==================")
fs = LocalFileSystem.getInstance()
......
......@@ -4,7 +4,7 @@ package com.intellij.openapi.vfs.local
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.IoTestUtil.*
......@@ -48,7 +48,7 @@ import java.util.concurrent.atomic.AtomicBoolean
class WslFileWatcherTest : BareTestFixtureTestCase() {
//<editor-fold desc="Set up / tear down">
companion object {
private val LOG: Logger by lazy { Logger.getInstance(WslFileWatcher::class.java) }
private val LOG = logger<WslFileWatcherTest>()
private val WSL: String? by lazy { enumerateWslDistributions().firstOrNull() }
}
......@@ -71,6 +71,7 @@ class WslFileWatcherTest : BareTestFixtureTestCase() {
wsl = WSL!!
assumeTrue("WSL distribution ${wsl} doesn't seem to be alive", reanimateWslDistribution(wsl))
TestLoggerFactory.enableTraceLogging(testRootDisposable, WslFileWatcher::class.java, FileWatcherTest::class.java)
LOG.debug("================== setting up " + getTestName(false) + " ==================")
tempDir = createWslTempDir(wsl, getTestName(false))
......
......@@ -164,6 +164,17 @@ public final class TestLoggerFactory implements Logger.Factory {
}
}
public static void enableTraceLogging(@NotNull Disposable parentDisposable, Class<?> @NotNull ... classes) {
for (var klass : classes) {
var category = '#' + klass.getName();
var logger = Logger.getInstance(category);
if (!logger.isTraceEnabled()) {
logger.setLevel(LogLevel.TRACE);
Disposer.register(parentDisposable, () -> logger.setLevel(LogLevel.INFO));
}
}
}
private void buffer(LogLevel level, String category, @Nullable String message, @Nullable Throwable t) {
var source = category.substring(Math.max(category.length() - 30, 0));
var format = String.format("%1$tH:%1$tM:%1$tS,%1$tL %2$-6s %3$30s - ", System.currentTimeMillis(), level.getLevelName(), source);
......
\#com.intellij.openapi.vfs.impl.local.NativeFileWatcherImpl.level=FINER
\#com.intellij.openapi.vfs.impl.wsl.WslFileWatcher.level=FINER
\#com.intellij.idea.SocketLock.level=FINER
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment