* Fixed a bug in make_space() that would endlessly skip entries, even
though there was nothing to do (if 'diff' was larger than 'needed'). * Improved KDL command output. * Added debug output to the allocation functions. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23491 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,6 +7,14 @@
|
|||||||
|
|
||||||
#if ENABLE_TRACING
|
#if ENABLE_TRACING
|
||||||
|
|
||||||
|
//#define TRACE_TRACING
|
||||||
|
#ifdef TRACE_TRACING
|
||||||
|
# define TRACE(x) dprintf x
|
||||||
|
#else
|
||||||
|
# define TRACE(x) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
WRAP_ENTRY = 0x01,
|
WRAP_ENTRY = 0x01,
|
||||||
ENTRY_INITIALIZED = 0x02,
|
ENTRY_INITIALIZED = 0x02,
|
||||||
@@ -45,24 +53,34 @@ make_space(size_t needed)
|
|||||||
sBufferEnd = sBuffer;
|
sBufferEnd = sBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 diff = sBufferStart - sBufferEnd;
|
int32 space = (sBufferStart - sBufferEnd) * 4;
|
||||||
if (diff < 0)
|
TRACE(("make_space(%lu), left %ld\n", needed, space));
|
||||||
|
if (space < 0)
|
||||||
sBufferEnd = sBuffer;
|
sBufferEnd = sBuffer;
|
||||||
|
else if ((size_t)space < needed)
|
||||||
|
needed -= space;
|
||||||
else
|
else
|
||||||
needed -= diff;
|
return;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
TraceEntry* removed = (TraceEntry*)sBufferStart;
|
||||||
uint16 freed = sBufferStart->size;
|
uint16 freed = sBufferStart->size;
|
||||||
|
TRACE((" skip start %p, %u bytes\n", sBufferStart, freed));
|
||||||
|
|
||||||
sBufferStart = next_entry(sBufferStart);
|
sBufferStart = next_entry(sBufferStart);
|
||||||
if (sBufferStart == NULL)
|
if (sBufferStart == NULL)
|
||||||
sBufferStart = sBufferEnd;
|
sBufferStart = sBufferEnd;
|
||||||
|
|
||||||
sEntries--;
|
sEntries--;
|
||||||
|
removed->~TraceEntry();
|
||||||
|
|
||||||
if (needed <= freed)
|
if (needed <= freed)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
needed -= freed;
|
needed -= freed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRACE((" out: start %p, entries %ld\n", sBufferStart, sEntries));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -76,9 +94,13 @@ allocate_entry(size_t size)
|
|||||||
|
|
||||||
size = (size + 3) & ~3;
|
size = (size + 3) & ~3;
|
||||||
|
|
||||||
|
TRACE(("allocate_entry(%lu), start %p, end %p, buffer %p\n", size,
|
||||||
|
sBufferStart, sBufferEnd, sBuffer));
|
||||||
|
|
||||||
if (sBufferStart < sBufferEnd || sEntries == 0) {
|
if (sBufferStart < sBufferEnd || sEntries == 0) {
|
||||||
// the buffer ahead of us is still empty
|
// the buffer ahead of us is still empty
|
||||||
uint32 space = (sBuffer + kBufferSize - sBufferEnd) * 4;
|
uint32 space = (sBuffer + kBufferSize - sBufferEnd) * 4;
|
||||||
|
TRACE((" free after end %p: %lu\n", sBufferEnd, space));
|
||||||
if (space < size)
|
if (space < size)
|
||||||
make_space(size);
|
make_space(size);
|
||||||
} else {
|
} else {
|
||||||
@@ -91,6 +113,8 @@ allocate_entry(size_t size)
|
|||||||
entry->flags = 0;
|
entry->flags = 0;
|
||||||
sBufferEnd += size >> 2;
|
sBufferEnd += size >> 2;
|
||||||
sEntries++;
|
sEntries++;
|
||||||
|
TRACE((" entry: %p, end %p, start %p, entries %ld\n", entry, sBufferEnd,
|
||||||
|
sBufferStart, sEntries));
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,12 +191,14 @@ dump_tracing(int argc, char** argv)
|
|||||||
kprintf("usage: %s [start] [count] [#pattern]\n", argv[0]);
|
kprintf("usage: %s [start] [count] [#pattern]\n", argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// TODO: add pattern matching mechanism for the class name
|
|
||||||
|
|
||||||
if (start < 0)
|
if (start < 0)
|
||||||
start = 0;
|
start = 0;
|
||||||
|
if (start + count > sEntries)
|
||||||
|
count = sEntries - start;
|
||||||
|
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
|
int32 dumped = 0;
|
||||||
|
|
||||||
for (trace_entry* current = sBufferStart; current != NULL;
|
for (trace_entry* current = sBufferStart; current != NULL;
|
||||||
current = next_entry(current), index++) {
|
current = next_entry(current), index++) {
|
||||||
@@ -180,7 +206,7 @@ dump_tracing(int argc, char** argv)
|
|||||||
continue;
|
continue;
|
||||||
if (index > start + count)
|
if (index > start + count)
|
||||||
break;
|
break;
|
||||||
if ((entry->flags & BUFFER_ENTRY) != 0) {
|
if ((current->flags & BUFFER_ENTRY) != 0) {
|
||||||
// skip buffer entries
|
// skip buffer entries
|
||||||
index--;
|
index--;
|
||||||
continue;
|
continue;
|
||||||
@@ -194,6 +220,8 @@ dump_tracing(int argc, char** argv)
|
|||||||
if (pattern != NULL && strstr(buffer, pattern) == NULL)
|
if (pattern != NULL && strstr(buffer, pattern) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
dumped++;
|
||||||
|
|
||||||
if (pattern != NULL)
|
if (pattern != NULL)
|
||||||
kprintf("%5ld. %s\n", index, buffer);
|
kprintf("%5ld. %s\n", index, buffer);
|
||||||
else
|
else
|
||||||
@@ -202,7 +230,8 @@ dump_tracing(int argc, char** argv)
|
|||||||
kprintf("%5ld. ** uninitialized entry **\n", index);
|
kprintf("%5ld. ** uninitialized entry **\n", index);
|
||||||
}
|
}
|
||||||
|
|
||||||
kprintf("%ld of %ld entries.\n", count, sEntries);
|
kprintf("%ld entries of entries %ld to %ld (total %ld).\n", dumped,
|
||||||
|
start + 1, start + count, sEntries);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,10 +261,8 @@ tracing_init(void)
|
|||||||
area_id area = create_area("tracing log", (void**)&sBuffer,
|
area_id area = create_area("tracing log", (void**)&sBuffer,
|
||||||
B_ANY_KERNEL_ADDRESS, MAX_TRACE_SIZE, B_FULL_LOCK,
|
B_ANY_KERNEL_ADDRESS, MAX_TRACE_SIZE, B_FULL_LOCK,
|
||||||
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
||||||
if (area < B_OK) {
|
if (area < B_OK)
|
||||||
panic("OH");
|
|
||||||
return area;
|
return area;
|
||||||
}
|
|
||||||
|
|
||||||
sBufferStart = sBuffer;
|
sBufferStart = sBuffer;
|
||||||
sBufferEnd = sBuffer;
|
sBufferEnd = sBuffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user