Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ tasks.runIde {
jvmArgs("-ea")

// Copy over some JVM args from IntelliJ.
jvmArgs("-XX:ReservedCodeCacheSize=240m")
jvmArgs("-XX:ReservedCodeCacheSize=512m")
jvmArgs("-XX:+UseConcMarkSweepGC")
jvmArgs("-XX:SoftRefLRUPolicyMSPerMB=50")
jvmArgs("-XX:CICompilerCount=2")
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/google/idea/perf/tracer/TracerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.google.idea.perf.tracer

import com.google.idea.perf.tracer.TraceOption.COUNT_AND_WALL_TIME
import com.google.idea.perf.tracer.TraceOption.COUNT_ONLY
import com.google.idea.perf.tracer.TraceOption.UNTRACE

/** A tracer CLI command */
sealed class TracerCommand {
Expand Down Expand Up @@ -56,7 +57,8 @@ sealed class TracerCommand {
/** Represents what to trace */
enum class TraceOption {
COUNT_AND_WALL_TIME,
COUNT_ONLY;
COUNT_ONLY,
UNTRACE;
}

/** A set of methods that the tracer will trace. */
Expand All @@ -68,7 +70,9 @@ sealed class TraceTarget {
data class Method(
val className: String,
val methodName: String?,
val parameterIndexes: List<Int>? = emptyList()
val parameterIndexes: List<Int>? = emptyList(),
// a redundant option to support user config tab
var traceOption: TraceOption = COUNT_AND_WALL_TIME
): TraceTarget()

val errors: List<String>
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/com/google/idea/perf/tracer/TracerController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,19 @@ class TracerController(
// Special case: handle this command while we're still on the EDT.
val path = cmd.substringAfter("save").trim()
savePngFromEdt(path)
}
else {
} else {
executor.execute { handleCommand(cmd) }
}
}

private fun handleCommand(commandString: String) {
fun handleCommand(commandString: String) {
val command = parseMethodTracerCommand(commandString)
val errors = command.errors

if (errors.isNotEmpty()) {
displayWarning(errors.joinToString("\n"))
return
}

handleCommand(command)
}

Expand All @@ -109,25 +107,34 @@ class TracerController(
is TracerCommand.Clear -> {
CallTreeManager.clearCallTrees()
}

is TracerCommand.Reset -> {
TracerUserConfig.resetAll()
runWithProgress { progress ->
val oldRequests = TracerConfig.clearAllRequests()
val affectedClasses = TracerConfigUtil.getAffectedClasses(oldRequests)
retransformClasses(affectedClasses, progress)
CallTreeManager.clearCallTrees()
}
}

is TracerCommand.Trace -> {
val countOnly = command.traceOption == TraceOption.COUNT_ONLY

when (command.target) {
is TraceTarget.All -> {
when {
command.enable -> displayWarning("Cannot trace all classes")
else -> handleCommand(TracerCommand.Reset)
}
}

is TraceTarget.Method -> {
if (command.enable) {
TracerUserConfig.addUserTraceRequest(command.target)
} else {
command.target.traceOption = TraceOption.UNTRACE
TracerUserConfig.addUserUntraceRequest(command.target)
}
runWithProgress { progress ->
val clazz = command.target.className
val method = command.target.methodName ?: "*"
Expand All @@ -145,6 +152,7 @@ class TracerController(
}
}
}

else -> {
displayWarning("Command not implemented")
}
Expand All @@ -165,11 +173,9 @@ class TracerController(
progress.checkCanceled()
try {
instrumentation.retransformClasses(clazz)
}
catch (e: UnmodifiableClassException) {
} catch (e: UnmodifiableClassException) {
LOG.info("Cannot instrument non-modifiable class: ${clazz.name}")
}
catch (e: Throwable) {
} catch (e: Throwable) {
LOG.error("Failed to retransform class: ${clazz.name}", e)
}
if (!progress.isIndeterminate) {
Expand All @@ -195,8 +201,7 @@ class TracerController(
getApplication().executeOnPooledThread {
try {
ImageIO.write(img, "png", file)
}
catch (e: IOException) {
} catch (e: IOException) {
displayWarning("Failed to write png to $path", e)
}
}
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/com/google/idea/perf/tracer/TracerUserConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2021 Google LLC
*
* 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
*
* https://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.
*/

package com.google.idea.perf.tracer

import java.util.*

/**
* [TracerUserConfig] keeps track of which methods should be traced and `untrace`d.
* When a user `untrace`s some request, it will be removed if it was created before.
*/
object TracerUserConfig {

private val userTraceRequests = Collections.synchronizedMap(LinkedHashMap<String, TraceTarget.Method>())

fun cloneUserTraceRequests(): List<TraceTarget.Method> {
return userTraceRequests.values.toList()
}

fun addUserTraceRequest(entry: TraceTarget.Method) {
val plainTextKey = concatClassAndMethod(entry)
userTraceRequests[plainTextKey] = entry
}

@Synchronized
fun addUserUntraceRequest(entry: TraceTarget.Method) {
val classAndMethod = concatClassAndMethod(entry)
val value = userTraceRequests[classAndMethod]
if (value != null && value.traceOption != TraceOption.UNTRACE) {
userTraceRequests.remove(classAndMethod)
} else {
userTraceRequests[classAndMethod] = entry
}
}

@Synchronized
fun resetAll() {
val keys = userTraceRequests.keys.toList()
for (key in keys) {
userTraceRequests.remove(key)
}
}

private fun concatClassAndMethod(entry: TraceTarget.Method): String {
return "${entry.className}#${entry.methodName ?: ""}"
}

}
55 changes: 55 additions & 0 deletions src/main/java/com/google/idea/perf/tracer/ui/TracerConfigTab.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2021 Google LLC
*
* 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
*
* https://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.
*/

package com.google.idea.perf.tracer.ui

import com.google.idea.perf.tracer.TraceOption
import com.google.idea.perf.tracer.TraceTarget
import com.intellij.ui.components.JBTextArea

/** Displays a list of trace/untrace commands as plain text. */
class TracerConfigTab : JBTextArea() {

private var previousCommandsList: List<TraceTarget.Method> = emptyList()

fun setTracingConfig(newStats: List<TraceTarget.Method>) {
if (previousCommandsList == newStats) {
return
}
previousCommandsList = newStats
document.remove(0, document.length)
val tmp = newStats.joinToString(
separator = "\n",
transform = TracerConfigTab::methodToString
)
append(tmp)
}

companion object {
private fun methodToString(method: TraceTarget.Method): String {
val option = when (method.traceOption) {
TraceOption.COUNT_AND_WALL_TIME -> "trace"
TraceOption.COUNT_ONLY -> "trace count"
TraceOption.UNTRACE -> "untrace"
}
if (method.methodName == "*") {
return "$option ${method.className}"
} else {
return "$option ${method.className}::${method.methodName}"
}
}
}
}
19 changes: 15 additions & 4 deletions src/main/java/com/google/idea/perf/tracer/ui/TracerPanel.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Google LLC
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,9 @@ package com.google.idea.perf.tracer.ui
import com.google.idea.perf.tracer.CallTreeManager
import com.google.idea.perf.tracer.CallTreeUtil
import com.google.idea.perf.tracer.TracerController
import com.google.idea.perf.tracer.TracerUserConfig
import com.google.idea.perf.util.formatNsInMs
import com.google.idea.perf.util.onDispose
import com.intellij.CommonBundle
import com.intellij.ide.BrowserUtil
import com.intellij.openapi.Disposable
Expand All @@ -29,7 +31,6 @@ import com.intellij.openapi.editor.ex.util.EditorUtil
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.util.ProgressIndicatorBase
import com.intellij.openapi.project.Project
import com.google.idea.perf.util.onDispose
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.MessageType
import com.intellij.openapi.ui.popup.util.PopupUtil
Expand Down Expand Up @@ -64,7 +65,8 @@ import javax.swing.SwingConstants.HORIZONTAL

/**
* This is the main tracer panel containing the command line, call tree view,
* overhead labels, etc. It also polls for new call tree data in [updateCallTree].
* overhead labels, a config tab with tracing commands etc.
* It also polls for new call tree data in [updateCallTree].
*
* This panel is displayed via the [TracerDialog].
*/
Expand All @@ -78,6 +80,7 @@ class TracerPanel(
private var showingEdtOnly = false
private val listView: TracerTable
private val treeView: TracerTree
internal val configView: TracerConfigTab
private val tracingOverheadLabel: JBLabel
private val uiOverheadLabel: JBLabel
private var uiOverhead = 0L
Expand Down Expand Up @@ -158,6 +161,13 @@ class TracerPanel(
.setSideComponent(createTabSideComponent())
tabs.addTab(treeTab)

// Config view.
configView = TracerConfigTab()
val configTab = TabInfo(JBScrollPane(configView))
.setText("Config")
.setSideComponent(createTabSideComponent())
tabs.addTab(configTab)

// Tracing overhead label.
val overheadFont = JBFont
.create(EditorUtil.getEditorFont())
Expand Down Expand Up @@ -217,7 +227,7 @@ class TracerPanel(
}
}

private fun updateCallTree() {
fun updateCallTree() {
// In order to measure tracer UI overhead we need to measure the time it
// takes to update the tree model *and* the time it takes to run all the
// invokeLater tasks generated by the update (but, exclude the time for
Expand All @@ -239,6 +249,7 @@ class TracerPanel(
val stats = CallTreeUtil.computeFlatTracepointStats(treeSnapshot)
listView.setTracepointStats(stats)
treeView.setCallTree(treeSnapshot)
configView.setTracingConfig(TracerUserConfig.cloneUserTraceRequests())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this call be moved into TracerController (after new tracing commands are issued), rather than here inside the render loop?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configView seems similar to previous set calls in the same function. Controller wouldn't have access to it. Could you elaborate please if you think it's worth moving a call?


// Estimate tracing overhead.
val tracingOverhead = CallTreeUtil.estimateTracingOverhead(treeSnapshot)
Expand Down
Loading