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_r164209999
 
 

 ##########
 File path: python/mxnet/profiler.py
 ##########
 @@ -54,5 +60,280 @@ def profiler_set_state(state='stop'):
 
 def dump_profile():
     """Dump profile and stop profiler. Use this to save profile
-    in advance in case your program cannot exit normally."""
+    in advance in case your program cannot exit normally.
+    """
     check_call(_LIB.MXDumpProfile())
+
+def dump_aggregate_stats(reset=False):
+    """Dump profile aggregate stats to console.
+    """
+    do_reset = 1 if reset is True else 0
+    check_call(_LIB.MXDumpAggregateProfileStats(int(do_reset)))
+
+def profiler_pause():
+    check_call(_LIB.MXProfilePause(int(1)))
+
+def profiler_resume():
+    check_call(_LIB.MXProfilePause(int(0)))
+
+class Domain(object):
+    """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):
+        """Profiling Domain class constructor
+            Parameters
+            ----------
+            name : string
+                Name of the domain
+        """
+        self.name = name
+        self.handle = ProfileHandle()
+        check_call(_LIB.MXProfileCreateDomain(c_str(self.name), 
ctypes.byref(self.handle)))
+
+    def __str__(self):
+        return self.name
+
+    def new_task(self, name):
+        """Create new Task object owned by this domain
+            Parameters
+            ----------
+            name : string
+                Name of the task
+        """
+        return Task(self, name)
+
+    def new_frame(self, name):
+        """Create new Frame object owned by this domain
+            Parameters
+            ----------
+            name : string
+                Name of the frame
+        """
+        return Frame(self, name)
+
+    def new_counter(self, name, value=None):
+        """Create new Counter object owned by this domain
+            Parameters
+            ----------
+            name : string
+                Name of the counter
+        """
+        return Counter(self, name, value)
+
+    def new_marker(self, name):
+        """Create new Marker object owned by this domain
+            Parameters
+            ----------
+            name : string
+                Name of the marker
+        """
+        return Marker(self, name)
+
+class Task(object):
+    """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):
+        """Profiling Task class constructor.
+            Parameters
+            ----------
+            domain : Domain object
+                Domain to which this object belongs
+            name : string
+                Name of the task
+        """
+        self.name = name
+        self.handle = ProfileHandle()
+        check_call(_LIB.MXProfileCreateTask(domain.handle,
+                                            c_str(self.name),
+                                            ctypes.byref(self.handle)))
+
+    def __del__(self):
+        if self.handle is not None:
+            check_call(_LIB.MXProfileDestroyHandle(self.handle))
+
+    def start(self):
+        """Start timing scope for this object"""
+        check_call(_LIB.MXProfileDurationStart(self.handle))
+
+    def stop(self):
+        """Stop timing scope for this object"""
+        check_call(_LIB.MXProfileDurationStop(self.handle))
+
+    def __str__(self):
+        return self.name
+
+
+class Frame(object):
+    """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.
+    When frames are displayed in Intel VTune Amplifier, they are displayed in a
+    separate track, so they provide a way to visually separate this data from 
normal task data.
+    """
+    def __init__(self, domain, name):
+        """Profiling Frame class constructor
+            Parameters
+            ----------
+            domain : Domain object
+                Domain to which this object belongs
+            name : string
+                Name of the frame
+        """
+        self.name = name
+        self.handle = ProfileHandle()
+        check_call(_LIB.MXProfileCreateFrame(domain.handle,
+                                             c_str(self.name),
+                                             ctypes.byref(self.handle)))
+
+    def __del__(self):
+        if self.handle is not None:
+            check_call(_LIB.MXProfileDestroyHandle(self.handle))
+
+    def start(self):
+        """Start timing scope for this object"""
+        check_call(_LIB.MXProfileDurationStart(self.handle))
+
+    def stop(self):
+        """Stop timing scope for this object"""
+        check_call(_LIB.MXProfileDurationStop(self.handle))
+
+    def __str__(self):
+        return self.name
+
+
+class Event(object):
+    """Profiling Event class
+    The event API is used to observe when demarcated events occur in your 
application, or to
+    identify how long it takes to execute demarcated regions of code. Set 
annotations in the
+    application to demarcate areas where events of interest occur.
+    After running analysis, you can see the events marked in the Timeline pane.
+    Event API is a per-thread function that works in resumed state.
+    This function does not work in paused state.
+    """
+    def __init__(self, name):
+        """Profiling Event class constructor
+            Parameters
+            ----------
+            name : string
+                Name of the event
+        """
+        self.name = name
+        self.handle = ProfileHandle()
+        check_call(_LIB.MXProfileCreateEvent(c_str(self.name), 
ctypes.byref(self.handle)))
+
+    def __del__(self):
+        if self.handle is not None:
+            check_call(_LIB.MXProfileDestroyHandle(self.handle))
+
+    def start(self):
+        """Start timing scope for this object"""
+        check_call(_LIB.MXProfileDurationStart(self.handle))
+
+    def stop(self):
+        """Stop timing scope for this object"""
+        check_call(_LIB.MXProfileDurationStop(self.handle))
+
+    def __str__(self):
+        return self.name
+
+
+class Counter(object):
+    """Profiling Counter class
+    The counter event can track a value as it changes over time.
+    """
+    def __init__(self, domain, name, value=None):
+        """Profiling Counter class constructor.
+        The counter event can track a value as it changes over time.
+            Parameters
+            ----------
+            domain : Domain object
+                Domain to which this object belongs
+            name : string
+                Name of the counter
+            value: integer, optional
+                Initial value of the counter
+        """
+        self.name = name
+        self.handle = ProfileHandle()
+        check_call(_LIB.MXProfileCreateCounter(domain.handle,
+                                               c_str(name),
+                                               ctypes.byref(self.handle)))
+        if value is not None:
+            self.set_value(value)
+
+    def __del__(self):
+        if self.handle is not None:
+            check_call(_LIB.MXProfileDestroyHandle(self.handle))
+
+
+    def set_value(self, value):
+        """Set counter value.
+            Parameters
+            ----------
+            value : int
+                Value for the counter
+        """
+        check_call(_LIB.MXProfileSetCounter(self.handle, int(value)))
+
+    def increment(self, value_change):
+        """Increment counter value.
+            Parameters
+            ----------
+            value_change : int
+                Amount by which to add to the counter
+        """
+        check_call(_LIB.MXProfileAdjustCounter(self.handle, int(value_change)))
+
+    def decrement(self, value_change):
 
 Review comment:
   same as increment

----------------------------------------------------------------
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