Bug 1321617 - Add a test for profiler_stream_json_for_this_process. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Sat, 08 Apr 2017 23:25:19 -0400
changeset 559168 d5fad5f562b1552c978c901e024c2cead345705d
parent 559167 21b5248514c181be7903f56a95ebd0bb0673a3aa
child 623317 3bf615b75b4288ff6df3fa153041c123462d80d7
push id53008
push userbmo:mstange@themasta.com
push dateSun, 09 Apr 2017 03:27:44 +0000
reviewersnjn
bugs1321617
milestone55.0a1
Bug 1321617 - Add a test for profiler_stream_json_for_this_process. r?njn MozReview-Commit-ID: A5Iu3dQFvHK
tools/profiler/tests/gtest/GeckoProfiler.cpp
--- a/tools/profiler/tests/gtest/GeckoProfiler.cpp
+++ b/tools/profiler/tests/gtest/GeckoProfiler.cpp
@@ -11,16 +11,17 @@
 
 #include "gtest/gtest.h"
 
 #include "GeckoProfiler.h"
 #include "ProfilerMarkers.h"
 #include "jsapi.h"
 #include "js/Initialization.h"
 #include "mozilla/UniquePtrExtensions.h"
+#include "ProfileJSONWriter.h"
 
 #include <string.h>
 
 // Note: profiler_init() has already been called in XRE_main(), so we can't
 // test it here. Likewise for profiler_shutdown(), and GeckoProfilerInitRAII
 // (which is just an RAII wrapper for profiler_init() and profiler_shutdown()).
 
 using namespace mozilla;
@@ -348,16 +349,41 @@ TEST(GeckoProfiler, GetProfile)
   UniquePtr<char[]> profile = profiler_get_profile();
   ASSERT_TRUE(profile && profile[0] == '{');
 
   profiler_stop();
 
   ASSERT_TRUE(!profiler_get_profile());
 }
 
+TEST(GeckoProfiler, StreamJSONForThisProcess)
+{
+  const char* features[] = { "stackwalk" };
+  const char* filters[] = { "GeckoMain" };
+
+  SpliceableChunkedJSONWriter w;
+  ASSERT_TRUE(!profiler_stream_json_for_this_process(w));
+
+  profiler_start(PROFILE_DEFAULT_ENTRIES, PROFILE_DEFAULT_INTERVAL,
+                 features, MOZ_ARRAY_LENGTH(features),
+                 filters, MOZ_ARRAY_LENGTH(filters));
+
+  w.Start(SpliceableJSONWriter::SingleLineStyle);
+  bool isActive = profiler_stream_json_for_this_process(w);
+  ASSERT_TRUE(isActive);
+  w.End();
+
+  UniquePtr<char[]> profile = w.WriteFunc()->CopyData();
+  ASSERT_TRUE(profile && profile[0] == '{');
+
+  profiler_stop();
+
+  ASSERT_TRUE(!profiler_stream_json_for_this_process(w));
+}
+
 TEST(GeckoProfiler, PseudoStack)
 {
   const char* features[] = { "stackwalk" };
   const char* filters[] = { "GeckoMain" };
 
   PROFILER_LABEL("A", "B", js::ProfileEntry::Category::OTHER);
   PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER);