|
@@ -19,11 +19,10 @@ void LineProfiler::begin(){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void LineProfiler::_step(FrameId frame){
|
|
void LineProfiler::_step(FrameId frame){
|
|
|
- bool is_virtual = frame->co->is_virtual[frame->_ip];
|
|
|
|
|
- if(is_virtual) return;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ auto line_info = frame->co->lines[frame->_ip];
|
|
|
|
|
+ if(line_info.is_virtual) return;
|
|
|
std::string_view filename = frame->co->src->filename.sv();
|
|
std::string_view filename = frame->co->src->filename.sv();
|
|
|
- int line = frame->co->lines[frame->_ip];
|
|
|
|
|
|
|
+ int line = line_info.lineno;
|
|
|
|
|
|
|
|
if(frames.empty()){
|
|
if(frames.empty()){
|
|
|
frames.push({frame, clock(), nullptr});
|
|
frames.push({frame, clock(), nullptr});
|
|
@@ -31,7 +30,7 @@ void LineProfiler::_step(FrameId frame){
|
|
|
_step_end(frame, line);
|
|
_step_end(frame, line);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- std::vector<LineRecord>& file_records = records[filename];
|
|
|
|
|
|
|
+ std::vector<_LineRecord>& file_records = records[filename];
|
|
|
if(file_records.empty()){
|
|
if(file_records.empty()){
|
|
|
// initialize file_records
|
|
// initialize file_records
|
|
|
int total_lines = frame->co->src->line_starts.size();
|
|
int total_lines = frame->co->src->line_starts.size();
|
|
@@ -46,8 +45,8 @@ void LineProfiler::_step(FrameId frame){
|
|
|
|
|
|
|
|
void LineProfiler::_step_end(FrameId frame, int line){
|
|
void LineProfiler::_step_end(FrameId frame, int line){
|
|
|
clock_t now = clock();
|
|
clock_t now = clock();
|
|
|
- FrameRecord& top_frame_record = frames.top();
|
|
|
|
|
- LineRecord* prev_record = top_frame_record.prev_record;
|
|
|
|
|
|
|
+ _FrameRecord& top_frame_record = frames.top();
|
|
|
|
|
+ _LineRecord* prev_record = top_frame_record.prev_record;
|
|
|
|
|
|
|
|
int id_delta = frame.index - top_frame_record.frame.index;
|
|
int id_delta = frame.index - top_frame_record.frame.index;
|
|
|
PK_ASSERT(id_delta >= -1 && id_delta <= 1);
|
|
PK_ASSERT(id_delta >= -1 && id_delta <= 1);
|
|
@@ -69,8 +68,8 @@ void LineProfiler::_step_end(FrameId frame, int line){
|
|
|
|
|
|
|
|
void LineProfiler::end(){
|
|
void LineProfiler::end(){
|
|
|
clock_t now = clock();
|
|
clock_t now = clock();
|
|
|
- FrameRecord& top_frame_record = frames.top();
|
|
|
|
|
- LineRecord* prev_record = top_frame_record.prev_record;
|
|
|
|
|
|
|
+ _FrameRecord& top_frame_record = frames.top();
|
|
|
|
|
+ _LineRecord* prev_record = top_frame_record.prev_record;
|
|
|
|
|
|
|
|
clock_t delta = now - top_frame_record.prev_time;
|
|
clock_t delta = now - top_frame_record.prev_time;
|
|
|
top_frame_record.prev_time = now;
|
|
top_frame_record.prev_time = now;
|
|
@@ -88,7 +87,7 @@ Str LineProfiler::stats(){
|
|
|
int end_line = decl->code->end_line;
|
|
int end_line = decl->code->end_line;
|
|
|
if(start_line == -1 || end_line == -1) continue;
|
|
if(start_line == -1 || end_line == -1) continue;
|
|
|
std::string_view filename = decl->code->src->filename.sv();
|
|
std::string_view filename = decl->code->src->filename.sv();
|
|
|
- std::vector<LineRecord>& file_records = records[filename];
|
|
|
|
|
|
|
+ std::vector<_LineRecord>& file_records = records[filename];
|
|
|
if(file_records.empty()) continue;
|
|
if(file_records.empty()) continue;
|
|
|
clock_t total_time = 0;
|
|
clock_t total_time = 0;
|
|
|
for(int line = start_line; line <= end_line; line++){
|
|
for(int line = start_line; line <= end_line; line++){
|
|
@@ -100,7 +99,7 @@ Str LineProfiler::stats(){
|
|
|
ss << "Line # Hits Time Per Hit % Time Line Contents\n";
|
|
ss << "Line # Hits Time Per Hit % Time Line Contents\n";
|
|
|
ss << "==============================================================\n";
|
|
ss << "==============================================================\n";
|
|
|
for(int line = start_line; line <= end_line; line++){
|
|
for(int line = start_line; line <= end_line; line++){
|
|
|
- const LineRecord& record = file_records.at(line);
|
|
|
|
|
|
|
+ const _LineRecord& record = file_records.at(line);
|
|
|
if(!record.is_valid()) continue;
|
|
if(!record.is_valid()) continue;
|
|
|
ss << left_pad(std::to_string(line), 6);
|
|
ss << left_pad(std::to_string(line), 6);
|
|
|
if(record.hits == 0){
|
|
if(record.hits == 0){
|