MCPcopy Create free account
hub / github.com/apple/foundationdb / writeEvent

Method writeEvent

flow/Trace.cpp:379–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

377 }
378
379 void writeEvent(TraceEventFields fields, std::string trackLatestKey, bool trackError) {
380 MutexHolder hold(mutex);
381
382 annotateEvent(fields);
383
384 if (!trackLatestKey.empty()) {
385 fields.addField("TrackLatestType", "Original");
386 }
387
388 if (!isOpen() &&
389 (preopenOverflowCount > 0 || bufferLength + fields.sizeBytes() > TRACE_LOG_MAX_PREOPEN_BUFFER)) {
390 ++preopenOverflowCount;
391 return;
392 }
393
394 // FIXME: What if we are using way too much memory for buffer?
395 ASSERT(!isOpen() || fields.isAnnotated());
396 eventBuffer.push_back(fields);
397 bufferLength += fields.sizeBytes();
398
399 if (g_network && g_network->isSimulated()) {
400 // Throw an error if we have queued up a large number of events in simulation. This makes it easier to
401 // diagnose cases where we get stuck in a loop logging trace events that eventually runs out of memory.
402 // Without this we would never see any trace events from that loop, and it would be more difficult to
403 // identify where the process is actually stuck.
404 if (bufferLength > 1e8) {
405 fprintf(stderr, "Trace log buffer overflow\n");
406 fprintf(stderr, "Last event: %s\n", fields.toString().c_str());
407 // Setting this to 0 avoids a recurse from the assertion trace event and also prevents a situation where
408 // we roll the trace log only to log the single assertion event when using --crash.
409 bufferLength = 0;
410 ASSERT(false);
411 }
412 if (++tracedLines > FLOW_KNOBS->MAX_TRACE_LINES && failedLineOverflow == 0) {
413 failedLineOverflow = 1; // we only want to do this once
414 }
415 }
416
417 if (trackError) {
418 latestEventCache.setLatestError(fields);
419 }
420 if (!trackLatestKey.empty()) {
421 latestEventCache.set(trackLatestKey, fields);
422 }
423 }
424
425 void log(int severity, const char* name, UID id, uint64_t event_ts) {
426 if (!logTraceEventMetrics)

Callers 2

logMethod · 0.80
dumpMethod · 0.80

Calls 11

fprintfFunction · 0.85
addFieldMethod · 0.80
sizeBytesMethod · 0.80
isAnnotatedMethod · 0.80
setLatestErrorMethod · 0.80
setMethod · 0.65
emptyMethod · 0.45
push_backMethod · 0.45
isSimulatedMethod · 0.45
c_strMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected