Made BDebugEventInputStream::ReadNextEvent() nicer to use.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30260 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
#include <system_profiler_defs.h>
|
|
||||||
|
|
||||||
|
|
||||||
class BDataIO;
|
class BDataIO;
|
||||||
|
|
||||||
@@ -43,9 +41,8 @@ public:
|
|||||||
status_t SetTo(BDataIO* stream);
|
status_t SetTo(BDataIO* stream);
|
||||||
void Unset();
|
void Unset();
|
||||||
|
|
||||||
ssize_t ReadNextEvent(
|
ssize_t ReadNextEvent(uint32* _event, uint32* _cpu,
|
||||||
const system_profiler_event_header**
|
const void** _buffer);
|
||||||
_header);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ssize_t _Read(void* buffer, size_t size);
|
ssize_t _Read(void* buffer, size_t size);
|
||||||
|
|||||||
@@ -134,15 +134,19 @@ MainModelLoader::_Loader()
|
|||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
// get next event
|
// get next event
|
||||||
const system_profiler_event_header* header;
|
uint32 event;
|
||||||
ssize_t bufferSize = fInput->ReadNextEvent(&header);
|
uint32 cpu;
|
||||||
if (bufferSize < 0) {
|
const void* buffer;
|
||||||
success = bufferSize == B_ENTRY_NOT_FOUND;
|
ssize_t bufferSize = fInput->ReadNextEvent(&event, &cpu, &buffer);
|
||||||
|
if (bufferSize < 0)
|
||||||
|
break;
|
||||||
|
if (buffer == NULL) {
|
||||||
|
success = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// process the event
|
// process the event
|
||||||
status_t error = _ProcessEvent(header, bufferSize);
|
status_t error = _ProcessEvent(event, cpu, buffer, bufferSize);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -178,7 +182,7 @@ MainModelLoader::_Loader()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
MainModelLoader::_ProcessEvent(const system_profiler_event_header* header,
|
MainModelLoader::_ProcessEvent(uint32 event, uint32 cpu, const void* buffer,
|
||||||
size_t size)
|
size_t size)
|
||||||
{
|
{
|
||||||
// TODO: Implement!
|
// TODO: Implement!
|
||||||
|
|||||||
@@ -29,9 +29,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
static status_t _LoaderEntry(void* data);
|
static status_t _LoaderEntry(void* data);
|
||||||
status_t _Loader();
|
status_t _Loader();
|
||||||
status_t _ProcessEvent(
|
status_t _ProcessEvent(uint32 event, uint32 cpu,
|
||||||
const system_profiler_event_header* header,
|
const void* buffer, size_t size);
|
||||||
size_t size);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BLocker fLock;
|
BLocker fLock;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
|
|
||||||
|
#include <system_profiler_defs.h>
|
||||||
|
|
||||||
|
|
||||||
#define INPUT_BUFFER_SIZE (128 * 1024)
|
#define INPUT_BUFFER_SIZE (128 * 1024)
|
||||||
|
|
||||||
@@ -98,39 +100,58 @@ BDebugEventInputStream::Unset()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \brief Returns the next event in the stream.
|
||||||
|
|
||||||
|
At the end of the stream \c 0 is returned and \c *_buffer is set to \c NULL.
|
||||||
|
For events that don't have data associated with them, \c *_buffer will still
|
||||||
|
be non-NULL, even if dereferencing that address is not allowed.
|
||||||
|
|
||||||
|
\param _event Pointer to a pre-allocated location where the event ID shall
|
||||||
|
be stored.
|
||||||
|
\param _cpu Pointer to a pre-allocated location where the CPU index shall
|
||||||
|
be stored.
|
||||||
|
\param _buffer Pointer to a pre-allocated location where the pointer to the
|
||||||
|
event data shall be stored.
|
||||||
|
\return A negative error code in case an error occurred while trying to read
|
||||||
|
the info, the size of the data associated with the event otherwise.
|
||||||
|
*/
|
||||||
ssize_t
|
ssize_t
|
||||||
BDebugEventInputStream::ReadNextEvent(
|
BDebugEventInputStream::ReadNextEvent(uint32* _event, uint32* _cpu,
|
||||||
const system_profiler_event_header** _header)
|
const void** _buffer)
|
||||||
{
|
{
|
||||||
// get the next header
|
// get the next header
|
||||||
status_t error = _GetData(sizeof(system_profiler_event_header));
|
status_t error = _GetData(sizeof(system_profiler_event_header));
|
||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
if (error == B_BAD_DATA && fBufferSize == 0)
|
if (error == B_BAD_DATA && fBufferSize == 0) {
|
||||||
return B_ENTRY_NOT_FOUND;
|
*_buffer = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
system_profiler_event_header* header
|
system_profiler_event_header header
|
||||||
= (system_profiler_event_header*)(fBuffer + fBufferPosition);
|
= *(system_profiler_event_header*)(fBuffer + fBufferPosition);
|
||||||
|
|
||||||
|
// skip the header in the buffer
|
||||||
|
fBufferSize -= sizeof(system_profiler_event_header);
|
||||||
|
fBufferPosition += sizeof(system_profiler_event_header);
|
||||||
|
|
||||||
// get the data
|
// get the data
|
||||||
size_t size = header->size;
|
if (header.size > 0) {
|
||||||
size_t totalSize = sizeof(system_profiler_event_header) + size;
|
error = _GetData(header.size);
|
||||||
if (header->size > 0) {
|
|
||||||
error = _GetData(totalSize);
|
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// header might have moved when getting the data
|
*_event = header.event;
|
||||||
header = (system_profiler_event_header*)(fBuffer + fBufferPosition);
|
*_cpu = header.cpu;
|
||||||
|
*_buffer = fBuffer + fBufferPosition;
|
||||||
|
|
||||||
// skip the event in the buffer
|
// skip the event in the buffer
|
||||||
fBufferSize -= totalSize;
|
fBufferSize -= header.size;
|
||||||
fBufferPosition += totalSize;
|
fBufferPosition += header.size;
|
||||||
|
|
||||||
*_header = header;
|
return header.size;
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user