Skip to content

Commit d12dd3f

Browse files
authored
std::format instead of snprintf in compositor_report.cpp (#4760)
Closes nothing <!-- Mention the issue this closes if applicable --> Related: #4660 <!-- List any PRs, issues, and links that might benefit reviewers build context around your work --> Related to #4736 ## What's new? std::format instead of snprintf in compositor_report.cpp <!-- List the major changes of this PR --> ## How to test <!-- List how reviewers can poke at the addition in this PR --> ## Checklist - [ ] Tests added and pass - [ ] Adequate documentation added - [ ] (optional) Added Screenshots or videos
2 parents f37ddfd + 10147e3 commit d12dd3f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/server/report/logging/compositor_report.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "compositor_report.h"
1818
#include <mir/logging/logger.h>
1919

20+
#include <format>
21+
2022
using namespace mir::time;
2123
namespace ml = mir::logging;
2224
namespace mrl = mir::report::logging;
@@ -43,9 +45,8 @@ mrl::CompositorReport::TimePoint mrl::CompositorReport::now() const
4345

4446
void mrl::CompositorReport::added_display(int width, int height, int x, int y, SubCompositorId id)
4547
{
46-
char msg[128];
47-
snprintf(msg, sizeof msg, "Added display %p: %dx%d %+d%+d",
48-
id, width, height, x, y);
48+
auto const msg = std::format("Added display {}: {}x{} {:+d}{:+d}",
49+
static_cast<const void*>(id), width, height, x, y);
4950
logger->log(ml::Severity::informational, msg, component);
5051
}
5152

@@ -101,13 +102,13 @@ void mrl::CompositorReport::Instance::log(ml::Logger& logger, SubCompositorId id
101102
long avg_latency_usec = dn ? dl / dn : 0;
102103
long dt_msec = dt / 1000L;
103104

104-
char msg[128];
105-
snprintf(msg, sizeof msg, "Display %p averaged %ld.%03ld FPS, "
106-
"%ld.%03ld ms/frame, "
107-
"latency %ld.%03ld ms, "
108-
"%ld frames over %ld.%03ld sec, "
109-
"%ld%% bypassed",
110-
id,
105+
auto const msg = std::format(
106+
"Display {} averaged {}.{:03d} FPS, "
107+
"{}.{:03d} ms/frame, "
108+
"latency {}.{:03d} ms, "
109+
"{} frames over {}.{:03d} sec, "
110+
"{}% bypassed",
111+
static_cast<const void*>(id),
111112
frames_per_1000sec / 1000,
112113
frames_per_1000sec % 1000,
113114
avg_render_time_usec / 1000,
@@ -156,9 +157,8 @@ void mrl::CompositorReport::finished_frame(SubCompositorId id)
156157

157158
if (inst.bypassed != inst.prev_bypassed || inst.nframes == 1)
158159
{
159-
char msg[128];
160-
snprintf(msg, sizeof msg, "Display %p bypass %s",
161-
id, inst.bypassed ? "ON" : "OFF");
160+
auto const msg = std::format("Display {} bypass {}",
161+
static_cast<const void*>(id), inst.bypassed ? "ON" : "OFF");
162162
logger->log(ml::Severity::informational, msg, component);
163163
}
164164
inst.prev_bypassed = inst.bypassed;

0 commit comments

Comments
 (0)