Skip to content
Open
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
14 changes: 10 additions & 4 deletions src/runtime/profiler_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,17 @@ ALWAYS_INLINE bool counter_is_approximate(const halide_profiler_func_stats *fs,
WEAK void halide_profiler_report_unlocked(void *user_context, halide_profiler_state *s) {
StringStreamPrinter<1024> sstr(user_context);

bool support_colors = false;
// Emit ANSI color escapes only when the report is going to an actual
// color-capable terminal. Checking TERM alone isn't enough: CI and other
// 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

const char *term = getenv("TERM");
if (term && (strstr(term, "color") || strstr(term, "xterm"))) {
support_colors = true;
}
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.


// Column-aligned rows are produced from `const char *` templates. A
// run of an uppercase marker char is a slot — the marker picks the
Expand Down
1 change: 1 addition & 0 deletions src/runtime/runtime_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ int fclose(void *);
int close(int);
size_t fwrite(const void *, size_t, size_t, void *);
ssize_t write(int fd, const void *buf, size_t bytes);
int isatty(int fd);
int remove(const char *pathname);
int ioctl(int fd, unsigned long request, ...);
char *strncpy(char *dst, const char *src, size_t n);
Expand Down
Loading