Skip to content

Commit

Permalink
Things run now
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin authored and andy31415 committed Jul 22, 2023
1 parent a0cd454 commit 1027304
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
27 changes: 24 additions & 3 deletions src/controller/python/chip/tracing/TracingSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <controller/python/chip/native/PyChipError.h>
#include <platform/PlatformManager.h>

#include <tracing/json/json_tracing.h>
#include <tracing/perfetto/event_storage.h>
Expand All @@ -27,6 +28,16 @@

namespace {

using chip::DeviceLayer::PlatformMgr;

class ScopedStackLock
{
public:
ScopedStackLock() { PlatformMgr().LockChipStack(); }

~ScopedStackLock() { PlatformMgr().UnlockChipStack(); }
};

::chip::Tracing::Json::JsonBackend mJsonBackend;

chip::Tracing::Perfetto::FileTraceOutput mPerfettoFileOutput;
Expand All @@ -35,13 +46,17 @@ chip::Tracing::Perfetto::PerfettoBackend mPerfettoBackend;
} // namespace

extern "C" void pychip_tracing_start_json_log(const char * file_name)
{
mJsonBackend.CloseFile(); // just in case, ensure no file output
chip::Tracing::Register(mJsonBackend);

ScopedStackLock lock;

mJsonBackend.CloseFile(); // just in case, ensure no file output
chip::Tracing::Register(mJsonBackend);
}

extern "C" PyChipError pychip_tracing_start_json_file(const char * file_name)
{
ScopedStackLock lock;

CHIP_ERROR err = mJsonBackend.OpenFile(file_name);
if (err != CHIP_NO_ERROR)
{
Expand All @@ -53,13 +68,17 @@ extern "C" PyChipError pychip_tracing_start_json_file(const char * file_name)

extern "C" void pychip_tracing_start_perfetto_system()
{
ScopedStackLock lock;

chip::Tracing::Perfetto::Initialize(perfetto::kSystemBackend);
chip::Tracing::Perfetto::RegisterEventTrackingStorage();
chip::Tracing::Register(mPerfettoBackend);
}

extern "C" PyChipError pychip_tracing_start_perfetto_file(const char * file_name)
{
ScopedStackLock lock;

chip::Tracing::Perfetto::Initialize(perfetto::kInProcessBackend);
chip::Tracing::Perfetto::RegisterEventTrackingStorage();

Expand All @@ -75,6 +94,8 @@ extern "C" PyChipError pychip_tracing_start_perfetto_file(const char * file_name

extern "C" void pychip_tracing_stop()
{
ScopedStackLock lock;

chip::Tracing::Perfetto::FlushEventTrackingStorage();
mPerfettoFileOutput.Close();
chip::Tracing::Unregister(mPerfettoBackend);
Expand Down
4 changes: 2 additions & 2 deletions src/controller/python/chip/tracing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#

import ctypes
from enum import Enum
from enum import Enum, auto
from typing import Optional

import chip.native
Expand Down Expand Up @@ -117,7 +117,7 @@ def __init__(self):
pass

def __enter__(self):
pass
return self

def __exit__(self, type, value, traceback):
StopTracing()

0 comments on commit 1027304

Please sign in to comment.