最近中在看art代码,看到这个函数的时候,想到logcat的events log中有大量的dvm_lock_sameple信息
进程名,主线程?,线程名字,锁等待时间,当前持有者的文件名,行号,上一个持有者文件名,行号,锁等待的百分比
- 打印此条LOG的时候,上一个锁的持有者已经释放锁,本线程为下一个锁的持有者,即将获取锁
- 上一个持有者的文件名,可能是“-”,表示与持有者是同一个文件。
dvm_lock_sample: [com.banyac.midrive.launcher,1,main,6,SourceFile,234,-,358,1]
- 1
art/runtime/monitor_android.cc
void Monitor::LogContentionEvent(Thread* self, uint32_t wait_ms, uint32_t sample_percent,
const char* owner_filename, uint32_t owner_line_number) {
// Emit the event list length, 1 byte.
char eventBuffer[174];
char* cp = eventBuffer;
*cp++ = 9;
// Emit the process name, <= 37 bytes.
int fd = open("/proc/self/cmdline", O_RDONLY);
char procName[33];
memset(procName, 0, sizeof(procName));
read(fd, procName, sizeof(procName) - 1);
close(fd);
size_t len = strlen(procName);
cp = EventLogWriteString(cp, procName, len);
// Emit the sensitive thread ("main thread") status, 5 bytes.
cp = EventLogWriteInt(cp, Monitor::IsSensitiveThread());
// Emit self thread name string, <= 37 bytes.
std::string thread_name;
self->GetThreadName(thread_name);
cp = EventLogWriteString(cp, thread_name.c_str(), thread_name.size());
// Emit the wait time, 5 bytes.
cp = EventLogWriteInt(cp, wait_ms);
// Emit the source code file name, <= 37 bytes.
uint32_t pc;
mirror::ArtMethod* m = self->GetCurrentMethod(&pc);
const char* filename;
uint32_t line_number;
TranslateLocation(m, pc, &filename, &line_number);
cp = EventLogWriteString(cp, filename, strlen(filename));
// Emit the source code line number, 5 bytes.
cp = EventLogWriteInt(cp, line_number);
// Emit the lock owner source code file name, <= 37 bytes.
if (owner_filename == NULL) {
owner_filename = "";
} else if (strcmp(filename, owner_filename) == 0) {
// Common case, so save on log space.
owner_filename = "-";
}
cp = EventLogWriteString(cp, owner_filename, strlen(owner_filename));
// Emit the source code line number, 5 bytes.
cp = EventLogWriteInt(cp, owner_line_number);
// Emit the sample percentage, 5 bytes.
cp = EventLogWriteInt(cp, sample_percent);
CHECK_LE((size_t)(cp - eventBuffer), sizeof(eventBuffer));
android_btWriteLog(EVENT_LOG_TAG_dvm_lock_sample, EVENT_TYPE_LIST, eventBuffer,
(size_t)(cp - eventBuffer));
}