Skip to content

Commit

Permalink
Merge pull request #11 from Lifzho/main
Browse files Browse the repository at this point in the history
Add CLOCK collector & its json output when perf_collector collect CSPMU counters.
  • Loading branch information
per-mathisen-arm authored Feb 26, 2024
2 parents 55567fd + ceb79e5 commit 7b8e59b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 30 additions & 7 deletions collectors/perf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ bool PerfCollector::deinit()
mMultiPMUThreads.clear();
mBookerThread.clear();
mCSPMUThreads.clear();
mClocks.clear();

clear();

Expand Down Expand Up @@ -342,9 +343,11 @@ bool PerfCollector::start()
return false;

for (perf_thread& t: mCSPMUThreads)
if ( !t.eventCtx.start() )
return false;

{
if ( !t.eventCtx.start() )
return false;
mClocks.emplace(t.device_name, std::vector<timespec>{});
}
mCollecting = true;
return true;
}
Expand Down Expand Up @@ -428,6 +431,10 @@ bool PerfCollector::collect(int64_t now)
{
snap = t.eventCtx.collect(now);
t.update_data(snap);
// save CLOCK_MONOTONIC_RAW when collect
struct timespec tmp_clock = {0, 0};
clock_gettime(CLOCK_MONOTONIC_RAW, &tmp_clock);
mClocks[t.device_name].push_back(tmp_clock);
}

return true;
Expand All @@ -452,9 +459,22 @@ bool PerfCollector::postprocess(const std::vector<int64_t>& timing)
i++;
}
}
for (unsigned int n =0;n<mCSPMUEvents.size();n++)
for (perf_thread& t : mCSPMUThreads)
{
mCSPMUThreads[n].postprocess(replayValue);
t.postprocess(replayValue);
std::string sec_name = t.device_name + "_sec";
std::string nsec_name = t.device_name + "_nsec";
std::vector<int64_t> clocks_sec;
std::vector<int64_t> clocks_nsec;
Json::Value clockValue;
for (auto iter : mClocks[t.device_name])
{
clocks_sec.push_back(iter.tv_sec);
clocks_nsec.push_back(iter.tv_nsec);
clockValue[sec_name.c_str()].append(iter.tv_sec);
clockValue[nsec_name.c_str()].append(iter.tv_nsec);
}
mCustomResult["thread_data"].append(clockValue);
}
for (perf_thread& t : mBookerThread)
{
Expand Down Expand Up @@ -641,10 +661,13 @@ void PerfCollector::create_perf_thread()
}
}
closedir(dirp);

for (unsigned int i =0; i<mCSPMUEvents.size();i++)

int i=0;
for (auto pair : mCSPMUEvents)
{
mCSPMUThreads.emplace_back(getpid(), current_pName);
mCSPMUThreads[i].device_name = pair.second[0].device;
i++;
}

if (mBookerEvents.size() > 0)
Expand Down
2 changes: 2 additions & 0 deletions collectors/perf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class PerfCollector : public Collector
std::vector<struct event> mBookerEvents;
std::map<int, std::vector<struct event>> mMultiPMUEvents;
std::map<int, std::vector<struct event>> mCSPMUEvents;
std::map<std::string, std::vector<struct timespec>> mClocks; // device_name -> clock_vector

struct perf_thread
{
Expand Down Expand Up @@ -163,6 +164,7 @@ class PerfCollector : public Collector
const std::string name;
event_context eventCtx;
CollectorValueResults mResultsPerThread;
std::string device_name;
};

std::vector<struct perf_thread> mReplayThreads;
Expand Down

0 comments on commit 7b8e59b

Please sign in to comment.