piiswrong commented on a change in pull request #8972: Profiling enhancements, 
python API, vtune and chrome tracing objects, etc.
URL: https://github.com/apache/incubator-mxnet/pull/8972#discussion_r155958933
 
 

 ##########
 File path: python/mxnet/profiler.py
 ##########
 @@ -56,3 +69,237 @@ def dump_profile():
     """Dump profile and stop profiler. Use this to save profile
     in advance in case your program cannot exit normally."""
     check_call(_LIB.MXDumpProfile())
+
+def create_domain(name):
+  domain_handle = ProfileDomainHandle()
+  check_call(_LIB.MXProfileCreateDomain(c_str(name), 
ctypes.byref(domain_handle)))
+  return domain_handle
+
+def create_task(domain_handle, name):
+    task_handle = ProfileTaskHandle()
+    check_call(_LIB.MXProfileCreateTask(domain_handle,
+                                        c_str(name),
+                                        ctypes.byref(task_handle)))
+    return task_handle
+
+def destroy_task(task_handle):
+    check_call(_LIB.MXProfileDestroyTask(task_handle))
+
+def task_start(task_handle):
+    check_call(_LIB.MXProfileTaskStart(task_handle))
+
+def task_stop(task_handle):
+    check_call(_LIB.MXProfileTaskStop(task_handle))
+
+def create_frame(domain_handle, name):
+    frame_handle = ProfileFrameHandle()
+    check_call(_LIB.MXProfileCreateFrame(domain_handle,
+                                        c_str(name),
+                                        ctypes.byref(frame_handle)))
+    return frame_handle
+
+def destroy_frame(frame_handle):
+    check_call(_LIB.MXProfileDestroyFrame(frame_handle))
+
+def frame_start(frame_handle):
+    check_call(_LIB.MXProfileFrameStart(frame_handle))
+
+def frame_stop(frame_handle):
+    check_call(_LIB.MXProfileFrameStop(frame_handle))
+
+def create_event(name):
+    event_handle = ProfileEventHandle()
+    check_call(_LIB.MXProfileCreateEvent(c_str(name), 
ctypes.byref(event_handle)))
+    return event_handle
+
+def destroy_event(event_handle):
+    check_call(_LIB.MXProfileDestroyEvent(event_handle))
+
+def event_start(event_handle):
+    check_call(_LIB.MXProfileEventStart(event_handle))
+
+def event_stop(event_handle):
+    check_call(_LIB.MXProfileEventStop(event_handle))
+
+def tune_pause():
+    check_call(_LIB.MXProfileTunePause())
+
+def tune_resume():
+    check_call(_LIB.MXProfileTuneResume())
+
+def create_counter(domain_handle, name, value=None):
+    counter_handle = ProfileCounterHandle()
+    check_call(_LIB.MXProfileCreateCounter(domain_handle,
+                                           c_str(name),
+                                           ctypes.byref(counter_handle)))
+    if value is not None:
+        set_counter(counter_handle, value)
+    return counter_handle
+
+def destroy_counter(counter_handle):
+    check_call(_LIB.MXProfileDestroyCounter(counter_handle))
+
+def set_counter(counter_handle, value):
+    check_call(_LIB.MXProfileSetCounter(counter_handle, int(value)))
+
+def increment_counter(counter_handle, by_value):
+    check_call(_LIB.MXProfileAdjustCounter(counter_handle, int(by_value)))
+
+def decrement_counter(counter_handle, by_value):
+    check_call(_LIB.MXProfileAdjustCounter(counter_handle, -int(by_value)))
+
+def set_append_mode(mode):
+  if mode is False:
+    mode = 0
+  else:
+    mode = 1
+  check_call(_LIB.MXSetDumpProfileAppendMode(int(mode)))
+
+def set_continuous_dump(continuous_dump=True, delay_in_seconds=1.0):
+  if continuous_dump is False:
+    cd = 0
+  else:
+    cd = 1
+  ds = float(delay_in_seconds)
+  check_call(_LIB.MXSetContinuousProfileDump(ctypes.c_int(cd), 
ctypes.c_float(ds)))
+
+def set_instant_marker(domain_handle, name, scope='process'):
+    marker_scope2int = { 'global': 1, 'process': 2, 'thread': 3, 'task': 4, 
'marker': 5 }
+    scope_int = marker_scope2int[scope]
+    check_call(_LIB.MXProfileSetInstantMarker(domain_handle, c_str(name), 
scope_int))
+
+
+class Domain:
+    """Profiling domain, used to group sub-objects like tasks, counters, etc 
into categories
+    Serves as part of 'categories' for chrome://tracing
+    Note: Domain handles are never destroyed
+    """
+    def __init__(self, name):
+        self.name = name
+        self.handle = create_domain(name)
+
+    def __str__(self):
+        return self.name
+
+
+class Task:
+    """Profiling Task class
+    A task is a logical unit of work performed by a particular thread.
+    Tasks can nest; thus, tasks typically correspond to functions, scopes, or 
a case block
+    in a switch statement.
+    You can use the Task API to assign tasks to threads
+    """
+    def __init__(self, domain, name):
+        self.domain = domain
+        self.name = name
+        self.handle = create_task(domain.handle, name)
+
+    def start(self):
+        task_start(self.handle)
+
+    def stop(self):
+        task_stop(self.handle)
+
+    def __str__(self):
+        return self.name
+
+    def __del__(self):
+        if self.handle is not None:
+            destroy_task(self.handle)
+
+
+class Frame:
+    """Profiling Frame class
+    Use the frame API to insert calls to the desired places in your code and 
analyze
+    performance per frame, where frame is the time period between frame begin 
and end points.
 
 Review comment:
   Btw why do we expose this to the front end?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to