Bug 1365400 - Add nsIProfiler::GetAllFeatures. r=njn

MozReview-Commit-ID: EfjiUYvfIgM

--HG--
extra : rebase_source : a690e0a451c31fe644ac3843f96afc1e6a2b42f0
This commit is contained in:
Markus Stange 2017-06-14 00:20:35 -04:00
Родитель d6cb0eba49
Коммит 61580a8992
2 изменённых файлов: 31 добавлений и 7 удалений

Просмотреть файл

@ -65,8 +65,19 @@ interface nsIProfiler : nsISupports
[optional] in double aSinceTime); [optional] in double aSinceTime);
boolean IsActive(); boolean IsActive();
/**
* Returns an array of the features that are supported in this build.
* Features may vary depending on platform and build flags.
*/
void GetFeatures(out uint32_t aCount, [retval, array, size_is(aCount)] out string aFeatures); void GetFeatures(out uint32_t aCount, [retval, array, size_is(aCount)] out string aFeatures);
/**
* Returns an array of all features that are supported by the profiler.
* The array may contain features that are not supported in this build.
*/
void GetAllFeatures(out uint32_t aCount, [retval, array, size_is(aCount)] out string aFeatures);
/** /**
* The starting parameters that were sent to the profiler for sampling. * The starting parameters that were sent to the profiler for sampling.
* If the profiler is not currently sampling, this will return null. * If the profiler is not currently sampling, this will return null.

Просмотреть файл

@ -418,13 +418,12 @@ nsProfiler::IsActive(bool *aIsActive)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP static void
nsProfiler::GetFeatures(uint32_t* aCount, char*** aFeatureList) GetArrayOfStringsForFeatures(uint32_t aFeatures,
uint32_t* aCount, char*** aFeatureList)
{ {
uint32_t features = profiler_get_available_features();
#define COUNT_IF_SET(n_, str_, Name_) \ #define COUNT_IF_SET(n_, str_, Name_) \
if (ProfilerFeature::Has##Name_(features)) { \ if (ProfilerFeature::Has##Name_(aFeatures)) { \
len++; \ len++; \
} }
@ -437,7 +436,7 @@ nsProfiler::GetFeatures(uint32_t* aCount, char*** aFeatureList)
auto featureList = static_cast<char**>(moz_xmalloc(len * sizeof(char*))); auto featureList = static_cast<char**>(moz_xmalloc(len * sizeof(char*)));
#define DUP_IF_SET(n_, str_, Name_) \ #define DUP_IF_SET(n_, str_, Name_) \
if (ProfilerFeature::Has##Name_(features)) { \ if (ProfilerFeature::Has##Name_(aFeatures)) { \
size_t strLen = strlen(str_); \ size_t strLen = strlen(str_); \
featureList[i] = static_cast<char*>( \ featureList[i] = static_cast<char*>( \
nsMemory::Clone(str_, (strLen + 1) * sizeof(char))); \ nsMemory::Clone(str_, (strLen + 1) * sizeof(char))); \
@ -448,10 +447,24 @@ nsProfiler::GetFeatures(uint32_t* aCount, char*** aFeatureList)
size_t i = 0; size_t i = 0;
PROFILER_FOR_EACH_FEATURE(DUP_IF_SET) PROFILER_FOR_EACH_FEATURE(DUP_IF_SET)
#undef STRDUP_IF_SET #undef DUP_IF_SET
*aFeatureList = featureList; *aFeatureList = featureList;
*aCount = len; *aCount = len;
}
NS_IMETHODIMP
nsProfiler::GetFeatures(uint32_t* aCount, char*** aFeatureList)
{
uint32_t features = profiler_get_available_features();
GetArrayOfStringsForFeatures(features, aCount, aFeatureList);
return NS_OK;
}
NS_IMETHODIMP
nsProfiler::GetAllFeatures(uint32_t* aCount, char*** aFeatureList)
{
GetArrayOfStringsForFeatures((uint32_t)-1, aCount, aFeatureList);
return NS_OK; return NS_OK;
} }