Skip to content

Commit 5905c7c

Browse files
committed
added explanation of potential issues in comments.
1 parent dc9868f commit 5905c7c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

core/src/main/java/com/microsoft/applicationinsights/internal/perfcounter/JniPCConnector.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ public static double getValueOfPerformanceCounter(String name) {
156156
}
157157

158158
/**
159+
* Performance Counters identify a process by "Instance Name."
160+
* This will be the executable name without the extension, e.g. a process running java.exe will have an instance name "java".
161+
* If there are multiple instances of the same executable, an additional identifier is appended. By default this looks like "java#1", "java#2".
162+
* For some reason, the instance name can change after the process starts with the default naming scheme.
163+
*
164+
* To workaround this, add a DWORD registry value named 'ProcessNameFormat' set to the value '2' to the key
165+
* 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfProc\Performance'.
166+
* This changes the naming scheme from "java#2" to "java_PID" where PID is the current process id. It also makes the name constant for the life of the process.
167+
*
159168
* @throws NumberFormatException if pid cannot be parsed.
160169
*/
161170
private static void initNativeCode() {

core/src/main/java/com/microsoft/applicationinsights/internal/system/SystemInformation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public boolean isUnix() {
5050
return SystemUtils.IS_OS_UNIX;
5151
}
5252

53+
/**
54+
* JVMs are not required to publish this value/bean and some processes may not have permission to access it.
55+
*/
5356
private String initializeProcessId() {
5457
String rawName = ManagementFactory.getRuntimeMXBean().getName();
5558
if (!Strings.isNullOrEmpty(rawName)) {

0 commit comments

Comments
 (0)