GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Automatically classify execution samples into categories · Issue #719 · async-profiler/async-profiler

Automatically classify execution samples into categories #719

New issue
Copy link
New issue
Copy link
Closed
Closed
Automatically classify execution samples into categories#719
Copy link
Labels
enhancement

Description

@apangin
apangin
opened on Feb 26, 2023
Issue body actions

When analyzing a flame graph, one often asks questions like

  • How many time in total was spent on class loading?
  • What percentage of time Java code was running in the interpreter and in C1/C2 compiled methods?
  • What is the impact of lambdas on the startup time?
  • etc.

To assist in performance analysis, async-profiler can automatically classify stack traces into certain categories.
Examples of such categories would be

  • Garbage collection
  • JIT compilation
  • Class loading
  • Class verification
  • Lambda bootstrapping
  • itable/vtable dispatch overhead
  • Running in the Interpreter
  • VM runtime
  • and so on.
Reacted by Ismael Juma, Peter Veentjer, liuzhengyang and Xie Junfeng
Reacted by Louis FRULEUX, Ismael Juma, Peter Veentjer, Jiajing LU, Johannes Bechberger and Francesco Nigro

Activity

Next
  1. apangin commented on Feb 26, 2023

    @apangin
    apangin
    on Feb 26, 2023
    CollaboratorAuthor
    More actions

    A new option to jfr2flame converter was introduced: --classify.
    It groups samples by adding a special frame at the root of the stack trace with the category name:

    classify

    The classifier works only with async-profiler recordings in .jfr format. --cstack dwarf option is recommended for better accuracy,

  2. apangin
    added a commit that references this issue on Feb 26, 2023

    #719: Automatically classify execution samples into categories

    a8f20eb
  3. apangin commented on Feb 26, 2023

    @apangin
    apangin
    on Feb 26, 2023
    CollaboratorAuthor
    More actions

    The initial implementation of the classifier was pushed.

    Currently supported categories:

    • [gc] - GC worker threads.
    • [jit] - JIT compilation.
    • [vm] - Activity inside the JVM runtime: reflection, parking/unparking, JNI upcalls, stop-the-world operations, etc.
    • [native] - Execution inside native functions.
    • [Interpreter] - Java code running in the interpreter.
    • [c1_comp], [c2_comp] - Execution of C1/C2 compiled code.
    • [c2i_adapter] - Calling compiled-to-interpreted adapters.
    • [class::init] - VM-level class initialization (excluding execution of static initializers).
    • [class::load] - ClassLoader activity: lookup, JAR loading, new class definition.
    • [class::resolve] - Class resolution/linking.
    • [class::verify] - Class verification.
    • [lambda::init] - Bootstrapping of lambdas: initial construction and linking of a lambda implementation.

    More categories to come later.

    Note that categories are mutually exclusive, e.g. if URLClassLoader runs some C2-compiled code, it will be classified as [class::load] but not [c2_comp].

  4. franz1981 commented on Feb 26, 2023

    @franz1981
    franz1981
    on Feb 26, 2023
    More actions

    Lovely, that's a great addition Andrei!

  5. apangin
    added
    enhancement
    on Feb 27, 2023
  6. schrepfler commented on Feb 27, 2023

    @schrepfler
    schrepfler
    on Feb 27, 2023
    More actions

    Can this be used to perhaps group by thread (by name)?

  7. apangin commented on Feb 27, 2023

    @apangin
    apangin
    on Feb 27, 2023
    CollaboratorAuthor
    More actions

    @schrepfler What do you mean? There has always been the option --threads to group samples by thread.

    Reacted by Srepfler Srdan
  8. pveentjer commented on Feb 27, 2023

    @pveentjer
    pveentjer
    on Feb 27, 2023
    More actions

    This seems like a very useful feature.

    Will there be an option to see both graphs in the same JMC? So you can switch between a view without classification and a view with? This way I don't need to collect 2 profiles.

  9. franz1981 commented on Feb 27, 2023

    @franz1981
    franz1981
    on Feb 27, 2023
    More actions

    This way I don't need to collect 2 profiles.

    I believe that, given that it applies to JFR you would collect events in JFR formats and specify the classify later, on the converter i.e. jfr2flame
    meaning that you collect data just one, but post-process twice

    Reacted by Andrei Pangin
  10. apangin commented on Feb 27, 2023

    @apangin
    apangin
    on Feb 27, 2023
    CollaboratorAuthor
    More actions

    @pveentjer @franz1981 Correct. The recording is not affected; you collect profile once and then use converter with different options to produce multiple views from it.

  11. krzysztofslusarski commented on Feb 27, 2023

    @krzysztofslusarski
    krzysztofslusarski
    on Feb 27, 2023
    Contributor
    More actions

    If you want to see more - a8f20eb - just changes in the converter, not in recording.

  12. parttimenerd commented on Feb 27, 2023

    @parttimenerd
    parttimenerd
    on Feb 27, 2023
    Contributor
    More actions

    Will there be an option to see both graphs in the same JMC?

    JMC does not support additional types. But I could implement in my IntelliJ Plugin :)

  13. krzysztofslusarski commented on Feb 27, 2023

    @krzysztofslusarski
    krzysztofslusarski
    on Feb 27, 2023
    Contributor
    More actions

    Will there be an option to see both graphs in the same JMC?

    JMC does not support additional types. But I could implement in my IntelliJ Plugin :)

    And because of that my viewer can't support it right now (I have JMC parser as dependency), I probably need to switch to Andrei's JFR parser sooner or later.

  14. franz1981 commented on Feb 27, 2023

    @franz1981
    franz1981
    on Feb 27, 2023
    More actions

    @krzysztofslusarski be aware that some JFR events collected by the JFR engine won't work if you do that eh, likely (even if the Andrei one is faster :P)

  15. parttimenerd commented on Feb 27, 2023

    @parttimenerd
    parttimenerd
    on Feb 27, 2023
    Contributor
    More actions

    Or it might be interesting to reuse the classification code and export it to a more generic classifier.

  16. 5 remaining items

  17. parttimenerd commented on Feb 27, 2023

    @parttimenerd
    parttimenerd
    on Feb 27, 2023
    Contributor
    More actions

    Why? Couldn't you just use a modified classifier on the JFR data directly without any use of one.jfr.JfrReader?

    I could export one.jfr.JfrReader in ap-loader if this helps.

  18. krzysztofslusarski commented on Feb 27, 2023

    @krzysztofslusarski
    krzysztofslusarski
    on Feb 27, 2023
    Contributor
    More actions

    I currently use JMC implementation of JFR parser where type is returned here:

            public IMCFrame.Type getType() {
                Object t = this.type;
                if (!(t instanceof IMCFrame.Type)) {
                    t = ParserToolkit.parseFrameType((String)t);
                    this.type = t;
                }
    
                return (IMCFrame.Type)t;
            }
    
        public static enum Type {
            JIT_COMPILED,
            INTERPRETED,
            INLINED,
            UNKNOWN;
           // ....
        }

    Async-profiler gives you more types as output and to correctly group the stacks you need to support more of them, not just those 4. I could create a subset of the functionality based on stack strings, but if I want to do it the same way as Anderi then I need all the supported types used in Classifier.

  19. parttimenerd commented on Feb 27, 2023

    @parttimenerd
    parttimenerd
    on Feb 27, 2023
    Contributor
    More actions

    I know, but I could implement a classifier that you could use to pass the JFR type, class name and method name of a frame. This method could then classify the frame. You then use this method to classify every frame in your application.

  20. krzysztofslusarski commented on Feb 27, 2023

    @krzysztofslusarski
    krzysztofslusarski
    on Feb 27, 2023
    Contributor
    More actions

    But that would need the type as integer or enum with values:

        public static final byte FRAME_INTERPRETED = 0;
        public static final byte FRAME_JIT_COMPILED = 1;
        public static final byte FRAME_INLINED = 2;
        public static final byte FRAME_NATIVE = 3;
        public static final byte FRAME_CPP = 4;
        public static final byte FRAME_KERNEL = 5;
        public static final byte FRAME_C1_COMPILED = 6;

    Even if you do so I don't see a way to get int type from IMCFrame.

  21. parttimenerd commented on Feb 27, 2023

    @parttimenerd
    parttimenerd
    on Feb 27, 2023
    Contributor
    More actions

    This information is not even stored in the IMCFrame.Type, but mapping it using a simple switch-case should be easy to implement. Maybe one should add the int to the JMC JFR parser anyways. I'm currently using the OpenJDK JFR parser in my projects, so I have limited knowledge on the JMC JFR parser.

  22. krzysztofslusarski commented on Feb 27, 2023

    @krzysztofslusarski
    krzysztofslusarski
    on Feb 27, 2023
    Contributor
    More actions

    I'm using classes from org.openjdk.jmc.common, hard to tell if it's the same as yours, it's both JMC and OpenJDK.

                <dependency>
                    <groupId>org.openjdk.jmc</groupId>
                    <artifactId>flightrecorder</artifactId>
                    <version>${flightrecorder.version}</version>
                </dependency>
  23. parttimenerd commented on Feb 27, 2023

    @parttimenerd
    parttimenerd
    on Feb 27, 2023
    Contributor
    More actions

    It's a different implementation.

    Could a classifier wrapper help you then?

  24. krzysztofslusarski commented on Feb 27, 2023

    @krzysztofslusarski
    krzysztofslusarski
    on Feb 27, 2023
    Contributor
    More actions

    No, I don't think so. With this implementation I cannot get int type. I need to switch to different JFR parser implementation.

  25. parttimenerd commented on Feb 27, 2023

    @parttimenerd
    parttimenerd
    on Feb 27, 2023
    Contributor
    More actions

    Hm?

    public int classify(IMCFrame.Type type, String klass, String method) {
       int t;
       switch (type) {
         case COMPILED:
           t = ...;
           break;
         ...
         default: throw ...;
      }
      return AsyncProfilerClassifier.classify(t, klass, method);
    }
  26. krzysztofslusarski commented on Feb 27, 2023

    @krzysztofslusarski
    krzysztofslusarski
    on Feb 27, 2023
    Contributor
    More actions

    That switch can have only 4 case branches, since that's the number of entries in enum. Async-profiler generates 7 different types. With that approach you cannot get FRAME_C1_COMPILED classification.

  27. parttimenerd commented on Feb 27, 2023

    @parttimenerd
    parttimenerd
    on Feb 27, 2023
    Contributor
    More actions

    You're correct. That's not that great. Using the async-profiler JFR reader seems to be the only real option then.

    Reacted by Krzysztof Ślusarski
  28. apangin
    closed this as completedon Mar 12, 2023
  29. xiejf2020 commented on Mar 14, 2023

    @xiejf2020
    xiejf2020
    on Mar 14, 2023
    More actions

    What an awesome feature!
    But it doesn't seem to support AOT (although I know AOT was removed in JDK17...)? Would you consider supporting it?

  30. apangin commented on Mar 14, 2023

    @apangin
    apangin
    on Mar 14, 2023
    CollaboratorAuthor
    More actions

    @xiejf2020 How do you think AOT support should look like and what problem/question this should solve?

  31. xiejf2020 commented on Mar 14, 2023

    @xiejf2020
    xiejf2020
    on Mar 14, 2023
    More actions

    @xiejf2020 How do you think AOT support should look like and what problem/question this should solve?

    I hope there's a [aot_comp] in addition to [Interpreter], [c1_comp] and [c2_comp].

    Currently, all code (including Interpreter and C1) seems to be identified as C2 when AOT is on (maybe the whole logic used to identify the compilation is broken due to AOT). The following program was run on OpenJDK16.

    java -XX:+UnlockExperimentalVMOptions -XX:+UseAOT -XX:AOTLibrary=$PWD/whatever.so -jar spring-petclinic-2.7.3.jar

    Whatever whatever.so is here (maybe even if it's an empty lib with no compiled code) results in all code being recognized as C2:

    image

    And this is the flamegraph without AOT (C1 and C2 are correctly identified):

    image

    I know there are probably not many people who use AOT, so if you don't have time to fix it, maybe give me some tips about how to fix it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.