diff --git a/src/bin/debug/profile/BasicThreadProfileResult.cpp b/src/bin/debug/profile/BasicThreadProfileResult.cpp index a04257fcde..03a9ac2dc7 100644 --- a/src/bin/debug/profile/BasicThreadProfileResult.cpp +++ b/src/bin/debug/profile/BasicThreadProfileResult.cpp @@ -56,15 +56,24 @@ BasicThreadImage::Init() } -void +bool BasicThreadImage::AddHit(addr_t address) { int32 symbolIndex = fImage->FindSymbol(address); - if (symbolIndex >= 0) - fSymbolHits[symbolIndex]++; - else - fUnknownHits++; + if (symbolIndex < 0) + return false; + fSymbolHits[symbolIndex]++; + fTotalHits++; + + return true; +} + + +void +BasicThreadImage::AddUnknownHit() +{ + fUnknownHits++; fTotalHits++; } @@ -264,17 +273,27 @@ void ExclusiveThreadProfileResult::AddSamples(addr_t* samples, int32 sampleCount) { BasicThreadImage* image = NULL; + // the image in which we hit a symbol + BasicThreadImage* firstImage = NULL; + // the first image we hit, != image if no symbol was hit + for (int32 k = 0; k < sampleCount; k++) { addr_t address = samples[k]; image = FindImage(address); if (image != NULL) { - image->AddHit(address); - break; + if (image->AddHit(address)) + break; + if (firstImage == NULL) + firstImage = image; } } - if (image == NULL) - fUnkownTicks++; + if (image == NULL) { + if (firstImage != NULL) + firstImage->AddUnknownHit(); + else + fUnkownTicks++; + } fTotalTicks++; fTotalSampleCount += sampleCount; diff --git a/src/bin/debug/profile/BasicThreadProfileResult.h b/src/bin/debug/profile/BasicThreadProfileResult.h index 1c0ce319f2..77c8b33108 100644 --- a/src/bin/debug/profile/BasicThreadProfileResult.h +++ b/src/bin/debug/profile/BasicThreadProfileResult.h @@ -16,7 +16,8 @@ public: virtual status_t Init(); - inline void AddHit(addr_t address); + inline bool AddHit(addr_t address); + inline void AddUnknownHit(); inline void AddSymbolHit(int32 symbolIndex); inline void AddImageHit(); diff --git a/src/bin/debug/profile/Image.h b/src/bin/debug/profile/Image.h index 97c6b18f4c..1e6af5c0d0 100644 --- a/src/bin/debug/profile/Image.h +++ b/src/bin/debug/profile/Image.h @@ -15,9 +15,12 @@ public: int32 creationEvent); ~Image(); + inline SharedImage* GetSharedImage() const { return fImage; } + inline const image_id ID() const; inline const char* Name() const; inline team_id Owner() const; + inline addr_t LoadDelta() const { return fLoadDelta; } inline int32 CreationEvent() const; inline int32 DeletionEvent() const; diff --git a/src/bin/debug/profile/profile.cpp b/src/bin/debug/profile/profile.cpp index 16434eeff5..dd695f8d70 100644 --- a/src/bin/debug/profile/profile.cpp +++ b/src/bin/debug/profile/profile.cpp @@ -97,6 +97,7 @@ public: : fTeams(20, true), fThreads(20, true), + fKernelTeam(NULL), fDebuggerPort(debuggerPort) { } @@ -154,8 +155,11 @@ public: void RemoveTeam(team_id teamID) { - if (Team* team = FindTeam(teamID)) + if (Team* team = FindTeam(teamID)) { + if (team == fKernelTeam) + fKernelTeam = NULL; fTeams.RemoveItem(team, true); + } } void RemoveThread(thread_id threadID) @@ -244,7 +248,7 @@ private: return B_NO_MEMORY; status_t error = addedInfo != NULL - ? team->Init(addedInfo) + ? _InitUndebuggedTeam(team, addedInfo) : _InitDebuggedTeam(team, teamID); if (error != B_OK) { delete team; @@ -253,6 +257,9 @@ private: fTeams.AddItem(team); + if (teamID == B_SYSTEM_TEAM) + fKernelTeam = team; + if (_team != NULL) *_team = team; @@ -275,6 +282,28 @@ private: return _LoadTeamImages(team, B_SYSTEM_TEAM); } + status_t _InitUndebuggedTeam(Team* team, + system_profiler_team_added* addedInfo) + { + // init the team + status_t error = team->Init(addedInfo); + if (error != B_OK) + return error; + + // in case of a user team, add the kernel images + if (team->ID() == B_SYSTEM_TEAM || fKernelTeam == NULL) + return B_OK; + + const BObjectList& kernelImages = fKernelTeam->Images(); + int32 count = kernelImages.CountItems(); + for (int32 i = 0; i < count; i++) { + SharedImage* sharedImage = kernelImages.ItemAt(i)->GetSharedImage(); + team->AddImage(sharedImage, sharedImage->Info(), B_SYSTEM_TEAM, 0); + } + + return B_OK; + } + status_t _LoadTeamImages(Team* team, team_id teamID) { // iterate through the team's images and collect the symbols @@ -360,6 +389,7 @@ private: BObjectList fTeams; BObjectList fThreads; ImageMap fImages; + Team* fKernelTeam; port_id fDebuggerPort; }; @@ -409,8 +439,6 @@ process_event_buffer(ThreadManager& threadManager, uint8* buffer, = (system_profiler_team_added*)buffer; threadManager.AddTeam(event); -// TODO: ATM we're not adding kernel images to the team, if this is a team -// created after we started profiling! break; }