pstats: Update macOS timeline view to show more of collector name

Now shows the parent collector name if there's room and a single character if there's no room for anything more, just like the other implementations
This commit is contained in:
rdb 2023-10-14 13:28:34 +02:00
parent 10110cbfff
commit d368fac3e3

View File

@ -232,9 +232,6 @@ draw_bar(int row, int from_x, int to_x, int collector_index,
if ((to_x - from_x) >= scale * 4) { if ((to_x - from_x) >= scale * 4) {
// Only bother drawing the text if we've got some space to draw on. // Only bother drawing the text if we've got some space to draw on.
const PStatClientData *client_data = monitor->get_client_data();
const PStatCollectorDef &def = client_data->get_collector_def(collector_index);
const CFStringRef keys[] = { const CFStringRef keys[] = {
(__bridge CFStringRef)NSForegroundColorAttributeName, (__bridge CFStringRef)NSForegroundColorAttributeName,
(__bridge CFStringRef)NSFontAttributeName, (__bridge CFStringRef)NSFontAttributeName,
@ -245,7 +242,7 @@ draw_bar(int row, int from_x, int to_x, int collector_index,
}; };
CFDictionaryRef attribs = CFDictionaryCreate(kCFAllocatorDefault, (const void **)keys, (const void **)values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionaryRef attribs = CFDictionaryCreate(kCFAllocatorDefault, (const void **)keys, (const void **)values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, def._name.c_str(), kCFStringEncodingUTF8); CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, collector_name.c_str(), kCFStringEncodingUTF8);
CFAttributedStringRef astr = CFAttributedStringCreate(kCFAllocatorDefault, str, attribs); CFAttributedStringRef astr = CFAttributedStringCreate(kCFAllocatorDefault, str, attribs);
CTLineRef line = CTLineCreateWithAttributedString(astr); CTLineRef line = CTLineCreateWithAttributedString(astr);
@ -260,23 +257,43 @@ draw_bar(int row, int from_x, int to_x, int collector_index,
double text_left = std::max(from_x, 0) + scale / 2.0; double text_left = std::max(from_x, 0) + scale / 2.0;
double text_right = std::min(to_x, get_xsize()) - scale / 2.0; double text_right = std::min(to_x, get_xsize()) - scale / 2.0;
double text_top = top + (bottom - top - text_height) / 2.0 + text_height; double text_top = top + (bottom - top - text_height) / 2.0 + text_height;
/*
if (text_width >= text_right - text_left) { if (text_width >= text_right - text_left) {
size_t c = collector_name.rfind(':'); size_t c = collector_name.rfind(':');
if (text_right - text_left < scale * 6) { if (text_right - text_left < scale * 6) {
// It's a really tiny space. Draw a single letter. // It's a really tiny space. Draw a single letter.
const char *ch = collector_name.data() + (c != std::string::npos ? c + 1 : 0); UniChar ch = *(collector_name.data() + (c != std::string::npos ? c + 1 : 0));
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
pango_layout_set_text(layout, ch, 1); CFStringRef str = CFStringCreateWithCharacters(kCFAllocatorDefault, &ch, 1);
} else { CFAttributedStringRef astr = CFAttributedStringCreate(kCFAllocatorDefault, str, attribs);
CTLineRef new_line = CTLineCreateWithAttributedString((CFAttributedStringRef)astr);
bounds = CTLineGetImageBounds(new_line, _ctx);
text_width = bounds.size.width;
CFRelease(line);
CFRelease(astr);
CFRelease(str);
line = new_line;
}
else {
// Maybe just use everything after the last colon. // Maybe just use everything after the last colon.
if (c != std::string::npos) { if (c != std::string::npos) {
pango_layout_set_text(layout, collector_name.data() + c + 1, const char *short_name = collector_name.data() + c + 1;
collector_name.size() - c - 1); CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, short_name, kCFStringEncodingUTF8);
pango_layout_get_pixel_size(layout, &text_width, &text_height); CFAttributedStringRef astr = CFAttributedStringCreate(kCFAllocatorDefault, str, attribs);
CTLineRef new_line = CTLineCreateWithAttributedString((CFAttributedStringRef)astr);
bounds = CTLineGetImageBounds(new_line, _ctx);
text_width = bounds.size.width;
CFRelease(line);
CFRelease(astr);
CFRelease(str);
line = new_line;
} }
} }
}*/ }
if (text_width >= text_right - text_left) { if (text_width >= text_right - text_left) {
// Have CoreText truncate to the correct length. // Have CoreText truncate to the correct length.