• Performance Tracing on Linux(转发)


    原文:

    https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/linux-performance-tracing.md#resolving-framework-symbols

    Performance Tracing on Linux

    When a performance problem is encountered on Linux, these instructions can be used to gather detailed information about what was happening on the machine at the time of the performance problem.

    CoreCLR supports two different mechanisms for tracing .NET applications on Linux: EventPipe and LTTng. They both have tools built by the .NET team, namely dotnet-trace (which uses EventPipe) and PerfCollect (which uses LTTng). Here are some notable differences between the two tools to help you decide which to use:

    1. PerfCollect leverages LTTng, which is a tracing framework built for the Linux kernel, so it can only be used on Linux. dotnet-trace is OS agnostic, so you can use it the same way across Windows/macOS and Linux.

    2. PerfCollect uses perf, which gives you native callstacks. dotnet-trace can only give you managed callstack.

    3. PerfCollect has a machine-wide scope, so it can be used to capture events from multiple processes running on the same machine. dotnet-trace is specific to a single runtime instance.

    4. PerfCollect can be started prior to the process start, whereas dotnet-trace can only be attached after the process has started and runtime has set up the necessary internal data structures to allow attach.

    5. PerfCollect supports .NET Core 2.1 or later. dotnet-trace supports .NET Core 3.0 or later.

    LTTng and PerfCollect (.NET Core 2.1 or later)

    Required Tools

    • perfcollect: Bash script that automates data collection.
    • PerfView: Windows-based performance tool that can also analyze trace files collected with Perfcollect.

    Preparing Your Machine

    Follow these steps to prepare your machine to collect a performance trace.

    1. Download Perfcollect.

      curl -OL http://aka.ms/perfcollect
    2. Make the script executable.

      chmod +x perfcollect
    3. Install tracing prerequisites - these are the actual tracing libraries. For details on prerequisites, see below.

      sudo ./perfcollect install

    Collecting a Trace

    1. Have two shell windows available - one for controlling tracing, referred to as [Trace], and one for running the application, referred to as [App].

    2. [App] Setup the application shell - this enables tracing configuration inside of CoreCLR.

      export COMPlus_PerfMapEnabled=1
      export COMPlus_EnableEventLog=1
    3. [Trace] Start collection.

      sudo ./perfcollect collect sampleTrace

      Expected Output:

      Collection started.  Press CTRL+C to stop.
    4. [App] Run the app - let it run as long as you need to in order to capture the performance problem. Generally, you don't need very long. As an example, for a CPU investigation, 5-10 seconds of the high CPU situation is usually enough.

      dotnet run
    5. [Trace] Stop collection - hit CTRL+C.

      ^C
      ...STOPPED.
      
      Starting post-processing. This may take some time.
      
      Generating native image symbol files
      ...SKIPPED
      Saving native symbols
      ...FINISHED
      Exporting perf.data file
      ...FINISHED
      Compressing trace files
      ...FINISHED
      Cleaning up artifacts
      ...FINISHED
      
      Trace saved to sampleTrace.trace.zip

      The compressed trace file is now stored in the current working directory.

    …………

    Viewing a Trace

    Traces are best viewed using PerfView on Windows. Note that we're currently looking into porting the analysis pieces of PerfView to Linux so that the entire investigation can occur on Linux.

    Open the Trace File

    1. Copy the trace.zip file from Linux to a Windows machine.

    2. Download PerfView from http://aka.ms/perfview.

    3. Run PerfView.exe

      PerfView.exe <path to trace.zip file>

    Select a View

    PerfView will display the list of views that are supported based on the data contained in the trace file.

    • For CPU investigations, choose CPU stacks.
    • For very detailed GC information, choose GCStats.
    • For per-process/module/method JIT information, choose JITStats.
    • If there is not a view for the information you need, you can try looking for the events in the raw events view. Choose Events.

    For more details on how to interpret views in PerfView, see help links in the view itself, or from the main window in PerfView choose Help->Users Guide.

    EventPipe and dotnet-trace (.NET Core 3.0 Preview 5 or later)

    Intro

    EventPipe is a new cross-platform tracing mechanism we built into the runtime from .NET Core 3.0. It works the same across all platforms we support (Windows, macOS, and Linux), and we have built various diagnostics tools on top of it. dotnet-trace is a dotnet CLI tool that allows you to trace your .NET application using EventPipe.

    Installing dotnet-trace

    dotnet-trace can be installed by using the dotnet CLI:

    dotnet tool install --global dotnet-trace --version 1.0.4-preview6.19311.1
    

    Collecting a trace

    To see which .NET processes are available for collecting traces on, you can run the following command to get their process IDs (PID):

    dotnet-trace list-processes
    

    Once you know the PID of the process you want to collect traces, you can run the following command to start tracing:

    dotnet-trace collect --process-id <PID>



    Viewing the Trace

    The resulting trace can be viewed in PerfView on Windows. Alternatively on Linux/macOS, it can be viewed on SpeedScope if you convert the trace format to speedscope by passing --format speedscope argument when collecting the trace.

    More Information

    To read more about how to use dotnet-trace, please refer to the dotnet-trace documentation.

  • 相关阅读:
    十天冲刺---Day10
    十天冲刺---Day9
    团队博客目录
    【Beta阶段】M2事后分析
    【Beta阶段】展示博客
    【Beta阶段】测试报告
    【Beta阶段】发布说明
    【Beta阶段】团队源代码管理
    【Beta阶段】第十次Scrum Meeting!!!
    【Beta阶段】第九次Scrum Meeting!(论坛已成功上线)
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/14282929.html
Copyright © 2020-2023  润新知