spark

spark

118M Downloads

standalone profiling agent `Failed to attach agent`

ZZZank opened this issue · 3 comments

commented

Description

I'm unable to use Spark standalone agent on any known Java application.

I've tried attaching Spark agent to

  • Minecraft 1.16.5 Forge
  • Minecraft 1.18.2 Fabric
  • Minecraft 1.20.1 Forge
  • JConsole
  • A simple program with Thread.sleep() and infinity loop (to make sure Java GC happens)

but none of them works.

There's an example where I tried to use Spark on JConsole:

PS D:\Minecraft\MCres\Tool\spark> java -jar .\spark-1.10.123-standalone-agent.jar
Usage: java -jar spark-standalone-agent.jar <pid> [args...]
Current JVM processes:
  pid=1960 (.\spark-1.10.123-standalone-agent.jar)
  pid=3500 (jdk.jconsole/sun.tools.jconsole.JConsole)
PS D:\Minecraft\MCres\Tool\spark> java -jar spark-1.10.123-standalone-agent.jar 3500
Failed to attach agent to process 3500
com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute
        at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:164)
        at me.lucko.spark.standalone.StandaloneSparkAgent.main(StandaloneSparkAgent.java:56)

Reproduction Steps

  • start any Java Application and get its PID
  • run java -jar spark-1.10.123-standalone-agent.jar <PID> in terminal (Windows Terminal in my case)
  • it crashed, reporting Failed to attach agent to process 3500 com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute

Expected Behaviour

no crash

Platform Information

  • Java: Zulu 21
  • OS: Windows 24H2, x64

Spark Version

spark-1.10.123-standalone-agent

Logs and Configs

No response

Extra Details

No response

commented

That error is safe to ignore :)

commented

Thanks for the detailed report - I was able to reproduce the issue in a Windows VM and implement a fix :)

Please could you test again with the latest version and let me know if that has fixed things?

commented

It works! I attached Spark to JConsole and profiled it once:

Image

But when stopping profilers, even though report can be generated and uploaded (https://spark.lucko.me/IbdFuh1kC3), Spark reports an exception. But I assume that I can ignore this? Since Spark said:

[⚡] If the command subsequently completes without any errors, this warning should be ignored. :)

The exception Spark reported when generating report:

[⚡] Profiler operation failed unexpectedly. Error: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@2b982444[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@303cdc94[Wrapped task = me.lucko.spark.common.sampler.java.JavaSampler$InsertDataTask@216df3a2]] rejected from java.util.concurrent.ScheduledThreadPoolExecutor@48497e7[Shutting down, pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 15139]
[⚡] Profiler operation failed unexpectedly
[⚡] java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@2b982444[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@303cdc94[Wrapped task = me.lucko.spark.common.sampler.java.JavaSampler$InsertDataTask@216df3a2]] rejected from java.util.concurrent.ScheduledThreadPoolExecutor@48497e7[Shutting down, pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 15139]
	at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2081)
	at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:841)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:340)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:562)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:705)
	at me.lucko.spark.common.sampler.java.JavaSampler.run(JavaSampler.java:137)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
	at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)