Skip to content

Only colorize the profiler report when writing to a terminal - #9383

Open
abadams wants to merge 3 commits into
mainfrom
abadams/profiler_report_isatty
Open

Only colorize the profiler report when writing to a terminal#9383
abadams wants to merge 3 commits into
mainfrom
abadams/profiler_report_isatty

Conversation

@abadams

@abadams abadams commented Aug 24, 2026

Copy link
Copy Markdown
Member

The profiler report gated its ANSI color escapes on the TERM environment variable alone. CI and other redirected environments commonly set TERM=xterm-256color while stdout is actually a pipe or file, so the escape codes were written straight into the captured log as noise (this showed up as [NON-XML-CHAR-0x1B]… garbage in buildbot test logs).

This adds an isatty(STDOUT_FILENO) check to the gate (the report is printed via halide_print, whose default writes to stdout) and honors the NO_COLOR convention. isatty is declared in runtime_internal.h next to the existing write/getenv declarations.

The no-color path already emits plain box-drawing separators, so the table stays well-formed — only the escape sequences are dropped.

Verified against a rebuilt runtime with a JIT pipeline compiled with Target::Profile:

  • piped stdout, TERM=xterm-256color → 0 escape bytes
  • real pseudo-terminal, TERM=xterm-256color → colors present
  • pseudo-terminal, NO_COLOR=1 → 0 escape bytes

🤖 Generated with Claude Code

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.97%. Comparing base (54cd1d8) to head (b3a02cf).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9383      +/-   ##
==========================================
+ Coverage   69.89%   69.97%   +0.07%     
==========================================
  Files         261      261              
  Lines       79362    79402      +40     
  Branches    19349    19360      +11     
==========================================
+ Hits        55474    55561      +87     
- Misses      17926    17936      +10     
+ Partials     5962     5905      -57     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexreinking

Copy link
Copy Markdown
Member

That's a real Windows failure

Comment thread src/runtime/profiler_common.cpp Outdated
The report gated ANSI color escapes on the TERM environment variable
alone. CI and other redirected environments commonly set
TERM=xterm-256color while stdout is a pipe or file, so the escapes were
written straight into the captured log as noise.

Also require isatty(STDOUT_FILENO) (the report is printed via halide_print,
whose default writes to stdout), and honor the NO_COLOR convention. The
no-color path already emits plain box-drawing separators, so the table
stays well-formed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@abadams
abadams force-pushed the abadams/profiler_report_isatty branch from db40ccc to f7d6109 Compare August 25, 2026 19:42
Comment thread src/runtime/profiler_common.cpp Outdated
Match IRPrinter's HL_COLORS handling: if HL_COLORS is set it is an explicit
override ("0" off, anything else on); otherwise fall back to honoring
NO_COLOR and auto-detecting a color-capable terminal. Also add isatty to the
list of posix calls that get an underscore prefix on Windows (_isatty).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@abadams

abadams commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

TODO: Make the IRPrinter.cpp logic match this exactly, so the behavior of both is in alignment. The priority of the env vars is the same, but NO_COLOR isn't checked, and the strings they expect differ (Exactly "1" vs atoi != 0)

Match the profiler report's logic exactly: HL_COLORS is an explicit override
(atoi() != 0); otherwise honor NO_COLOR in addition to detecting a
color-capable terminal. Previously NO_COLOR was ignored here.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants