GithubHelp home page GithubHelp logo

shamanime / phoenix_profiler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mcrumm/phoenix_profiler

0.0 0.0 0.0 622 KB

Web Profiler and Debug Toolbar for Phoenix Framework

License: MIT License

Elixir 57.54% HTML 6.63% CSS 33.86% JavaScript 1.97%

phoenix_profiler's Introduction

PhoenixProfiler

Provides a development tool that gives detailed information about the execution of any request.

Never enable it on production servers as it exposes sensitive data about your web application.

Built-in Features

  • Request/Response - status code, params, headers, cookies, etc.

  • Routing - endpoint, router, controller/live view, action, etc.

  • Basic diagnostics - response time, memory

  • Inspect LiveView crashes

  • Inspect Ecto queries (Coming Soon)

  • Swoosh mailer integration (Coming Soon)

Installation

To start using the profiler, you will need the following steps:

  1. Add the phoenix_profiler dependency
  2. Define a profiler on your supervision tree
  3. Enable the profiler on your Endpoint
  4. Configure LiveView
  5. Add the PhoenixProfiler plug
  6. Mount the profiler on your LiveViews
  7. Add the profiler page on your LiveDashboard (optional)

1. Add the phoenix_profiler dependency

Add phoenix_profiler to your mix.exs:

{:phoenix_profiler, "~> 0.1.0", github: "mcrumm/phoenix_profiler"}

2. Define a profiler on your supervision tree

You define a profiler on your main application's supervision tree (usually in lib/my_app/application.ex):

    children = [
      {PhoenixProfiler, name: MyAppWeb.Profiler},
      # MyApp.Repo
      # MyAppWeb.Endpoint,
      # etc...
    ]

Note that the profiler must be running for data to be collected, so it must come before any endpoints in your supervision tree.

The following options are available:

  • :name - The name of the profiler server. This option is required.

  • :request_sweep_interval - How often to sweep the ETS table where the profiles are stored. Default is 24h in milliseconds.

3. Enable the profiler on your Endpoint

PhoenixProfiler is disabled by default. In order to enable it, you must update your endpoint's :dev configuration to include the :phoenix_profiler options:

# config/dev.exs
config :my_app, MyAppWeb.Endpoint,
  phoenix_profiler: [server: MyAppWeb.Profiler]

All web configuration is done inside the :phoenix_profiler key on the endpoint.

The following options are available:

  • :server - The name of the profiler server. This option is required.

  • :enable - When set to false, disables profiling by default. You can always enable profiling on a request via enable/1. Defaults to true.

  • :profiler_link_base - The base path for generating links on the toolbar. Defaults to "/dashboard/_profiler".

  • :toolbar_attrs - HTML attributes to be given to the element injected for the toolbar. Expects a keyword list of atom keys and string values. Defaults to [].

4. Configure LiveView

If LiveView is already installed in your app, you may skip this section.

The Phoenix Web Debug Toolbar is built on top of LiveView. If you plan to use LiveView in your application in the future we recommend you follow the official installation instructions. This guide only covers the minimum steps necessary for the toolbar itself to run.

Update your endpoint's configuration to include a signing salt. You can generate a signing salt by running mix phx.gen.secret 32 (note Phoenix v1.5+ apps already have this configuration):

# config/config.exs
config :my_app, MyAppWeb.Endpoint,
  live_view: [signing_salt: "SECRET_SALT"]

5. Add the PhoenixProfiler plug

Add the PhoenixProfiler plug within the code_reloading? block on your Endpoint (usually in lib/my_app_web/endpoint.ex):

  if code_reloading? do
    # plugs...
    plug PhoenixProfiler
  end

6. Mount the profiler on your LiveViews

Note this section is required only if you are using LiveView, otherwise you may skip it.

Add the profiler hook to the live_view function on your web module (usually in lib/my_app_web.ex):

  def live_view do
    quote do
      # use...

      on_mount PhoenixProfiler

      # view helpers...
    end
  end

Note the on_mount macro requires LiveView 0.16+. For earlier versions, see PhoenixProfiler.enable/1.

This is all. Run mix phx.server and observe the toolbar on your browser requests.

7. Add the profiler page on your LiveDashboard (optional)

Note this section is required for the LiveDashboard integration. If you are not using LiveDashboard, you may technically skip this step, although it is highly recommended that you install LiveDashboard to enjoy all the features of PhoenixProfiler.

Add the dashboard definition to the list of :additional_pages on the live_dashboard macro in your router (usually in lib/my_app_web/router.ex):

live_dashboard "/dashboard",
  additional_pages: [
    _profiler: {PhoenixProfiler.Dashboard, []}
    # additional pages...
  ]

Reduced motion toolbar options

If a PHOENIX_PROFILER_REDUCED_MOTION environment variable is set, PhoenixProfiler will disable all toolbar animations. The value of the environment variable is not evaluated.

Contributing

For those planning to contribute to this project, you can run a dev app with the following commands:

$ mix setup
$ mix dev

Alternatively, run iex -S mix dev if you also want a shell.

License

MIT License. Copyright (c) 2021 Michael Allen Crumm Jr.

phoenix_profiler's People

Contributors

mcrumm avatar leandrocp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.