Init default profile for perf tests

This commit is contained in:
Vladimir Dolzhenko
2020-05-15 22:40:33 +02:00
parent fb6ef38370
commit 7afadb9b5e
5 changed files with 69 additions and 33 deletions
@@ -170,6 +170,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
it.value?.let { project -> it.value?.let { project ->
lastProject = project lastProject = project
openAction.postOpenProject(openProject = openProject, project = project) openAction.postOpenProject(openProject = openProject, project = project)
openAction.initDefaultProfile(project)
logMessage { "project '$name' successfully opened" } logMessage { "project '$name' successfully opened" }
@@ -269,44 +269,40 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() {
note: String = "" note: String = ""
) { ) {
val project = myProject!! val project = myProject!!
val disposable = Disposer.newDisposable("perfKtsFileAnalysis $fileName") //val disposable = Disposer.newDisposable("perfKtsFileAnalysis $fileName")
enableAllInspectionsCompat(project, disposable) //enableAllInspectionsCompat(project, disposable)
replaceWithCustomHighlighter() replaceWithCustomHighlighter()
try { highlightFile {
highlightFile { val testName = "fileAnalysis ${notePrefix(note)}${simpleFilename(fileName)}"
val testName = "fileAnalysis ${notePrefix(note)}${simpleFilename(fileName)}" val extraStats = Stats("${stats.name} $testName")
val extraStats = Stats("${stats.name} $testName") val extraTimingsNs = mutableListOf<Map<String, Any>?>()
val extraTimingsNs = mutableListOf<Map<String, Any>?>()
val warmUpIterations = 20 val warmUpIterations = 20
val iterations = 30 val iterations = 30
performanceTest<Fixture, Pair<Long, List<HighlightInfo>>> { performanceTest<Fixture, Pair<Long, List<HighlightInfo>>> {
name(testName) name(testName)
stats(stats) stats(stats)
warmUpIterations(30) warmUpIterations(30)
iterations(50) iterations(50)
setUp(perfKtsFileAnalysisSetUp(project, fileName)) setUp(perfKtsFileAnalysisSetUp(project, fileName))
test(perfKtsFileAnalysisTest()) test(perfKtsFileAnalysisTest())
tearDown(perfKtsFileAnalysisTearDown(extraTimingsNs, project)) tearDown(perfKtsFileAnalysisTearDown(extraTimingsNs, project))
profilerEnabled(true) profilerEnabled(true)
}
extraStats.printWarmUpTimings(
"annotator",
extraTimingsNs.take(warmUpIterations).toTypedArray()
)
extraStats.appendTimings(
"annotator",
extraTimingsNs.drop(warmUpIterations).toTypedArray()
)
} }
} finally {
Disposer.dispose(disposable) extraStats.printWarmUpTimings(
"annotator",
extraTimingsNs.take(warmUpIterations).toTypedArray()
)
extraStats.appendTimings(
"annotator",
extraTimingsNs.drop(warmUpIterations).toTypedArray()
)
} }
} }
@@ -148,6 +148,7 @@ class KotlinFileSource : AbstractSource() {
class ProjectBuilder { class ProjectBuilder {
internal var buildGradle: String? = null internal var buildGradle: String? = null
internal lateinit var name: String internal lateinit var name: String
internal var initDefaultProfile: Boolean = true
private val kotlinFiles = mutableListOf<Pair<String, KotlinFileSource>>() private val kotlinFiles = mutableListOf<Pair<String, KotlinFileSource>>()
fun buildGradle(buildGradle: String) { fun buildGradle(buildGradle: String) {
@@ -158,6 +159,14 @@ class ProjectBuilder {
this.name = name this.name = name
} }
fun initDefaultProfile() {
this.initDefaultProfile = true
}
fun initDefaultProfile(initDefaultProfile: Boolean) {
this.initDefaultProfile = initDefaultProfile
}
fun kotlinFile(name: String, kotlinFileSource: KotlinFileSource.() -> Unit) { fun kotlinFile(name: String, kotlinFileSource: KotlinFileSource.() -> Unit) {
val source = KotlinFileSource().apply(kotlinFileSource) val source = KotlinFileSource().apply(kotlinFileSource)
kotlinFiles.add(Pair(name, source)) kotlinFiles.add(Pair(name, source))
@@ -223,5 +232,8 @@ fun openProject(initializer: ProjectBuilder.() -> Unit): Project {
) )
val project = ProjectOpenAction.openProject(openProject) val project = ProjectOpenAction.openProject(openProject)
openAction.postOpenProject(project = project, openProject = openProject) openAction.postOpenProject(project = project, openProject = openProject)
if (projectBuilder.initDefaultProfile) {
openAction.initDefaultProfile(project)
}
return project return project
} }
@@ -204,6 +204,9 @@ class Stats(
for ((k, v) in statInfo) { for ((k, v) in statInfo) {
if (k == TEST_KEY) continue if (k == TEST_KEY) continue
printStatValue("$n $k", v) printStatValue("$n $k", v)
(v as? Number)?.let {
printTestMetadata(n, k, it)
}
} }
printTestFinished(n, (statInfo[TEST_KEY] as Long).nsToMs) printTestFinished(n, (statInfo[TEST_KEY] as Long).nsToMs)
@@ -363,6 +366,10 @@ class Stats(
println("##teamcity[buildStatisticValue key='$name' value='$value']") println("##teamcity[buildStatisticValue key='$name' value='$value']")
} }
fun printTestMetadata(testName: String, name: String, value: Number) {
println("##teamcity[testMetadata testName='$testName' name='$name' type='number' value='$value']")
}
private fun printTestFinished(testName: String) { private fun printTestFinished(testName: String) {
println("##teamcity[testFinished name='$testName']") println("##teamcity[testFinished name='$testName']")
} }
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.idea.testFramework package org.jetbrains.kotlin.idea.testFramework
import com.intellij.codeInspection.ex.InspectionProfileImpl
import com.intellij.ide.highlighter.ModuleFileType import com.intellij.ide.highlighter.ModuleFileType
import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.application.runWriteAction
@@ -16,15 +17,18 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ex.ProjectManagerEx import com.intellij.openapi.project.ex.ProjectManagerEx
import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.vcs.changes.ChangeListManager import com.intellij.openapi.vcs.changes.ChangeListManager
import com.intellij.openapi.vcs.changes.ChangeListManagerImpl import com.intellij.openapi.vcs.changes.ChangeListManagerImpl
import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
import com.intellij.testFramework.PsiTestUtil import com.intellij.testFramework.PsiTestUtil
import com.intellij.testFramework.UsefulTestCase import com.intellij.testFramework.UsefulTestCase.assertTrue
import com.intellij.util.io.exists import com.intellij.util.io.exists
import org.jetbrains.kotlin.idea.configuration.getModulesWithKotlinFiles import org.jetbrains.kotlin.idea.configuration.getModulesWithKotlinFiles
import org.jetbrains.kotlin.idea.perf.Stats.Companion.runAndMeasure import org.jetbrains.kotlin.idea.perf.Stats.Companion.runAndMeasure
import org.jetbrains.kotlin.idea.perf.enableAllInspectionsCompat
import org.jetbrains.kotlin.idea.project.getAndCacheLanguageLevelByDependencies import org.jetbrains.kotlin.idea.project.getAndCacheLanguageLevelByDependencies
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import java.io.File import java.io.File
@@ -131,7 +135,7 @@ enum class ProjectOpenAction {
}.get() }.get()
val modules = ModuleManager.getInstance(project).modules val modules = ModuleManager.getInstance(project).modules
UsefulTestCase.assertTrue("project ${openProject.projectName} has to have at least one module", modules.isNotEmpty()) assertTrue("project ${openProject.projectName} has to have at least one module", modules.isNotEmpty())
logMessage { "modules of ${openProject.projectName}: ${modules.map { m -> m.name }}" } logMessage { "modules of ${openProject.projectName}: ${modules.map { m -> m.name }}" }
@@ -140,6 +144,22 @@ enum class ProjectOpenAction {
//runWriteAction { project.save() } //runWriteAction { project.save() }
} }
fun initDefaultProfile(project: Project) {
val projectInspectionProfileManager = ProjectInspectionProfileManager.getInstance(project)
projectInspectionProfileManager.forceLoadSchemes()
val projectProfile = projectInspectionProfileManager.projectProfile ?: error("project has to have non null profile name")
val profile = projectInspectionProfileManager.getProfile(projectProfile)
InspectionProfileImpl.INIT_INSPECTIONS = true
profile.initInspectionTools(project)
val enabledTools = profile.getAllEnabledInspectionTools(project)
assertTrue(
"project ${project.name} has to have at least one enabled inspection in profile",
enabledTools.isNotEmpty()
)
InspectionProfileImpl.INIT_INSPECTIONS = false
}
companion object { companion object {
fun openProject(openProject: OpenProject): Project { fun openProject(openProject: OpenProject): Project {
val project = openProject.projectOpenAction.openProject( val project = openProject.projectOpenAction.openProject(