NS_IMETHOD Run() { TableTicker *t = mozilla::tls::get<TableTicker>(pkey_ticker); char buff[MAXPATHLEN]; #ifdef ANDROID #define FOLDER "/sdcard/" #elif defined(XP_WIN) #define FOLDER "%TEMP%\\" #else #define FOLDER "/tmp/" #endif snprintf(buff, MAXPATHLEN, "%sprofile_%i_%i.txt", FOLDER, XRE_GetProcessType(), getpid()); #ifdef XP_WIN // Expand %TEMP% on Windows { char tmp[MAXPATHLEN]; ExpandEnvironmentStringsA(buff, tmp, mozilla::ArrayLength(tmp)); strcpy(buff, tmp); } #endif FILE* stream = ::fopen(buff, "w"); if (stream) { t->GetPrimaryThreadProfile()->WriteProfile(stream); ::fclose(stream); LOG("Saved to " FOLDER "profile_TYPE_PID.txt"); } else { LOG("Fail to open profile log file."); } return NS_OK; }
char* mozilla_sampler_get_profile() { TableTicker *t = mozilla::tls::get<TableTicker>(pkey_ticker); if (!t) { return NULL; } StringBuilder profile; t->GetPrimaryThreadProfile()->ToString(profile); char *rtn = (char*)malloc( (profile.Length()+1) * sizeof(char) ); strcpy(rtn, profile.Buffer()); return rtn; }
char* mozilla_sampler_get_profile() { TableTicker *t = mozilla::tls::get<TableTicker>(pkey_ticker); if (!t) { return NULL; } std::stringstream profile; profile << *(t->GetPrimaryThreadProfile()); std::string profileString = profile.str(); char *rtn = (char*)malloc( (profileString.length() + 1) * sizeof(char) ); strcpy(rtn, profileString.c_str()); return rtn; }
char* mozilla_sampler_get_profile() { TableTicker *t = tlsTicker.get(); if (!t) { return NULL; } std::stringstream profile; t->SetPaused(true); profile << *(t->GetPrimaryThreadProfile()); t->SetPaused(false); std::string profileString = profile.str(); char *rtn = (char*)malloc( (profileString.length() + 1) * sizeof(char) ); strcpy(rtn, profileString.c_str()); return rtn; }
NS_IMETHOD Run() { TableTicker *t = tlsTicker.get(); char buff[MAXPATHLEN]; #ifdef ANDROID #define FOLDER "/sdcard/" #elif defined(XP_WIN) #define FOLDER "%TEMP%\\" #else #define FOLDER "/tmp/" #endif snprintf(buff, MAXPATHLEN, "%sprofile_%i_%i.txt", FOLDER, XRE_GetProcessType(), getpid()); #ifdef XP_WIN // Expand %TEMP% on Windows { char tmp[MAXPATHLEN]; ExpandEnvironmentStringsA(buff, tmp, mozilla::ArrayLength(tmp)); strcpy(buff, tmp); } #endif // Pause the profiler during saving. // This will prevent us from recording sampling // regarding profile saving. This will also // prevent bugs caused by the circular buffer not // being thread safe. Bug 750989. std::ofstream stream; stream.open(buff); t->SetPaused(true); if (stream.is_open()) { stream << *(t->GetPrimaryThreadProfile()); stream << "h-" << GetSharedLibraryInfoString() << std::endl; stream.close(); LOG("Saved to " FOLDER "profile_TYPE_PID.txt"); } else { LOG("Fail to open profile log file."); } t->SetPaused(false); return NS_OK; }