Signed-off-by: xdmal <maxiaodong16@huawei.com>

Why
DFX use test in the use of hap, found that generate json file could not be chrome parsing

Description
Change the time stamp of the type of the variable, which can be stored subtle level
Change the code logic, which can identify fault frames and export right to json

 On branch master
 Your branch is up to date with 'origin/master'.
This commit is contained in:
xdmal 2022-02-08 14:39:46 +08:00
parent f037ce6928
commit 2108edcd88
6 changed files with 21 additions and 21 deletions

View File

@ -83,7 +83,7 @@ void CpuProfiler::StartCpuProfiler(const EcmaVM *vm, const std::string &fileName
return;
}
#endif
time_t ts = ProfileProcessor::GetMicrosecondsTimeStamp();
uint64_t ts = ProfileProcessor::GetMicrosecondsTimeStamp();
ts = ts % TIME_CHANGE;
SetProfileStart(ts);
Platform::GetCurrentPlatform()->PostTask(std::make_unique<ProfileProcessor>(generator_, vm, interval_));
@ -121,9 +121,9 @@ CpuProfiler::~CpuProfiler()
}
}
void CpuProfiler::SetProfileStart(time_t nowTimeStamp)
void CpuProfiler::SetProfileStart(uint64_t nowTimeStamp)
{
time_t ts = ProfileProcessor::GetMicrosecondsTimeStamp();
uint64_t ts = ProfileProcessor::GetMicrosecondsTimeStamp();
ts = ts % TIME_CHANGE;
struct CurrentProcessInfo currentProcessInfo = {0};
GetCurrentProcessInfo(currentProcessInfo);

View File

@ -23,8 +23,8 @@
namespace panda::ecmascript {
struct CurrentProcessInfo {
time_t nowTimeStamp = 0;
time_t tts = 0;
uint64_t nowTimeStamp = 0;
uint64_t tts = 0;
pid_t pid = 0;
pthread_t tid = 0;
};
@ -66,7 +66,7 @@ private:
static CpuProfiler *singleton_;
explicit CpuProfiler();
void SetProfileStart(time_t nowTimeStamp);
void SetProfileStart(uint64_t nowTimeStamp);
void GetCurrentProcessInfo(struct CurrentProcessInfo &currentProcessInfo) const;
bool CheckFileName(const std::string &fileName, std::string &absoluteFilePath) const;

View File

@ -32,7 +32,7 @@ ProfileGenerator::~ProfileGenerator()
}
}
void ProfileGenerator::AddSample(CVector<JSMethod *> sample, time_t sampleTimeStamp)
void ProfileGenerator::AddSample(CVector<JSMethod *> sample, uint64_t sampleTimeStamp)
{
static int PreviousId = 0;
struct MethodKey methodkey;
@ -72,9 +72,9 @@ void ProfileGenerator::AddSample(CVector<JSMethod *> sample, time_t sampleTimeSt
}
}
}
static time_t threadStartTime = 0;
static uint64_t threadStartTime = 0;
struct SampleInfo sampleInfo;
sampleInfo.id = methodNode.id;
sampleInfo.id = methodNode.id == 0 ? PreviousId = 1, 1 : methodNode.id;
sampleInfo.line = stackTopLines_[methodNode.id];
if (threadStartTime == 0) {
sampleInfo.timeStamp = sampleTimeStamp - threadStartTime_;
@ -154,11 +154,11 @@ void ProfileGenerator::WriteMethodsAndSampleInfo(bool timeEnd)
"\"0x2\",\"name\":\"ProfileChunk\",\"ph\":\"P\",\"pid\":";
pid_t pid = getpid();
pthread_t tid = syscall(SYS_gettid);
time_t ts = ProfileProcessor::GetMicrosecondsTimeStamp();
uint64_t ts = ProfileProcessor::GetMicrosecondsTimeStamp();
ts = ts % TIME_CHANGE;
struct timespec time = {0, 0};
clock_gettime(CLOCK_MONOTONIC, &time);
time_t tts = time.tv_nsec / 1000; // 1000:Nanoseconds to milliseconds.
uint64_t tts = time.tv_nsec / 1000; // 1000:Nanoseconds to milliseconds.
sampleData_ += std::to_string(pid) + ",\"tid\":" +
std::to_string(tid) + ",\"ts\":" +
std::to_string(ts) + ",\"tts\":" +
@ -198,7 +198,7 @@ struct StackInfo ProfileGenerator::GetGcInfo()
return gcEntry;
}
void ProfileGenerator::SetThreadStartTime(time_t threadStartTime)
void ProfileGenerator::SetThreadStartTime(uint64_t threadStartTime)
{
threadStartTime_ = threadStartTime;
}

View File

@ -41,7 +41,7 @@ struct MethodNode {
struct SampleInfo {
int id = 0;
int line = 0;
time_t timeStamp = 0;
uint64_t timeStamp = 0;
};
struct MethodKey {
JSMethod *method = nullptr;
@ -57,12 +57,12 @@ public:
explicit ProfileGenerator();
virtual ~ProfileGenerator();
void AddSample(CVector<JSMethod *> sample, time_t sampleTimeStamp);
void AddSample(CVector<JSMethod *> sample, uint64_t sampleTimeStamp);
void WriteMethodsAndSampleInfo(bool timeEnd);
CVector<struct MethodNode> GetMethodNodes() const;
CDeque<struct SampleInfo> GetSamples() const;
std::string GetSampleData() const;
void SetThreadStartTime(time_t threadStartTime);
void SetThreadStartTime(uint64_t threadStartTime);
void SetStartsampleData(std::string sampleData);
void SetFileName(std::string &fileName);
const std::string GetFileName() const;
@ -81,7 +81,7 @@ private:
CMap<struct MethodKey, int> methodMap_;
CDeque<struct SampleInfo> samples_;
std::string sampleData_;
time_t threadStartTime_;
uint64_t threadStartTime_;
std::string fileName_;
};
} // namespace panda::ecmascript

View File

@ -33,8 +33,8 @@ ProfileProcessor::~ProfileProcessor() {}
bool ProfileProcessor::Run(uint32_t threadIndex)
{
time_t startTime = 0;
time_t endTime = 0;
uint64_t startTime = 0;
uint64_t endTime = 0;
startTime = GetMicrosecondsTimeStamp();
generator_->SetThreadStartTime(startTime);
while (isStart_) {
@ -64,7 +64,7 @@ bool ProfileProcessor::Run(uint32_t threadIndex)
generator_->GetSamples().size() == 100) { // 100:Number of Samples currently stored
generator_->WriteMethodsAndSampleInfo(false);
}
time_t ts = interval_ - (endTime - startTime);
int64_t ts = interval_ - (endTime - startTime);
if (ts > 0) {
usleep(ts);
}
@ -81,7 +81,7 @@ bool ProfileProcessor::Run(uint32_t threadIndex)
return true;
}
time_t ProfileProcessor::GetMicrosecondsTimeStamp()
uint64_t ProfileProcessor::GetMicrosecondsTimeStamp()
{
struct timeval time;
gettimeofday(&time, NULL);

View File

@ -25,7 +25,7 @@
namespace panda::ecmascript {
class ProfileProcessor : public Task {
public:
static time_t GetMicrosecondsTimeStamp();
static uint64_t GetMicrosecondsTimeStamp();
static JSThread *GetJSThread();
static void SetIsStart(bool isStart);