Skip to content

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

Open
abadams wants to merge 1 commit into
mainfrom
abadams/profiler_report_isatty
Open

Only colorize the profiler report when writing to a terminal#9383
abadams wants to merge 1 commit 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 70.09%. Comparing base (54cd1d8) to head (f7d6109).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9383      +/-   ##
==========================================
+ Coverage   69.89%   70.09%   +0.19%     
==========================================
  Files         261      261              
  Lines       79362    79362              
  Branches    19349    19349              
==========================================
+ Hits        55474    55628     +154     
+ Misses      17926    17898      -28     
+ Partials     5962     5836     -126     

☔ 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

bool support_colors =
!(no_color && no_color[0]) &&
term && (strstr(term, "color") || strstr(term, "xterm")) &&
isatty(STDOUT_FILENO);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's _isatty on Windows, I'm pretty sure.

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
// redirected environments often set TERM=xterm-256color while stdout is a
// pipe or file, which would splatter escape codes into the captured log.
// The report is printed via halide_print, whose default writes to stdout.
const char *no_color = getenv("NO_COLOR");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should ideally honor the same logic as IRPrinter.h, but note I'm about to fix a bug there #9393

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.

2 participants