Added support for providing a command line also for the system profiling mode.
Just as in the other mode the command is started and profiling stops when the command terminates. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30229 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -206,7 +206,7 @@ public:
|
|||||||
status_t AddImage(team_id teamID, const image_info& imageInfo, int32 event)
|
status_t AddImage(team_id teamID, const image_info& imageInfo, int32 event)
|
||||||
{
|
{
|
||||||
// get a shared image
|
// get a shared image
|
||||||
SharedImage* sharedImage;
|
SharedImage* sharedImage = NULL;
|
||||||
status_t error = _GetSharedImage(teamID, imageInfo, &sharedImage);
|
status_t error = _GetSharedImage(teamID, imageInfo, &sharedImage);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
@@ -424,9 +424,9 @@ get_id(const char *str, int32 &id)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
process_event_buffer(ThreadManager& threadManager, uint8* buffer,
|
process_event_buffer(ThreadManager& threadManager, uint8* buffer,
|
||||||
size_t bufferSize)
|
size_t bufferSize, team_id mainTeam)
|
||||||
{
|
{
|
||||||
//printf("process_event_buffer(%p, %lu)\n", buffer, bufferSize);
|
//printf("process_event_buffer(%p, %lu)\n", buffer, bufferSize);
|
||||||
const uint8* bufferEnd = buffer + bufferSize;
|
const uint8* bufferEnd = buffer + bufferSize;
|
||||||
@@ -452,8 +452,12 @@ process_event_buffer(ThreadManager& threadManager, uint8* buffer,
|
|||||||
system_profiler_team_removed* event
|
system_profiler_team_removed* event
|
||||||
= (system_profiler_team_removed*)buffer;
|
= (system_profiler_team_removed*)buffer;
|
||||||
|
|
||||||
// TODO: Print results!
|
|
||||||
threadManager.RemoveTeam(event->team);
|
threadManager.RemoveTeam(event->team);
|
||||||
|
|
||||||
|
// quit, if the main team we're interested in is gone
|
||||||
|
if (mainTeam >= 0 && event->team == mainTeam)
|
||||||
|
return true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,12 +529,14 @@ process_event_buffer(ThreadManager& threadManager, uint8* buffer,
|
|||||||
{
|
{
|
||||||
// Marks the end of the ring buffer -- we need to ignore the
|
// Marks the end of the ring buffer -- we need to ignore the
|
||||||
// remaining bytes.
|
// remaining bytes.
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer += header->size;
|
buffer += header->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -542,8 +548,20 @@ signal_handler(int signal, void* data)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
profile_all()
|
profile_all(const char* const* programArgs, int programArgCount)
|
||||||
{
|
{
|
||||||
|
// Load the executable, if we have to.
|
||||||
|
thread_id threadID = -1;
|
||||||
|
if (programArgCount >= 1) {
|
||||||
|
threadID = load_program(programArgs, programArgCount,
|
||||||
|
gOptions.profile_loading);
|
||||||
|
if (threadID < 0) {
|
||||||
|
fprintf(stderr, "%s: Failed to start `%s': %s\n", kCommandName,
|
||||||
|
programArgs[0], strerror(threadID));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// install signal handlers so we can exit gracefully
|
// install signal handlers so we can exit gracefully
|
||||||
struct sigaction action;
|
struct sigaction action;
|
||||||
action.sa_handler = (sighandler_t)signal_handler;
|
action.sa_handler = (sighandler_t)signal_handler;
|
||||||
@@ -584,6 +602,10 @@ profile_all()
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resume the loaded team, if we have one
|
||||||
|
if (threadID >= 0)
|
||||||
|
resume_thread(threadID);
|
||||||
|
|
||||||
// main event loop
|
// main event loop
|
||||||
while (true) {
|
while (true) {
|
||||||
// get the current buffer
|
// get the current buffer
|
||||||
@@ -592,15 +614,21 @@ profile_all()
|
|||||||
uint8* buffer = bufferBase + bufferStart;
|
uint8* buffer = bufferBase + bufferStart;
|
||||||
//printf("processing buffer of size %lu bytes\n", bufferSize);
|
//printf("processing buffer of size %lu bytes\n", bufferSize);
|
||||||
|
|
||||||
|
bool quit;
|
||||||
if (bufferStart + bufferSize <= totalBufferSize) {
|
if (bufferStart + bufferSize <= totalBufferSize) {
|
||||||
process_event_buffer(threadManager, buffer, bufferSize);
|
quit = process_event_buffer(threadManager, buffer, bufferSize,
|
||||||
|
threadID);
|
||||||
} else {
|
} else {
|
||||||
size_t remainingSize = bufferStart + bufferSize - totalBufferSize;
|
size_t remainingSize = bufferStart + bufferSize - totalBufferSize;
|
||||||
process_event_buffer(threadManager, buffer,
|
quit = process_event_buffer(threadManager, buffer,
|
||||||
bufferSize - remainingSize);
|
bufferSize - remainingSize, threadID)
|
||||||
process_event_buffer(threadManager, bufferBase, remainingSize);
|
|| process_event_buffer(threadManager, bufferBase,
|
||||||
|
remainingSize, threadID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (quit)
|
||||||
|
break;
|
||||||
|
|
||||||
// get next buffer
|
// get next buffer
|
||||||
error = _kern_system_profiler_next_buffer(bufferSize);
|
error = _kern_system_profiler_next_buffer(bufferSize);
|
||||||
|
|
||||||
@@ -707,14 +735,14 @@ main(int argc, const char* const* argv)
|
|||||||
} else
|
} else
|
||||||
gOptions.output = stdout;
|
gOptions.output = stdout;
|
||||||
|
|
||||||
if (gOptions.profile_all) {
|
|
||||||
profile_all();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* const* programArgs = argv + optind;
|
const char* const* programArgs = argv + optind;
|
||||||
int programArgCount = argc - optind;
|
int programArgCount = argc - optind;
|
||||||
|
|
||||||
|
if (gOptions.profile_all) {
|
||||||
|
profile_all(programArgs, programArgCount);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// get thread/team to be debugged
|
// get thread/team to be debugged
|
||||||
thread_id threadID = -1;
|
thread_id threadID = -1;
|
||||||
team_id teamID = -1;
|
team_id teamID = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user