16
16
* limitations under the License.
17
17
*/
18
18
19
+ #include < controller/python/chip/native/ChipMainLoopWork.h>
19
20
#include < controller/python/chip/native/PyChipError.h>
20
- #include < platform/PlatformManager.h>
21
21
22
22
#include < tracing/json/json_tracing.h>
23
23
#include < tracing/perfetto/event_storage.h>
27
27
#include < tracing/registry.h>
28
28
29
29
namespace {
30
-
31
- using chip::DeviceLayer::PlatformMgr;
32
-
33
- class ScopedStackLock
34
- {
35
- public:
36
- ScopedStackLock () { PlatformMgr ().LockChipStack (); }
37
-
38
- ~ScopedStackLock () { PlatformMgr ().UnlockChipStack (); }
39
- };
40
-
41
30
chip::Tracing::Json::JsonBackend gJsonBackend ;
42
31
43
32
chip::Tracing::Perfetto::FileTraceOutput gPerfettoFileOutput ;
@@ -47,58 +36,61 @@ chip::Tracing::Perfetto::PerfettoBackend gPerfettoBackend;
47
36
48
37
extern " C" void pychip_tracing_start_json_log (const char * file_name)
49
38
{
50
-
51
- ScopedStackLock lock;
52
-
53
- gJsonBackend .CloseFile (); // just in case, ensure no file output
54
- chip::Tracing::Register (gJsonBackend );
39
+ chip::MainLoopWork::ExecuteInMainLoop ([] {
40
+ gJsonBackend .CloseFile (); // just in case, ensure no file output
41
+ chip::Tracing::Register (gJsonBackend );
42
+ });
55
43
}
56
44
57
45
extern " C" PyChipError pychip_tracing_start_json_file (const char * file_name)
58
46
{
59
- ScopedStackLock lock;
60
-
61
- CHIP_ERROR err = gJsonBackend .OpenFile (file_name);
62
- if (err != CHIP_NO_ERROR)
63
- {
64
- return ToPyChipError (err);
65
- }
66
- chip::Tracing::Register (gJsonBackend );
67
- return ToPyChipError (CHIP_NO_ERROR);
47
+ CHIP_ERROR err = CHIP_NO_ERROR;
48
+
49
+ chip::MainLoopWork::ExecuteInMainLoop ([&err, file_name] {
50
+ err = gJsonBackend .OpenFile (file_name);
51
+ if (err != CHIP_NO_ERROR)
52
+ {
53
+ return ;
54
+ }
55
+ chip::Tracing::Register (gJsonBackend );
56
+ });
57
+
58
+ return ToPyChipError (err);
68
59
}
69
60
70
61
extern " C" void pychip_tracing_start_perfetto_system ()
71
62
{
72
- ScopedStackLock lock;
73
-
74
- chip::Tracing::Perfetto::Initialize (perfetto:: kSystemBackend );
75
- chip::Tracing::Perfetto::RegisterEventTrackingStorage ( );
76
- chip::Tracing::Register ( gPerfettoBackend );
63
+ chip::MainLoopWork::ExecuteInMainLoop ([] {
64
+ chip::Tracing::Perfetto::Initialize (perfetto:: kSystemBackend );
65
+ chip::Tracing::Perfetto::RegisterEventTrackingStorage ( );
66
+ chip::Tracing::Register ( gPerfettoBackend );
67
+ } );
77
68
}
78
69
79
70
extern " C" PyChipError pychip_tracing_start_perfetto_file (const char * file_name)
80
71
{
81
- ScopedStackLock lock;
82
-
83
- chip::Tracing::Perfetto::Initialize (perfetto::kInProcessBackend );
84
- chip::Tracing::Perfetto::RegisterEventTrackingStorage ();
85
-
86
- CHIP_ERROR err = gPerfettoFileOutput .Open (file_name);
87
- if (err != CHIP_NO_ERROR)
88
- {
89
- return ToPyChipError (err);
90
- }
91
- chip::Tracing::Register (gPerfettoBackend );
92
-
93
- return ToPyChipError (CHIP_NO_ERROR);
72
+ CHIP_ERROR err = CHIP_NO_ERROR;
73
+ chip::MainLoopWork::ExecuteInMainLoop ([&err, file_name] {
74
+ chip::Tracing::Perfetto::Initialize (perfetto::kInProcessBackend );
75
+ chip::Tracing::Perfetto::RegisterEventTrackingStorage ();
76
+
77
+ err = gPerfettoFileOutput .Open (file_name);
78
+ if (err != CHIP_NO_ERROR)
79
+ {
80
+ return ;
81
+ }
82
+ chip::Tracing::Register (gPerfettoBackend );
83
+ });
84
+
85
+ return ToPyChipError (err);
94
86
}
95
87
96
88
extern " C" void pychip_tracing_stop ()
97
89
{
98
- ScopedStackLock lock;
99
-
100
- chip::Tracing::Perfetto::FlushEventTrackingStorage ();
101
- gPerfettoFileOutput . Close ( );
102
- chip::Tracing::Unregister (gPerfettoBackend );
103
- chip::Tracing::Unregister ( gJsonBackend );
90
+ chip::MainLoopWork::ExecuteInMainLoop ([] {
91
+ chip::Tracing::Perfetto::FlushEventTrackingStorage ();
92
+ gPerfettoFileOutput . Close ();
93
+ chip::Tracing::Unregister ( gPerfettoBackend );
94
+ chip::Tracing::Unregister (gJsonBackend );
95
+ } );
104
96
}
0 commit comments