Bug 1444765 - Allow setting a pid:<pid> thread filter to capture all threads for a process. r?njn
MozReview-Commit-ID: CaMsmEtQ5UY
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -68,16 +68,22 @@
#include "ProfilerParent.h"
#include "mozilla/Services.h"
#include "nsThreadUtils.h"
#include "ProfilerMarkerPayload.h"
#include "shared-libraries.h"
#include "prdtoa.h"
#include "prtime.h"
+#if defined(XP_WIN)
+#include <processthreadsapi.h> // for GetCurrentProcessId()
+#else
+#include <unistd.h> // for getpid()
+#endif // defined(XP_WIN)
+
#ifdef MOZ_TASK_TRACER
#include "GeckoTaskTracer.h"
#endif
#if defined(GP_OS_android)
# include "FennecJNINatives.h"
# include "FennecJNIWrappers.h"
#endif
@@ -423,16 +429,30 @@ private:
for (uint32_t i = 0; i < mFilters.length(); ++i) {
std::string filter = mFilters[i];
std::transform(filter.begin(), filter.end(), filter.begin(), ::tolower);
// Crude, non UTF-8 compatible, case insensitive substring search
if (name.find(filter) != std::string::npos) {
return true;
}
+
+ // If the filter starts with pid:, check for a pid match
+ if (filter.find("pid:") == 0) {
+ std::string mypid = std::to_string(
+#ifdef XP_WIN
+ GetCurrentProcessId()
+#else
+ getpid()
+#endif
+ );
+ if (filter.compare(4, std::string::npos, mypid) == 0) {
+ return true;
+ }
+ }
}
return false;
}
public:
static void Create(PSLockRef aLock, uint32_t aEntries, double aInterval,
uint32_t aFeatures,
--- a/tools/profiler/public/GeckoProfiler.h
+++ b/tools/profiler/public/GeckoProfiler.h
@@ -242,16 +242,22 @@ void profiler_shutdown();
// Start the profiler -- initializing it first if necessary -- with the
// selected options. Stops and restarts the profiler if it is already active.
// After starting the profiler is "active". The samples will be recorded in a
// circular buffer.
// "aEntries" is the number of entries in the profiler's circular buffer.
// "aInterval" the sampling interval, measured in millseconds.
// "aFeatures" is the feature set. Features unsupported by this
// platform/configuration are ignored.
+// "aFilters" is the list of thread filters. Threads that do not match any
+// of the filters are not profiled. A filter matches a thread if
+// (a) the thread name contains the filter as a case-insensitive
+// substring, or
+// (b) the filter is of the form "pid:<n>" where n is the process
+// id of the process that the thread is running in.
void profiler_start(uint32_t aEntries, double aInterval, uint32_t aFeatures,
const char** aFilters, uint32_t aFilterCount);
// Stop the profiler and discard the profile without saving it. A no-op if the
// profiler is inactive. After stopping the profiler is "inactive".
void profiler_stop();
// If the profiler is inactive, start it. If it's already active, restart it if