Bug 1083694 - TraceLogger: Part 3: Don't use EventEntry in TraceLoggerGraph, r=bbouvier

This commit is contained in:
Hannes Verschore 2014-11-20 17:44:03 +01:00
parent 38df06a92c
commit 355513536e
2 changed files with 19 additions and 29 deletions

View File

@ -114,10 +114,6 @@ TraceLoggerGraphState::nextLoggerId()
bool
TraceLoggerGraph::init(uint64_t startTimestamp)
{
if (!events.init()) {
failed = true;
return false;
}
if (!tree.init()) {
failed = true;
return false;
@ -253,19 +249,6 @@ TraceLoggerGraph::flush()
tree.clear();
}
if (eventFile) {
// Format data in big endian
for (size_t i = 0; i < events.size(); i++) {
events[i].time = NativeEndian::swapToBigEndian(events[i].time);
events[i].textId = NativeEndian::swapToBigEndian(events[i].textId);
}
size_t bytesWritten = fwrite(events.data(), sizeof(EventEntry), events.size(), eventFile);
if (bytesWritten < events.size())
return false;
events.clear();
}
return true;
}
@ -419,24 +402,33 @@ TraceLoggerGraph::stopEvent(uint64_t timestamp)
void
TraceLoggerGraph::logTimestamp(uint32_t id, uint64_t timestamp)
{
if (failed)
return;
if (id == TraceLogger_Enable)
enabled = true;
if (!enabled)
return;
if (!events.ensureSpaceBeforeAdd()) {
fprintf(stderr, "TraceLogging: Disabled a tracelogger due to OOM.\n");
enabled = 0;
return;
}
if (id == TraceLogger_Disable)
disable(timestamp);
EventEntry &entry = events.pushUninitialized();
entry.time = timestamp;
entry.textId = id;
MOZ_ASSERT(eventFile);
// Format data in big endian
timestamp = NativeEndian::swapToBigEndian(timestamp);
id = NativeEndian::swapToBigEndian(id);
// The layout of the event log in the log file is:
// [timestamp, textId]
size_t itemsWritten = 0;
itemsWritten += fwrite(&timestamp, sizeof(uint64_t), 1, eventFile);
itemsWritten += fwrite(&id, sizeof(uint32_t), 1, eventFile);
if (itemsWritten < 2) {
failed = true;
enabled = false;
}
}
bool

View File

@ -214,8 +214,6 @@ class TraceLoggerGraph
ContinuousSpace<StackEntry> stack;
uint32_t treeOffset;
ContinuousSpace<EventEntry> events;
// Helper functions that convert a TreeEntry in different endianness
// in place.
void entryToBigEndian(TreeEntry *entry);
@ -239,7 +237,7 @@ class TraceLoggerGraph
bool updateNextId(uint32_t treeId, uint32_t nextId);
bool updateStop(uint32_t treeId, uint64_t timestamp);
// Flush the tree and events.
// Flush the tree.
bool flush();
// Stop a tree event.