Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

profiler 命令需要增加测试,检查文档里的使用说明 #2961

Open
hengyunabc opened this issue Nov 26, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@hengyunabc
Copy link
Collaborator

升级 async-profiler 版本之后,增加了很多选项。导致实际上有的选项可能根本不工作,或者文档的内容不对。

比如 profiler start --loop 1h -f /var/log/profile-%t.jfr4.0.4 版本会失败。

2024-11-26 16:46:54 [arthas-command-execute] ERROR c.t.a.c.s.system.impl.ProcessImpl -Error during processing the command:
com.taobao.middleware.cli.CLIException: Cannot inject value for option 'loop'
        at com.taobao.middleware.cli.annotations.CLIConfigurator.inject(CLIConfigurator.java:257)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:81)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)
        at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:385)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException: null
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.taobao.middleware.cli.annotations.CLIConfigurator.inject(CLIConfigurator.java:254)
        ... 12 common frames omitted
Caused by: java.lang.NullPointerException: null
        at com.taobao.arthas.core.command.monitor200.ProfilerCommand.setLoop(ProfilerCommand.java:527)
        ... 17 common frames omitted

原因是在 https://github.com/alibaba/arthas/pull/2685/files#diff-31021667a755f6fcc9789a6f31fee49b592a9caa1cf560cc5d77c3f42a18ecd7R475

没有考虑 action 可能是 null 。


根本原因是 cli 在注入配置时,获取到的 methods 顺序可能是随机的。

The elements in the returned array are not sorted and are not in any particular order.

    public static void inject(CommandLine cli, Object object) throws CLIException {
        final List<Method> methods = ReflectionUtils.getSetterMethods(object.getClass());
        for (Method method : methods) {
            Option option = method.getAnnotation(Option.class);
            Argument argument = method.getAnnotation(Argument.class);
            if (option != null) {
                String name = option.longName();
                if (name == null) {
                    name = option.shortName();
                }
                try {
                    Object injected = getOptionValue(method, name, cli);
                    if (injected != null) {
                        method.setAccessible(true);
                        method.invoke(object, injected);
                    }
                } catch (Exception e) {
                    throw new CLIException("Cannot inject value for option '" + name + "'", e);
                }
            }
@hengyunabc hengyunabc added the bug Something isn't working label Nov 26, 2024
@hengyunabc
Copy link
Collaborator Author

关联 pr: #2685

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant