Skip to content

Commit e28053c

Browse files
marcopennekampyanex
authored andcommitted
Add a guide page about Analysis API statistics
1 parent a092f02 commit e28053c

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

Writerside/hi.tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<toc-element topic="KaDiagnosticWithPsi.md"/>
8383
</toc-element>
8484
<toc-element topic="File-Compilation.md"/>
85+
<toc-element topic="Statistics.md"/>
8586
</toc-element>
8687
<toc-element topic="Migrating-from-K1.md">
8788
<toc-element topic="Declaring-K2-Compatibility.md"/>
Loading
Loading

Writerside/topics/Statistics.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Statistics
2+
3+
When run with the IntelliJ Kotlin plugin, the Analysis API optionally allows gathering statistics (such as metrics)
4+
about analysis activity. All data is saved **locally** in a log file. It is *not* sent over any network connection.
5+
Furthermore, the feature requires an explicit opt-in.
6+
7+
These statistics allow us as Analysis API developers to better understand how the Analysis API handles certain
8+
workloads. For you as a user of the Analysis API, the statistics can also provide some insights into how your plugin
9+
uses the Analysis API. The log files are easily shareable, allowing you to send them to us if you encounter any
10+
problems (especially around performance and memory consumption) or include them in your YouTrack issues.
11+
12+
As of now, we are tracking only a few metrics, but we're planning to add many more. It's also worth noting that only the
13+
K2 backend of the Analysis API collects statistics.
14+
15+
The feature is built on the same OpenTelemetry-based framework as IntelliJ's tracing and metrics collection, so using
16+
the approach described in this guide can also help with IntelliJ-specific statistics such as virtual file system
17+
metrics. The framework is mainly developed for internal use: it is not a public API and JetBrains makes no compatibility
18+
guarantees. Nonetheless, you're welcome to use it as an external user.
19+
20+
## Configuration
21+
22+
To enable the local Analysis API statistics collection in IntelliJ IDEA, open the
23+
[Registry](https://stackoverflow.com/questions/28415695/how-do-you-set-a-value-in-the-intellij-registry) and enable the
24+
following setting:
25+
26+
```
27+
kotlin.analysis.statistics
28+
```
29+
30+
If the registry setting isn't listed, it is likely that that version of IntelliJ is not recent enough.
31+
32+
After enabling the setting, restart the IDE. It will automatically begin to collect Analysis API metrics and write them
33+
to a local log file.
34+
35+
By default, metrics are collected every 60 seconds. This is a coarse-grained view and may not be sufficient for every
36+
use case. To specify more granular collection, the interval can be adjusted with a
37+
[system property](https://www.jetbrains.com/help/idea/tuning-the-ide.html#configure-jvm-options). For example, to
38+
specify an interval of one second (1000ms):
39+
40+
```
41+
-Didea.diagnostic.opentelemetry.metrics-reporting-period-ms=1000
42+
```
43+
44+
It is recommended to enable `kotlin.analysis.statistics` only when needed, as it will impact performance. For example,
45+
we increment counters in hot spots like symbol providers. The metrics reporting period also contributes to the
46+
performance impact, not only for Analysis API statistics, but more broadly all metrics that IntelliJ locally collects
47+
with OpenTelemetry. So it's best to use these settings only temporarily.
48+
49+
## Locating & plotting metrics
50+
51+
The collected metrics will be written into a CSV file in IntelliJ's
52+
[log folder](https://intellij-support.jetbrains.com/hc/en-us/articles/207241085-Locating-IDE-log-files). The file should
53+
be called `open-telemetry-metrics.<date>-<time>.csv`. There may be multiple files from multiple runs, and usually the
54+
most recent file is the relevant one.
55+
56+
The CSV file contains not only Analysis API metrics, but all metrics collected by IntelliJ (such as virtual file system
57+
metrics). You can share this file with us, for example together with a
58+
[new YouTrack issue](https://youtrack.jetbrains.com/newIssue?project=KT).
59+
60+
You can also open the CSV file in the dedicated metrics plotter. Open `open-telemetry-metrics-plotter.html`, which is
61+
in the same log folder as the CSV, in your browser. You should see the following page:
62+
63+
![](statistics-metrics-plotter-open-file.png)
64+
65+
Drag the CSV file onto the page or open it with the file chooser.
66+
67+
The website will show a few default graphs, but none of them are directly related to the Analysis API. To plot Analysis
68+
API metrics, scroll to the last section "Plot other". In the drop-down menu, search for `kotlin.analysis` and select the
69+
metrics you're interested in. For example, you can select `kotlin.analysis.analysisSessions.anlyze.invocations` to check
70+
the number of `analyze` invocations.
71+
72+
![](statistics-metrics-plotter-analyze-invocations.png)

0 commit comments

Comments
 (0)