Bug 1453591 - Add a GetIDForProcessName utility function in TelemetryCommon. r?janerik,chutten
This introduces a function for getting the ProcessID value given
the name of a process.
MozReview-Commit-ID: 9cbZAO5hyL5
--- a/toolkit/components/telemetry/TelemetryCommon.cpp
+++ b/toolkit/components/telemetry/TelemetryCommon.cpp
@@ -130,16 +130,28 @@ LogToBrowserConsole(uint32_t aLogLevel,
const char*
GetNameForProcessID(ProcessID process)
{
MOZ_ASSERT(process < ProcessID::Count);
return ProcessIDToString[static_cast<uint32_t>(process)];
}
+ProcessID
+GetIDForProcessName(const char* aProcessName)
+{
+ for (uint32_t id = 0; id < static_cast<uint32_t>(ProcessID::Count); id++) {
+ if (!strcmp(GetNameForProcessID(ProcessID(id)), aProcessName)) {
+ return ProcessID(id);
+ }
+ }
+
+ return ProcessID::Count;
+}
+
GeckoProcessType
GetGeckoProcessType(ProcessID process)
{
MOZ_ASSERT(process < ProcessID::Count);
return ProcessIDToGeckoProcessType[static_cast<uint32_t>(process)];
}
bool
--- a/toolkit/components/telemetry/TelemetryCommon.h
+++ b/toolkit/components/telemetry/TelemetryCommon.h
@@ -93,16 +93,25 @@ void LogToBrowserConsole(uint32_t aLogLe
/**
* Get the name string for a ProcessID.
* This is the name we use for the Telemetry payloads.
*/
const char* GetNameForProcessID(ProcessID process);
/**
+ * Get the process id give a process name.
+ *
+ * @param aProcessName - the name of the process.
+ * @returns {ProcessID} one value from ProcessID::* or ProcessID::Count if the
+ * name of the process was not found.
+ */
+ProcessID GetIDForProcessName(const char* aProcessName);
+
+/**
* Get the GeckoProcessType for a ProcessID.
* Telemetry distinguishes between more process types than the GeckoProcessType,
* so the mapping is not direct.
*/
GeckoProcessType GetGeckoProcessType(ProcessID process);
/**
* Check if the passed telemetry identifier is valid.