Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DX][Stopwatch] Assign colors to custom categories #33514

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

Closed
javiereguiluz opened this issue Sep 9, 2019 · 2 comments
Closed

[DX][Stopwatch] Assign colors to custom categories #33514

javiereguiluz opened this issue Sep 9, 2019 · 2 comments
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature Stopwatch

Comments

@javiereguiluz
Copy link
Member

Description
I'm playing with the Stopwatch component and I used something like this:

$this->stopwatch->start('export-data', 'export');

In the profiler I can see this ... but the export custom category is not assigned a color, so it looks like a bug and it complicates understanding the different events:

image

Proposed solution
Let's assign a different color for each custom category.

In practice:

  1. We select 5 to 10 beautiful colors which are not already associated with Symfony things (the event's blue, the doctrine's orange, the twig's green, etc.)
  2. We assign a color randomly to each custom category.

Instead of pure randomness, we could apply the same strategy of the Asset component, which uses this code to always assign the same base URL for each path. This way we'd always select the same "random" color for the same category name:

protected function chooseBaseUrl($path)
{
    return (int) fmod(hexdec(substr(hash('sha256', $path), 0, 10)), \count($this->baseUrls));
}
@javiereguiluz javiereguiluz added Feature Stopwatch DX DX = Developer eXperience (anything that improves the experience of using Symfony) labels Sep 9, 2019
@ro0NL
Copy link
Contributor

ro0NL commented Sep 10, 2019

Somewhat related to the final bullet in #27262

@fabpot
Copy link
Member

fabpot commented Sep 10, 2019

Sounds like a great idea? @javiereguiluz Up for a PR?

fabpot added a commit that referenced this issue Sep 10, 2019
…Stopwatch categories (javiereguiluz)

This PR was merged into the 4.4 branch.

Discussion
----------

[WebProfilerBundle] Assign automatic colors to custom Stopwatch categories

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #33514
| License       | MIT
| Doc PR        | not needed

### Before

![image](https://user-images.githubusercontent.com/73419/64624345-d2907000-d3ea-11e9-9320-5b316768273d.png)

### After

![image](https://user-images.githubusercontent.com/73419/64624358-d6bc8d80-d3ea-11e9-875d-99396782d95a.png)

- - - - -

I'd appreciate reviews from JavaScript experts. Thanks!

Commits
-------

329a74f [WebProfilerBundle] Assign automatic colors to custom Stopwatch categories
@stof stof closed this as completed Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature Stopwatch
Projects
None yet
Development

No branches or pull requests

4 participants