1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_PUBLIC_COMMON_PROFILING_UTILS_H_ 6 #define CONTENT_PUBLIC_COMMON_PROFILING_UTILS_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/callback_forward.h" 12 #include "base/files/file.h" 13 #include "base/synchronization/waitable_event.h" 14 #include "content/common/content_export.h" 15 16 namespace content { 17 18 // Open the file that should be used by a child process to save its profiling 19 // data. 20 CONTENT_EXPORT base::File OpenProfilingFile(); 21 22 // Serves WaitableEvent that should be used by the child processes to signal 23 // that they have finished dumping the profiling data. 24 class CONTENT_EXPORT WaitForProcessesToDumpProfilingInfo { 25 public: 26 WaitForProcessesToDumpProfilingInfo(); 27 ~WaitForProcessesToDumpProfilingInfo(); 28 WaitForProcessesToDumpProfilingInfo( 29 const WaitForProcessesToDumpProfilingInfo& other) = delete; 30 WaitForProcessesToDumpProfilingInfo& operator=( 31 const WaitForProcessesToDumpProfilingInfo&) = delete; 32 33 // Wait for all the events served by |GetNewWaitableEvent| to signal. 34 void WaitForAll(); 35 36 // Return a new waitable event. Calling |WaitForAll| will wait for this event 37 // to be signaled. 38 // The returned WaitableEvent is owned by this 39 // WaitForProcessesToDumpProfilingInfo instance. 40 base::WaitableEvent* GetNewWaitableEvent(); 41 42 private: 43 // Implementation of WaitForAll that will run on the thread pool. This will 44 // run |quit_closure| once it's done waiting. 45 void WaitForAllOnThreadPool(base::OnceClosure quit_closure); 46 47 std::vector<std::unique_ptr<base::WaitableEvent>> events_; 48 }; 49 50 } // namespace content 51 52 #endif // CONTENT_PUBLIC_COMMON_PROFILING_UTILS_H_ 53