Skip to content

Commit 1ef5847

Browse files
committed
Add 'signpost' implementation for ftrace system tracing
1 parent 0a2922e commit 1ef5847

4 files changed

Lines changed: 75 additions & 28 deletions

File tree

Source/WTF/wtf/SystemTracing.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ inline void tracePoint(TracePointCode code, uint64_t data1 = 0, uint64_t data2 =
211211
UNUSED_PARAM(data3);
212212
UNUSED_PARAM(data4);
213213
#elif USE(LINUX_FTRACE)
214-
SystemTracingFTrace::instance().tracePoint(code, data1);
214+
SystemTracingFTrace::instance().tracePoint(code, data1, data2, data3, data4);
215215
UNUSED_PARAM(data2);
216216
UNUSED_PARAM(data3);
217217
UNUSED_PARAM(data4);
@@ -420,6 +420,39 @@ enum WTFOSSignpostType {
420420
#define WTFBeginSignpostAlwaysWithTimeDelta(pointer, name, timeDelta, ...) WTFBeginSignpostWithTimeDelta((pointer), name, (timeDelta), ##__VA_ARGS__)
421421
#define WTFEndSignpostAlwaysWithTimeDelta(pointer, name, timeDelta, ...) WTFEndSignpostWithTimeDelta((pointer), name, (timeDelta), ##__VA_ARGS__)
422422
423+
#elif USE(LINUX_FTRACE)
424+
425+
#define WTFEmitSignpostWithPhase(phase, pointer, name, format, ...) \
426+
do { \
427+
if (SystemTracingFTrace::isEnabled()) \
428+
SystemTracingFTrace::instance().addMark( \
429+
phase, std::span(_STRINGIFY(name)), \
430+
"p=%p" format, \
431+
reinterpret_cast<const void*>(pointer) \
432+
__VA_OPT__(,) __VA_ARGS__); \
433+
} while (0)
434+
435+
#define WTFEmitSignpost(pointer, name, ...) \
436+
WTFEmitSignpostWithPhase('I', pointer, name, __VA_OPT__(",") __VA_ARGS__) \
437+
438+
#define WTFBeginSignpost(pointer, name, ...) \
439+
WTFEmitSignpostWithPhase('B', pointer, name, __VA_OPT__(",") __VA_ARGS__) \
440+
441+
#define WTFEndSignpost(pointer, name, ...) \
442+
WTFEmitSignpostWithPhase('E', pointer, name, __VA_OPT__(",") __VA_ARGS__) \
443+
444+
#define WTFEmitSignpostAlways(pointer, name, ...) WTFEmitSignpost((pointer), name, ##__VA_ARGS__)
445+
#define WTFBeginSignpostAlways(pointer, name, ...) WTFBeginSignpost((pointer), name, ##__VA_ARGS__)
446+
#define WTFEndSignpostAlways(pointer, name, ...) WTFEndSignpost((pointer), name, ##__VA_ARGS__)
447+
448+
#define WTFEmitSignpostWithTimeDelta(pointer, name, timeDelta, ...) WTFEmitSignpost((pointer), name, ##__VA_ARGS__)
449+
#define WTFBeginSignpostWithTimeDelta(pointer, name, timeDelta, ...) WTFBeginSignpost((pointer), name, ##__VA_ARGS__)
450+
#define WTFEndSignpostWithTimeDelta(pointer, name, timeDelta, ...) WTFEndSignpost((pointer), name, ##__VA_ARGS__)
451+
452+
#define WTFEmitSignpostAlwaysWithTimeDelta(pointer, name, ...) WTFEmitSignpost((pointer), name, ##__VA_ARGS__)
453+
#define WTFBeginSignpostAlwaysWithTimeDelta(pointer, name, ...) WTFBeginSignpost((pointer), name, ##__VA_ARGS__)
454+
#define WTFEndSignpostAlwaysWithTimeDelta(pointer, name, ...) WTFEndSignpost((pointer), name, ##__VA_ARGS__)
455+
423456
#else
424457
425458
#define WTFEmitSignpost(pointer, name, ...) do { } while (0)

Source/WTF/wtf/linux/SystemTracingFTrace.h

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SystemTracingFTrace {
4141
return instance;
4242
}
4343

44-
inline void tracePoint(TracePointCode code, uint64_t cookie) {
44+
inline void tracePoint(TracePointCode code, uint64_t data1 = 0, uint64_t data2 = 0, uint64_t data3 = 0, uint64_t data4 = 0) {
4545
// ftrace disabled in runtime
4646
if (m_traceMarkerFd < 0) return;
4747

@@ -103,7 +103,7 @@ class SystemTracingFTrace {
103103
case LayerFlushStart:
104104
case UpdateLayerContentBuffersStart:
105105
#endif
106-
beginSyncMark(code);
106+
beginSyncMark(code, data1, data2, data3, data4);
107107
return;
108108

109109
case VMEntryScopeEnd:
@@ -168,12 +168,12 @@ class SystemTracingFTrace {
168168

169169
case MainResourceLoadDidStartProvisional:
170170
case SubresourceLoadWillStart:
171-
beginAsyncMark(code, cookie);
171+
beginAsyncMark(code, data1);
172172
return;
173173

174174
case MainResourceLoadDidEnd:
175175
case SubresourceLoadDidEnd:
176-
endAsyncMark(code, cookie);
176+
endAsyncMark(code, data1);
177177
return;
178178

179179
case DisplayRefreshDispatchingToMainThread:
@@ -183,7 +183,7 @@ class SystemTracingFTrace {
183183
case SyntheticMomentumEvent:
184184
case RemoteLayerTreeScheduleRenderingUpdate:
185185
case DisplayLinkUpdate:
186-
instantMark(code);
186+
instantMark(code, data1, data2, data3, data4);
187187
return;
188188

189189
case WTFRange:
@@ -208,45 +208,57 @@ class SystemTracingFTrace {
208208
}
209209
}
210210

211+
static bool isEnabled() {
212+
return !(instance().m_traceMarkerFd < 0);
213+
}
214+
211215
private:
212216

213-
inline void beginSyncMark(TracePointCode code) {
214-
// "B|<pid>|<name>"
215-
std::string message = std::string("B|") + std::to_string(m_pid) + "|" + tracePointCodeName(code).characters();
216-
writeFTraceMarker(message.c_str());
217+
inline void beginSyncMark(TracePointCode code, uint64_t data1, uint64_t data2, uint64_t data3, uint64_t data4) {
218+
// "B|<pid>|<name>|<args>"
219+
addMark('B', tracePointCodeName(code).spanIncludingNullTerminator(), "%" PRIu64 ",%" PRIu64 ",%" PRIu64 ",%" PRIu64, data1, data2, data3, data4);
217220
}
218221

219222
inline void endSyncMark(TracePointCode code) {
220-
UNUSED_PARAM(code);
221-
// "E|<pid>"
222-
std::string message = std::string("E|") + std::to_string(m_pid);
223-
writeFTraceMarker(message.c_str());
223+
// "E|<pid>|<name>"
224+
addMark('E', tracePointCodeName(code).spanIncludingNullTerminator());
224225
}
225226

226227
inline void beginAsyncMark(TracePointCode code, uint64_t cookie) {
227228
// "S|<pid>|<name>|<cookie>"
228-
std::string message = std::string("S|") + std::to_string(m_pid) + "|" + tracePointCodeName(code).characters() + "|" + std::to_string(cookie);
229-
writeFTraceMarker(message.c_str());
229+
addMark('S', tracePointCodeName(code).spanIncludingNullTerminator(), "%" PRIu64, cookie);
230230
}
231231

232232
inline void endAsyncMark(TracePointCode code, uint64_t cookie) {
233233
// "F|<pid>|<name>|<cookie>"
234-
std::string message = std::string("F|") + std::to_string(m_pid) + "|" + tracePointCodeName(code).characters() + "|" + std::to_string(cookie);
235-
writeFTraceMarker(message.c_str());
234+
addMark('F', tracePointCodeName(code).spanIncludingNullTerminator(),"%" PRIu64, cookie);
236235
}
237236

238-
inline void instantMark(TracePointCode code) {
237+
inline void instantMark(TracePointCode code, uint64_t data1, uint64_t data2, uint64_t data3, uint64_t data4) {
239238
// "I|<pid>|<name>"
240-
std::string message = std::string("I|") + std::to_string(m_pid) + "|" + tracePointCodeName(code).characters();
241-
writeFTraceMarker(message.c_str());
239+
addMark('I', tracePointCodeName(code).spanIncludingNullTerminator(),"%" PRIu64 ",%" PRIu64 ",%" PRIu64 ",%" PRIu64, data1, data2, data3, data4);
242240
}
243241

244-
inline void writeFTraceMarker(const char* message) {
242+
inline void writeFTraceMarker(const char* message, size_t len) {
245243
RELEASE_ASSERT(m_traceMarkerFd >= 0);
246244

245+
size_t offset = 0;
246+
247247
// make sure no other thread is writing at the same time
248248
std::lock_guard<std::mutex> lock(m_mutex);
249-
write(m_traceMarkerFd, message, strlen(message));
249+
while (len > 0) {
250+
ssize_t ret;
251+
252+
do {
253+
ret = write(m_traceMarkerFd, message + offset, len);
254+
} while (ret < 0 && errno == EINTR);
255+
256+
if (ret <= 0)
257+
break;
258+
259+
len -= ret;
260+
offset += ret;
261+
}
250262
}
251263

252264
SystemTracingFTrace() {
@@ -490,4 +502,6 @@ class SystemTracingFTrace {
490502

491503
} // namespace WTF
492504

493-
#endif // USE(LINUX_FTRACE)
505+
using WTF::SystemTracingFTrace;
506+
507+
#endif // USE(LINUX_FTRACE)

Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedBackingStore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ void CoordinatedBackingStoreTile::swapBuffers(TextureMapper& textureMapper)
4141
if (!updatesCount)
4242
return;
4343

44-
WTFBeginSignpost(this, CoordinatedSwapBuffers, "%lu updates", updatesCount);
44+
WTFBeginSignpost(this, CoordinatedSwapBuffers, "%zu updates", updatesCount);
4545
for (unsigned updateIndex = 0; updateIndex < updates.size(); ++updateIndex) {
4646
auto& update = updates[updateIndex];
4747
if (!update.buffer)
4848
continue;
4949

50-
WTFBeginSignpost(this, CoordinatedSwapBuffer, "%u/%lu, rect %ix%i+%i+%i", updateIndex + 1, updatesCount, update.tileRect.x(), update.tileRect.y(), update.tileRect.width(), update.tileRect.height());
50+
WTFBeginSignpost(this, CoordinatedSwapBuffer, "%u/%zu, rect %ix%i+%i+%i", updateIndex + 1, updatesCount, update.tileRect.x(), update.tileRect.y(), update.tileRect.width(), update.tileRect.height());
5151

5252
ASSERT(textureMapper.maxTextureSize().width() >= update.tileRect.size().width());
5353
ASSERT(textureMapper.maxTextureSize().height() >= update.tileRect.size().height());

Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,13 +1245,13 @@ void CoordinatedGraphicsLayer::updateContentBuffers()
12451245
auto dirtyTilesCount = dirtyTiles.size();
12461246
bool didUpdateTiles = false;
12471247

1248-
WTFBeginSignpost(this, UpdateTiles, "dirty tiles: %lu", dirtyTilesCount);
1248+
WTFBeginSignpost(this, UpdateTiles, "dirty tiles: %zu", dirtyTilesCount);
12491249

12501250
for (unsigned dirtyTileIndex = 0; dirtyTileIndex < dirtyTilesCount; ++dirtyTileIndex) {
12511251
auto& tile = dirtyTiles[dirtyTileIndex].get();
12521252
tile.ensureTileID();
12531253

1254-
WTFBeginSignpost(this, UpdateTile, "%u/%lu, id: %d", dirtyTileIndex + 1, dirtyTilesCount, tile.tileID());
1254+
WTFBeginSignpost(this, UpdateTile, "%u/%zu, id: %d", dirtyTileIndex + 1, dirtyTilesCount, tile.tileID());
12551255

12561256
auto& tileRect = tile.rect();
12571257
auto& dirtyRect = tile.dirtyRect();

0 commit comments

Comments
 (0)