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

Dependency updates including Phoenix.HTML 4.0 #42

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
plugins: [Phoenix.LiveView.HTMLFormatter],
import_deps: [:ecto],
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
line_length: 120
line_length: 150
]
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
otp: ["26.1.1"]
elixir: ["1.15.6"]
elixir: ["1.16.3"]
steps:
- uses: actions/checkout@v2

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Next

- `Phoenix.HTML` 4.0
- Bandit.Pipeline.run as default MFA when available (it's now the default in `mix phx_new`)
- Fix issue with changeset form not honoring initial node
- Elixir 1.16 in CI
- Increase formatter line length

## 0.6.0

- Upgrade Dialyxir
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ You will now find a `Flame On` tab along the top of the LiveDashboard page

## Usage

Choose the Module, Function, and Arity of the function you want to profile, click "Flame On", and then trigger the function (e.g. make a web request in a new tab). Note that for Elixir modules, you will need to prefix them with `Elixir`, e.g. `Elixir.Phoenix.Controller`, while Erlang modules take simply the erlang module name, e.g. `cowboy_handler`. The default values of `cowboy_handler`/`execute`/`2` are the best way to capture a standard Phoenix Controller DeadView request or the DeadView request that kicks off a LiveView request.
Choose the Module, Function, and Arity of the function you want to profile, click "Flame On", and then trigger the function (e.g. make a web request in a new tab). Note that for Elixir modules, you will need to prefix them with `Elixir`, e.g. `Elixir.Phoenix.Controller`, while Erlang modules take simply the erlang module name, e.g. `cowboy_handler`. The default values of `Bandit.Pipeline`/`run`/`4` (for newer Phoenix apps) and `cowboy_handler`/`execute`/`2` (for older Phoenix apps) are the best way to capture a standard Phoenix Controller DeadView request or the DeadView request that kicks off a LiveView request.

### Zooming

Expand Down
12 changes: 8 additions & 4 deletions lib/flame_on/component.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
defmodule FlameOn.Component do
use Phoenix.LiveComponent
use Phoenix.HTML

import FlameOn.ErrorHelpers

use PhoenixHTMLHelpers

alias FlameOn.Capture.Block
alias FlameOn.Capture.Config
alias FlameOn.Component.CaptureSchema
Expand All @@ -30,17 +31,20 @@ defmodule FlameOn.Component do
end

def update(assigns, socket) do
target_node = Map.get(assigns, :node, Node.self())
capture_changeset = Map.put(CaptureSchema.changeset(target_node), :action, :validate)

socket =
if !Map.has_key?(socket.assigns, :id) do
socket
|> assign(:capturing?, false)
|> assign(:root_block, nil)
|> assign(:capture_changeset, CaptureSchema.changeset(Node.self()))
|> assign(:capture_changeset, capture_changeset)
|> assign(:viewing_block, nil)
|> assign(:view_block_path, [])
|> assign(:capture_timed_out?, false)
|> assign(:id, assigns.id)
|> assign(:target_node, Map.get(assigns, :node, Node.self()))
|> assign(:target_node, target_node)
else
socket
end
Expand Down Expand Up @@ -86,7 +90,7 @@ defmodule FlameOn.Component do
changeset =
socket.assigns.target_node
|> CaptureSchema.changeset(attrs)
|> Map.put(:action, :insert)
|> Map.put(:action, :validate)

{:noreply, assign(socket, :capture_changeset, changeset)}
end
Expand Down
17 changes: 2 additions & 15 deletions lib/flame_on/component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,7 @@
cursor: not-allowed;
}
</style>
<.form
:let={f}
for={@capture_changeset}
phx-submit="capture_schema"
phx-change="validate"
phx-target={@myself}
class="flame-on-form"
>
<.form :let={f} for={@capture_changeset} phx-submit="capture_schema" phx-change="validate" phx-target={@myself} class="flame-on-form">
<%= label(f, :module, class: "label1") %>
<%= text_input(f, :module, class: "input1", disabled: @capturing?) %>
<%= error_tag(f, :module, "fo-error error1") %>
Expand Down Expand Up @@ -148,13 +141,7 @@
<%= if not is_nil(@viewing_block) do %>
<%= if @view_block_path do %>
<%= for %Block{} = block <- @view_block_path do %>
<a
href="#"
phx-click="view_block"
phx-target={@myself}
phx-value-id={block.id}
style="font-size: 12.5px; font-family: monospace"
>
<a href="#" phx-click="view_block" phx-target={@myself} phx-value-id={block.id} style="font-size: 12.5px; font-family: monospace">
<%= FlameOn.SVG.mfa_to_string(block.function) %>
</a>
<% end %>
Expand Down
23 changes: 21 additions & 2 deletions lib/flame_on/component/capture_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ defmodule FlameOn.Component.CaptureSchema do
import Ecto.Changeset
alias Ecto.Changeset

require Logger

schema "capture" do
field :module, :string
field :function, :string
field :arity, :integer
field :timeout, :integer
end

@default_attrs %{module: "cowboy_handler", function: "execute", arity: 2, timeout: 15000}
@default_cowboy_attrs %{module: "cowboy_handler", function: "execute", arity: 2, timeout: 15000}
@default_bandit_attrs %{module: "Bandit.Pipeline", function: "run", arity: 4, timeout: 15000}

def changeset(node, attrs \\ nil) do
attrs = attrs || default_attrs(node)

def changeset(node, attrs \\ @default_attrs) do
%__MODULE__{}
|> cast(attrs, [:module, :function, :arity, :timeout])
|> validate_required([:module, :function, :arity, :timeout])
Expand Down Expand Up @@ -86,4 +91,18 @@ defmodule FlameOn.Component.CaptureSchema do
defp rpc_function_exported?(module, function, arity, node) do
:rpc.call(node, Kernel, :function_exported?, [module, function, arity])
end

defp default_attrs(node) do
cond do
rpc_function_exported?(@default_bandit_attrs.module, @default_bandit_attrs.function, @default_bandit_attrs.arity, node) ->
@default_bandit_attrs

rpc_function_exported?(@default_cowboy_attrs.module, @default_cowboy_attrs.function, @default_cowboy_attrs.arity, node) ->
@default_cowboy_attrs

true ->
Logger.info("FlameOn did not detect Cowboy or Bandit modules")
%{}
end
end
end
4 changes: 3 additions & 1 deletion lib/flame_on/error_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ defmodule FlameOn.ErrorHelpers do
Conveniences for translating and building error messages.
"""

use Phoenix.HTML
# For Phoenix HTML 4 vs 3
import Phoenix.HTML.Form
use PhoenixHTMLHelpers

@doc """
Generates tag for inlined form input errors.
Expand Down
4 changes: 1 addition & 3 deletions lib/flame_on/svg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ defmodule FlameOn.SVG do
<rect width="100%" height="100%" style={"fill: #{color_for_function(@block.function)};"}></rect>
<text x={@block_height / 4} y={@block_height * 0.5}><%= mfa_to_string(@block.function) %></text>
<title>
<%= format_integer(@block.duration) %>&micro;s (<%= trunc(@block.duration * 100 / @top_block.duration) %>%) <%= mfa_to_string(
@block.function
) %>
<%= format_integer(@block.duration) %>&micro;s (<%= trunc(@block.duration * 100 / @top_block.duration) %>%) <%= mfa_to_string(@block.function) %>
</title>
</svg>
<% end %>
Expand Down
10 changes: 5 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ defmodule FlameOn.MixProject do
{:meck, "~> 0.9.2"},
{:gettext, "~> 0.21"},
{:jason, "~> 1.0"},
{:phoenix_ecto, "~> 4.4"},
{:phoenix_live_dashboard, "~> 0.8.2"},
{:phoenix_live_view, "~> 0.20.0"}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
{:phoenix_ecto, "~> 4.6.1"},
{:phoenix_live_dashboard, "~> 0.8.3"},
{:phoenix_live_view, "~> 0.20.14"},
{:phoenix_html, "~> 4.0"},
{:phoenix_html_helpers, "~> 1.0.1"}
]
end
end
Loading
Loading