[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-21 Thread GitBox
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_r169731765
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -52,7 +58,298 @@ def profiler_set_state(state='stop'):
 state2int = {'stop': 0, 'run': 1}
 check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))
 
-def dump_profile():
+def dump(finished=True):
 """Dump profile and stop profiler. Use this to save profile
-in advance in case your program cannot exit normally."""
-check_call(_LIB.MXDumpProfile())
+in advance in case your program cannot exit normally.
+
+Parameters
+--
+finished : boolean
+Indicates whether to stop statistical output (dumping) after this dump.
+Default is True
+"""
+fin = 1 if finished is True else False
+check_call(_LIB.MXDumpProfile(fin))
+
+def aggregate_stats_str(reset=False):
 
 Review comment:
   This should be a verb. I still like dumps better.


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168574121
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -52,7 +58,298 @@ def profiler_set_state(state='stop'):
 state2int = {'stop': 0, 'run': 1}
 check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))
 
-def dump_profile():
 
 Review comment:
   same


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168654795
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -52,7 +58,298 @@ def profiler_set_state(state='stop'):
 state2int = {'stop': 0, 'run': 1}
 check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))
 
-def dump_profile():
+def dump(finished=True):
 """Dump profile and stop profiler. Use this to save profile
-in advance in case your program cannot exit normally."""
-check_call(_LIB.MXDumpProfile())
+in advance in case your program cannot exit normally.
+
+Parameters
+--
+finished : boolean
+Indicates whether to stop statistical output (dumping) after this dump.
+Default is True
+"""
+fin = 1 if finished is True else False
+check_call(_LIB.MXDumpProfile(fin))
+
+def aggregate_stats_str(reset=False):
+"""Return a printable string of aggregate profile stats.
+Parameters
+--
+reset: boolean
+Indicates whether to clean aggeregate statistical data collected up to 
this point
+"""
+debug_str = ctypes.c_char_p()
+do_reset = 1 if reset is True else 0
+check_call(_LIB.MXAggregateProfileStatsPrint(ctypes.byref(debug_str), 
int(do_reset)))
+return py_str(debug_str.value)
+
+def pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def 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.
+This is different from Task 

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168574260
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -20,28 +20,34 @@
 # pylint: disable=too-many-branches, too-many-statements
 """Profiler setting methods."""
 from __future__ import absolute_import
-
 import ctypes
-from .base import _LIB, check_call, c_str
+from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array, py_str
 
-def profiler_set_config(mode='symbolic', filename='profile.json'):
+def set_config(kwargs):
 """Set up the configure of profiler.
 
 Parameters
 --
-mode : string, optional
-Indicates whether to enable the profiler, can
-be 'symbolic', or 'all'. Defaults to `symbolic`.
-filename : string, optional
-The name of output trace file. Defaults to 'profile.json'.
+kwargs : list of key/value pair tuples
+Indicates configuration parameters
+  profile_all : boolean, all profile types enabled
+  profile_symbolic : boolean, whether to profile symbolic operators
+  profile_imperative : boolean, whether to profile imperative operators
+  profile_memory : boolean, whether to profile memory usage
+  profile_api : boolean, whether to profile the C API
+  filename : string, output file for profile data
+  contiguous_dump : boolean, whether to periodically dump profiling 
data to file
+  dump_period : float, seconds between profile data dumps
+  aggregate_stats : boolean, whether to maintain aggregate stats in 
memory for console
+dump.  Has some negative performance impact.
 """
-mode2int = {'symbolic': 0, 'all': 1}
-check_call(_LIB.MXSetProfilerConfig(
-ctypes.c_int(mode2int[mode]),
-c_str(filename)))
+check_call(_LIB.MXSetProfilerConfig(len(kwargs),
+c_str_array([key for key, _ in 
kwargs]),
+c_str_array([str(val) for _, val in 
kwargs])))
+
 
-def profiler_set_state(state='stop'):
 
 Review comment:
   same


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168574446
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -52,7 +58,298 @@ def profiler_set_state(state='stop'):
 state2int = {'stop': 0, 'run': 1}
 check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))
 
-def dump_profile():
+def dump(finished=True):
 """Dump profile and stop profiler. Use this to save profile
-in advance in case your program cannot exit normally."""
-check_call(_LIB.MXDumpProfile())
+in advance in case your program cannot exit normally.
+
+Parameters
+--
+finished : boolean
+Indicates whether to stop statistical output (dumping) after this dump.
+Default is True
+"""
+fin = 1 if finished is True else False
+check_call(_LIB.MXDumpProfile(fin))
+
+def aggregate_stats_str(reset=False):
 
 Review comment:
   name is too verbose.
   How about print or dumps?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168574202
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -52,7 +58,298 @@ def profiler_set_state(state='stop'):
 state2int = {'stop': 0, 'run': 1}
 check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))
 
-def dump_profile():
+def dump(finished=True):
 """Dump profile and stop profiler. Use this to save profile
-in advance in case your program cannot exit normally."""
-check_call(_LIB.MXDumpProfile())
+in advance in case your program cannot exit normally.
+
+Parameters
+--
+finished : boolean
+Indicates whether to stop statistical output (dumping) after this dump.
 
 Review comment:
   statistical?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168655942
 
 

 ##
 File path: src/profiler/storage_profiler.h
 ##
 @@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef MXNET_PROFILER_STORAGE_PROFILER_H_
+#define MXNET_PROFILER_STORAGE_PROFILER_H_
+
+#include 
+#include 
+#include 
+#include "./profiler.h"
+
+namespace mxnet {
+namespace storage {
+
+#if MXNET_USE_PROFILER
 
 Review comment:
   Note for future reference: we should consider removing this macro and always 
compile profiler if it doesn't introduce overhead when profiler is off.
   
   One possibility of overhead even when profiler is off might comes from 
PROFILER_MESSAGE strings.


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168655033
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -52,7 +58,298 @@ def profiler_set_state(state='stop'):
 state2int = {'stop': 0, 'run': 1}
 check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))
 
-def dump_profile():
+def dump(finished=True):
 """Dump profile and stop profiler. Use this to save profile
-in advance in case your program cannot exit normally."""
-check_call(_LIB.MXDumpProfile())
+in advance in case your program cannot exit normally.
+
+Parameters
+--
+finished : boolean
+Indicates whether to stop statistical output (dumping) after this dump.
+Default is True
+"""
+fin = 1 if finished is True else False
+check_call(_LIB.MXDumpProfile(fin))
+
+def aggregate_stats_str(reset=False):
+"""Return a printable string of aggregate profile stats.
+Parameters
+--
+reset: boolean
+Indicates whether to clean aggeregate statistical data collected up to 
this point
+"""
+debug_str = ctypes.c_char_p()
+do_reset = 1 if reset is True else 0
+check_call(_LIB.MXAggregateProfileStatsPrint(ctypes.byref(debug_str), 
int(do_reset)))
+return py_str(debug_str.value)
+
+def pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def 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.
+This is different from Task 

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168654314
 
 

 ##
 File path: include/mxnet/c_api.h
 ##
 @@ -227,10 +231,133 @@ MXNET_DLL int MXSetProfilerConfig(int mode, const char* 
filename);
  */
 MXNET_DLL int MXSetProfilerState(int state);
 
-/*! \brief Save profile and stop profiler */
-MXNET_DLL int MXDumpProfile();
+/*!
+ * \brief Save profile and stop profiler
+ * \param finished true if stat output should stop after this point
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXDumpProfile(int finished);
+
+
+/*!
+ * \brief Print aggregate stats to the a string
+ * \param out_str Will receive a pointer to the output string
+ * \param reset Clear the aggregate stats after printing
+ * \return 0 when success, -1 when failure happens.
+ * \note
+ */
+MXNET_DLL int MXAggregateProfileStatsPrint(const char **out_str, int reset);
+
+/*!
+ * \brief Pause profiler tuning collection
+ * \param paused If nonzero, profiling pauses. Otherwise, profiling 
resumes/continues
+ * \return 0 when success, -1 when failure happens.
+ * \note pausing and resuming is global and not recursive
+ */
+MXNET_DLL int MXProfilePause(int paused);
 
 Review comment:
   Why not merge this with SetProfileState?
   
   


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168654895
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -52,7 +58,298 @@ def profiler_set_state(state='stop'):
 state2int = {'stop': 0, 'run': 1}
 check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))
 
-def dump_profile():
+def dump(finished=True):
 """Dump profile and stop profiler. Use this to save profile
-in advance in case your program cannot exit normally."""
-check_call(_LIB.MXDumpProfile())
+in advance in case your program cannot exit normally.
+
+Parameters
+--
+finished : boolean
+Indicates whether to stop statistical output (dumping) after this dump.
+Default is True
+"""
+fin = 1 if finished is True else False
+check_call(_LIB.MXDumpProfile(fin))
+
+def aggregate_stats_str(reset=False):
+"""Return a printable string of aggregate profile stats.
+Parameters
+--
+reset: boolean
+Indicates whether to clean aggeregate statistical data collected up to 
this point
+"""
+debug_str = ctypes.c_char_p()
+do_reset = 1 if reset is True else 0
+check_call(_LIB.MXAggregateProfileStatsPrint(ctypes.byref(debug_str), 
int(do_reset)))
+return py_str(debug_str.value)
+
+def pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def 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.
 
 Review comment:
   also explain task/frame difference here


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168574049
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -20,28 +20,34 @@
 # pylint: disable=too-many-branches, too-many-statements
 """Profiler setting methods."""
 from __future__ import absolute_import
-
 import ctypes
-from .base import _LIB, check_call, c_str
+from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array, py_str
 
-def profiler_set_config(mode='symbolic', filename='profile.json'):
 
 Review comment:
   Keep these profiler* APIs as backward compatible layer.
   They should print a deprecation warning message with warnings.warn


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168573664
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -20,28 +20,34 @@
 # pylint: disable=too-many-branches, too-many-statements
 """Profiler setting methods."""
 from __future__ import absolute_import
-
 import ctypes
-from .base import _LIB, check_call, c_str
+from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array, py_str
 
-def profiler_set_config(mode='symbolic', filename='profile.json'):
+def set_config(kwargs):
 
 Review comment:
   `**kwargs`


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168573446
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -52,7 +58,298 @@ def profiler_set_state(state='stop'):
 state2int = {'stop': 0, 'run': 1}
 check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))
 
-def dump_profile():
+def dump(finished=True):
 """Dump profile and stop profiler. Use this to save profile
-in advance in case your program cannot exit normally."""
-check_call(_LIB.MXDumpProfile())
+in advance in case your program cannot exit normally.
+
+Parameters
+--
+finished : boolean
+Indicates whether to stop statistical output (dumping) after this dump.
+Default is True
+"""
+fin = 1 if finished is True else False
+check_call(_LIB.MXDumpProfile(fin))
+
+def aggregate_stats_str(reset=False):
+"""Return a printable string of aggregate profile stats.
+Parameters
+--
+reset: boolean
+Indicates whether to clean aggeregate statistical data collected up to 
this point
+"""
+debug_str = ctypes.c_char_p()
+do_reset = 1 if reset is True else 0
+check_call(_LIB.MXAggregateProfileStatsPrint(ctypes.byref(debug_str), 
int(do_reset)))
+return py_str(debug_str.value)
+
+def pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def 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
 
 Review comment:
   I don't know if this would work. AFAIK most other APIs put this in the class 
docstring


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168573339
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -52,7 +58,298 @@ def profiler_set_state(state='stop'):
 state2int = {'stop': 0, 'run': 1}
 check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))
 
-def dump_profile():
+def dump(finished=True):
 """Dump profile and stop profiler. Use this to save profile
-in advance in case your program cannot exit normally."""
-check_call(_LIB.MXDumpProfile())
+in advance in case your program cannot exit normally.
+
+Parameters
+--
+finished : boolean
+Indicates whether to stop statistical output (dumping) after this dump.
+Default is True
+"""
+fin = 1 if finished is True else False
+check_call(_LIB.MXDumpProfile(fin))
+
+def aggregate_stats_str(reset=False):
+"""Return a printable string of aggregate profile stats.
+Parameters
+--
+reset: boolean
+Indicates whether to clean aggeregate statistical data collected up to 
this point
+"""
+debug_str = ctypes.c_char_p()
+do_reset = 1 if reset is True else 0
+check_call(_LIB.MXAggregateProfileStatsPrint(ctypes.byref(debug_str), 
int(do_reset)))
+return py_str(debug_str.value)
+
+def pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def 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.
 
 Review comment:
   I don't know if this would work. AFAIK most other APIs do this in the class 
docstring


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-02-15 Thread GitBox
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_r168573339
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -52,7 +58,298 @@ def profiler_set_state(state='stop'):
 state2int = {'stop': 0, 'run': 1}
 check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))
 
-def dump_profile():
+def dump(finished=True):
 """Dump profile and stop profiler. Use this to save profile
-in advance in case your program cannot exit normally."""
-check_call(_LIB.MXDumpProfile())
+in advance in case your program cannot exit normally.
+
+Parameters
+--
+finished : boolean
+Indicates whether to stop statistical output (dumping) after this dump.
+Default is True
+"""
+fin = 1 if finished is True else False
+check_call(_LIB.MXDumpProfile(fin))
+
+def aggregate_stats_str(reset=False):
+"""Return a printable string of aggregate profile stats.
+Parameters
+--
+reset: boolean
+Indicates whether to clean aggeregate statistical data collected up to 
this point
+"""
+debug_str = ctypes.c_char_p()
+do_reset = 1 if reset is True else 0
+check_call(_LIB.MXAggregateProfileStatsPrint(ctypes.byref(debug_str), 
int(do_reset)))
+return py_str(debug_str.value)
+
+def pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def 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.
 
 Review comment:
   I don't know if this would work. AFAIK most other APIs do this in the class 
docstring


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164212223
 
 

 ##
 File path: src/engine/thread_pool.h
 ##
 @@ -39,40 +40,17 @@ namespace engine {
  */
 class ThreadPool {
  public:
-  /*! \brief Simple manually-signalled event gate which remains open */
-  class SimpleEvent {
-   public:
-SimpleEvent()
-  : signaled_(false) {}
-void wait() {
-  std::unique_lock lock(mutex_);
-  if (!signaled_) {
-condition_variable_.wait(lock);
-  }
-}
-void signal() {
-  signaled_ = true;
-  std::unique_lock lk(mutex_);
-  condition_variable_.notify_all();
+  /*! \brief Signal event upon destruction, even for exceptions (RAII) */
+  struct SetReadyOnDestroy {
+explicit inline SetReadyOnDestroy(std::shared_ptr 
*event)
+  : event_(*event) {
 }
-
-/*! \brief Signal event upon destruction, even for exceptions (RAII) */
-struct SetReadyOnDestroy {
-  explicit inline SetReadyOnDestroy(std::shared_ptr *event)
-: event_(*event) {
+inline ~SetReadyOnDestroy() {
+  if (event_) {
+event_->signal();
   }
-  inline ~SetReadyOnDestroy() {
-if (event_) {
-  event_->signal();
-}
-  }
-  std::shared_ptr  event_;
-};
-
-   private:
-std::mutex  mutex_;
-std::condition_variable condition_variable_;
-std::atomic   signaled_;
+}
+std::shared_ptr  event_;
 
 Review comment:
   does unique_ptr work?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164212160
 
 

 ##
 File path: src/engine/thread_pool.h
 ##
 @@ -39,40 +40,17 @@ namespace engine {
  */
 class ThreadPool {
  public:
-  /*! \brief Simple manually-signalled event gate which remains open */
-  class SimpleEvent {
-   public:
-SimpleEvent()
-  : signaled_(false) {}
-void wait() {
-  std::unique_lock lock(mutex_);
-  if (!signaled_) {
-condition_variable_.wait(lock);
-  }
-}
-void signal() {
-  signaled_ = true;
-  std::unique_lock lk(mutex_);
-  condition_variable_.notify_all();
+  /*! \brief Signal event upon destruction, even for exceptions (RAII) */
+  struct SetReadyOnDestroy {
+explicit inline SetReadyOnDestroy(std::shared_ptr 
*event)
+  : event_(*event) {
 }
-
-/*! \brief Signal event upon destruction, even for exceptions (RAII) */
-struct SetReadyOnDestroy {
-  explicit inline SetReadyOnDestroy(std::shared_ptr *event)
-: event_(*event) {
+inline ~SetReadyOnDestroy() {
+  if (event_) {
+event_->signal();
   }
-  inline ~SetReadyOnDestroy() {
-if (event_) {
-  event_->signal();
-}
-  }
-  std::shared_ptr  event_;
-};
-
-   private:
-std::mutex  mutex_;
-std::condition_variable condition_variable_;
-std::atomic   signaled_;
+}
+std::shared_ptr  event_;
 
 Review comment:
   doesn't it have to be shared_ptr?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164211586
 
 

 ##
 File path: src/c_api/c_api_profile.cc
 ##
 @@ -0,0 +1,586 @@
+//
+// Created by coolivie on 11/25/17.
+//
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ *  Copyright (c) 2017 by Contributors
+ * \file c_api_profile.cc
+ * \brief C API of mxnet profiler and support functions
+ */
+#include 
+#include 
+#include 
+#include 
+#include "./c_api_common.h"
+#include "../profiler/profiler.h"
+
+namespace mxnet {
+
+// #define PROFILE_API_INCLUDE_AS_EVENT
+
+#if MXNET_USE_PROFILER
+static profiler::ProfileDomain api_domain("MXNET_C_API");
+static profiler::ProfileCounter api_call_counter("MXNet C API Calls", 
_domain);
+static profiler::ProfileCounter api_concurrency_counter("MXNet C API 
Concurrency",
+_domain);
+
+/*! \brief Per-API-call timing data */
+struct APICallTimingData {
+  const char *name_;
+  profiler::ProfileTask *task_;
+#ifdef PROFILE_API_INCLUDE_AS_EVENT
+  profiler::ProfileEvent *event_;
+#endif  // PROFILE_API_INCLUDE_AS_EVENT
+};
+
+template
+inline std::unique_ptr make_unique(Args&&... args) {
+  return std::unique_ptr(new T(std::forward(args)...));
+}
+
+/*!
+ * \brief Per-thread profiling data
+ */
+class ProfilingThreadData {
+ public:
+  /*!
+   * \brief Constructor, nothrow
+   */
+  inline ProfilingThreadData() noexcept {}
+
+  /*!
+   * \brief Retreive ProfileTask object of the given name, or create if it 
doesn't exist
+   * \param name Name of the task
+   * \param domain Domain of the task
+   * \return Pointer to the stored or created ProfileTask object
+   */
+  profiler::ProfileTask *profile_task(const char *name, 
profiler::ProfileDomain *domain) {
+// Per-thread so no lock necessary
+auto iter = tasks_.find(name);
+if (iter == tasks_.end()) {
+  iter = tasks_.emplace(std::make_pair(
+name, make_unique(name, domain))).first;
+}
+return iter->second.get();
+  }
+
+#ifdef PROFILE_API_INCLUDE_AS_EVENT
+  /*!
+   * \brief Retreive ProfileEvent object of the given name, or create if it 
doesn't exist
+   * \param name Name of the event
+   * \return Pointer to the stored or created ProfileEvent object
+   */
+  profiler::ProfileEvent *profile_event(const char *name) {
+// Per-thread so no lock necessary
+auto iter = events_.find(name);
+if (iter == events_.end()) {
+  iter = events_.emplace(std::make_pair(name, 
make_unique(name))).first;
+}
+return iter->second.get();
+  }
+#endif  // PROFILE_API_INCLUDE_AS_EVENT
+
+  /*! \brief nestable call stack */
+  std::stack calls_;
+  /*! \brief Whether profiling actions should be ignored/excluded */
+  volatile bool ignore_call_ = false;  // same-thread only, so not atomic
+
+ private:
+  /*! \brief tasks */
+  std::unordered_map 
tasks_;
+#ifdef PROFILE_API_INCLUDE_AS_EVENT
+  /*! \brief events */
+  std::unordered_map 
events_;
+#endif  // PROFILE_API_INCLUDE_AS_EVENT
+};
+
+static thread_local ProfilingThreadData thread_profiling_data;
+#endif  // MXNET_USE_PROFILER
+
+extern void on_enter_api(const char *function) {
 
 Review comment:
   put this in header as inline function?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164211317
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -20,28 +20,34 @@
 # pylint: disable=too-many-branches, too-many-statements
 """Profiler setting methods."""
 from __future__ import absolute_import
-
 import ctypes
-from .base import _LIB, check_call, c_str
+from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array
 
-def profiler_set_config(mode='symbolic', filename='profile.json'):
+def profiler_set_config(flags):
 """Set up the configure of profiler.
 
 Parameters
 --
-mode : string, optional
-Indicates whether to enable the profiler, can
-be 'symbolic', or 'all'. Defaults to `symbolic`.
-filename : string, optional
-The name of output trace file. Defaults to 'profile.json'.
+flags : list of key/value pair tuples
+Indicates configuration parameters
+  profile_all : boolean, all profile types enabled
 
 Review comment:
   mode='all|symbolic|imperative|api|memory' to keep backward compatibility?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r16420
 
 

 ##
 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:
+

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164209974
 
 

 ##
 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:
+

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164209658
 
 

 ##
 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.
 
 Review comment:
   add a note explaining the differences with task


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164209612
 
 

 ##
 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.
 
 Review comment:
   1. Add standard Parameter section.
   2. Add a note explaining the difference with Frame.


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164209441
 
 

 ##
 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():
 
 Review comment:
   remove `profiler_`. Its superfluous given mx.profiler.
   
   We might also want to alias the existing apis to remove `profiler_`


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164209124
 
 

 ##
 File path: include/mxnet/c_api.h
 ##
 @@ -227,10 +228,131 @@ MXNET_DLL int MXSetProfilerConfig(int mode, const char* 
filename);
  */
 MXNET_DLL int MXSetProfilerState(int state);
 
-/*! \brief Save profile and stop profiler */
+/*!
+ * \brief Save profile and stop profiler
+ * \param append true if appending to current profile file, false for truncate
+ * \return
+ */
 MXNET_DLL int MXDumpProfile();
 
-/*! \brief Set the number of OMP threads to use */
+/*!
+ * \brief Set whether to continuously write the profiling data to a file
+ * \param continuous_dump true to continuously write profiling data to a file
+ * \param delay_in_seconds Number of seconds (or fraction of seconds) to delay 
between writes
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXSetContinuousProfileDump(int continuous_dump, float 
delay_in_seconds);
+
+/*!
+ * \brief Pause profiler tuning collection
+ * \param paused If nonzero, profiling pauses. Otherwise, profiling 
resumes/continues
+ * \return 0 when success, -1 when failure happens.
+ * \note pausing and resuming is global and not recursive
+ */
+MXNET_DLL int MXProfilePause(int paused);
 
 Review comment:
   Why not merge this with SetProfileState?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164208353
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -20,28 +20,34 @@
 # pylint: disable=too-many-branches, too-many-statements
 """Profiler setting methods."""
 from __future__ import absolute_import
-
 import ctypes
-from .base import _LIB, check_call, c_str
+from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array
 
-def profiler_set_config(mode='symbolic', filename='profile.json'):
+def profiler_set_config(flags):
 """Set up the configure of profiler.
 
 Parameters
 --
-mode : string, optional
-Indicates whether to enable the profiler, can
-be 'symbolic', or 'all'. Defaults to `symbolic`.
-filename : string, optional
-The name of output trace file. Defaults to 'profile.json'.
+flags : list of key/value pair tuples
+Indicates configuration parameters
+  profile_all : boolean, all profile types enabled
+  profile_symbolic : boolean, whether to profile symbolic operators
+  profile_imperative : boolean, whether to profile imperative operators
+  profile_memory : boolean, whether to profile memory usage
+  profile_api : boolean, whether to profile the C API
+  file_name : string, output file for profile data
+  continuous_dump : boolean, whether to periodically dump profiling 
data to file
+  dump_period : float, seconds between profile data dumps
 
 Review comment:
   Merge continuous_dump and dump_period to dump_interval = xxs? use 0 as 
default


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164208067
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -20,28 +20,34 @@
 # pylint: disable=too-many-branches, too-many-statements
 """Profiler setting methods."""
 from __future__ import absolute_import
-
 import ctypes
-from .base import _LIB, check_call, c_str
+from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array
 
-def profiler_set_config(mode='symbolic', filename='profile.json'):
+def profiler_set_config(flags):
 """Set up the configure of profiler.
 
 Parameters
 --
-mode : string, optional
-Indicates whether to enable the profiler, can
-be 'symbolic', or 'all'. Defaults to `symbolic`.
-filename : string, optional
-The name of output trace file. Defaults to 'profile.json'.
+flags : list of key/value pair tuples
+Indicates configuration parameters
+  profile_all : boolean, all profile types enabled
+  profile_symbolic : boolean, whether to profile symbolic operators
+  profile_imperative : boolean, whether to profile imperative operators
+  profile_memory : boolean, whether to profile memory usage
+  profile_api : boolean, whether to profile the C API
+  file_name : string, output file for profile data
 
 Review comment:
   filename


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164208051
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -20,28 +20,34 @@
 # pylint: disable=too-many-branches, too-many-statements
 """Profiler setting methods."""
 from __future__ import absolute_import
-
 import ctypes
-from .base import _LIB, check_call, c_str
+from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array
 
-def profiler_set_config(mode='symbolic', filename='profile.json'):
+def profiler_set_config(flags):
 """Set up the configure of profiler.
 
 Parameters
 --
-mode : string, optional
-Indicates whether to enable the profiler, can
-be 'symbolic', or 'all'. Defaults to `symbolic`.
-filename : string, optional
-The name of output trace file. Defaults to 'profile.json'.
+flags : list of key/value pair tuples
+Indicates configuration parameters
+  profile_all : boolean, all profile types enabled
+  profile_symbolic : boolean, whether to profile symbolic operators
+  profile_imperative : boolean, whether to profile imperative operators
+  profile_memory : boolean, whether to profile memory usage
+  profile_api : boolean, whether to profile the C API
+  file_name : string, output file for profile data
+  continuous_dump : boolean, whether to periodically dump profiling 
data to file
 
 Review comment:
   contiguous?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164207417
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -20,28 +20,34 @@
 # pylint: disable=too-many-branches, too-many-statements
 """Profiler setting methods."""
 from __future__ import absolute_import
-
 import ctypes
-from .base import _LIB, check_call, c_str
+from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array
 
-def profiler_set_config(mode='symbolic', filename='profile.json'):
+def profiler_set_config(flags):
 
 Review comment:
   Use `**kwargs` and keep backward compatibility


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164207417
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -20,28 +20,34 @@
 # pylint: disable=too-many-branches, too-many-statements
 """Profiler setting methods."""
 from __future__ import absolute_import
-
 import ctypes
-from .base import _LIB, check_call, c_str
+from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array
 
-def profiler_set_config(mode='symbolic', filename='profile.json'):
+def profiler_set_config(flags):
 
 Review comment:
   `**kwargs`?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164206089
 
 

 ##
 File path: include/mxnet/c_api.h
 ##
 @@ -227,10 +231,132 @@ MXNET_DLL int MXSetProfilerConfig(int mode, const char* 
filename);
  */
 MXNET_DLL int MXSetProfilerState(int state);
 
-/*! \brief Save profile and stop profiler */
+/*!
+ * \brief Save profile and stop profiler
+ * \param append true if appending to current profile file, false for truncate
+ * \return 0 when success, -1 when failure happens.
+ */
 MXNET_DLL int MXDumpProfile();
 
-/*! \brief Set the number of OMP threads to use */
+
+/*!
+ * \brief Print aggregate stats to the console
+ * \param reset Clear the aggregate stats after printing
+ * \return 0 when success, -1 when failure happens.
+ * \note
+ */
+MXNET_DLL int MXDumpAggregateProfileStats(int reset);
 
 Review comment:
   Would it be better return as string?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-26 Thread GitBox
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_r164205553
 
 

 ##
 File path: amalgamation/amalgamation.py
 ##
 @@ -31,7 +31,7 @@
 'nvml.h', 'opencv2/opencv.hpp', 'sys/stat.h', 'sys/types.h', 'cuda.h', 
'cuda_fp16.h',
 'omp.h', 'execinfo.h', 'packet/sse-inl.h', 'emmintrin.h', 
'thrust/device_vector.h',
 'cusolverDn.h', 'internal/concurrentqueue_internal_debug.h', 
'relacy/relacy_std.hpp',
-'relacy_shims.h'
+'relacy_shims.h', 'ittnotify.h', 'shared_mutex'
 
 Review comment:
   shared_mutex is only available in c++14 right? We only require c++11


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156563575
 
 

 ##
 File path: include/mxnet/c_api.h
 ##
 @@ -227,10 +228,131 @@ MXNET_DLL int MXSetProfilerConfig(int mode, const char* 
filename);
  */
 MXNET_DLL int MXSetProfilerState(int state);
 
-/*! \brief Save profile and stop profiler */
+/*!
+ * \brief Save profile and stop profiler
+ * \param append true if appending to current profile file, false for truncate
+ * \return
+ */
 MXNET_DLL int MXDumpProfile();
 
-/*! \brief Set the number of OMP threads to use */
+/*!
+ * \brief Set whether to continuously write the profiling data to a file
+ * \param continuous_dump true to continuously write profiling data to a file
+ * \param delay_in_seconds Number of seconds (or fraction of seconds) to delay 
between writes
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXSetContinuousProfileDump(int continuous_dump, float 
delay_in_seconds);
+
+/*!
+ * \brief Pause profiler tuning collection
+ * \param paused If nonzero, profiling pauses. Otherwise, profiling 
resumes/continues
+ * \return 0 when success, -1 when failure happens.
+ * \note pausing and resuming is global and not recursive
+ */
+MXNET_DLL int MXProfilePause(int paused);
+
+/*!
+ * \brief Create profiling domain
+ * \param domain String representing the domain name to create
+ * \param out Return domain object
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileCreateDomain(const char *domain, ProfileHandle *out);
+
+/*!
+ * \brief Create profile task
+ * \param name Name of the task
+ * \param domain Domain of the task
+ * \param out Output handle
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileCreateTask(ProfileHandle domain,
+  const char *task_name,
+  ProfileHandle *out);
+
+/*!
+ * \brief Create profile frame
+ * \param name Name of the frame
+ * \param domain Domain of the frame
+ * \param out Output handle
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileCreateFrame(ProfileHandle domain,
+   const char *frame_name,
+   ProfileHandle *out);
+
+/*!
+ * \brief Create profile event
+ * \param name Name of the event
+ * \param out Output handle
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileCreateEvent(const char *event_name, ProfileHandle *out);
+
+/*!
+ * \brief Create profile counter
+ * \param name Name of the counter
+ * \param domain Domain of the counter
+ * \param out Output handle
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileCreateCounter(ProfileHandle domain,
+ const char *counter_name,
+ ProfileHandle *out);
+
+/*!
+ * \brief Destroy a frame
+ * \param frame_handle Handle to frame to destroy
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileDestroyHandle(ProfileHandle frame_handle);
+
+/*!
+ * \brief Start timing the duration of a profile duration object such as an 
event, task or frame
+ * \param duration_handle handle to the duration object
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileDurationStart(ProfileHandle duration_handle);
+
+/*!
+ * \brief Stoptiming the duration of a profile duration object such as an 
event, task or frame
+ * \param duration_handle handle to the duration object
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileDurationStop(ProfileHandle duration_handle);
+
+/*!
+ * \brief Set a counter, given its handle
+ * \param counter_handle Handle to counter to set
+ * \param value Value to set the counter to (64-bit unsigned integer)
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileSetCounter(ProfileHandle counter_handle, uint64_t 
value);
+
+/*!
+ * \brief Adjust a counter by the given amount, given its handle
+ * \param counter_handle Handle to counter to adjust
+ * \param value Value to adjust the counter by (64-bit signed integer)
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileAdjustCounter(ProfileHandle counter_handle, int64_t 
value);
+
+/*!
+ * \brief Mark a single instant in time
+ * \param domain Domain of the marker
+ * \param instant_marker_name Name of the marker
+ * \param scope Scope of marker ('global', 'process', 'thread', 'task', 
'marker')
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXProfileSetInstantMarker(ProfileHandle domain,
 
 Review comment:
   just marker


This is an automated message from the Apache Git Service.
To respond to 

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156562734
 
 

 ##
 File path: include/mxnet/c_api.h
 ##
 @@ -227,10 +228,131 @@ MXNET_DLL int MXSetProfilerConfig(int mode, const char* 
filename);
  */
 MXNET_DLL int MXSetProfilerState(int state);
 
-/*! \brief Save profile and stop profiler */
+/*!
+ * \brief Save profile and stop profiler
+ * \param append true if appending to current profile file, false for truncate
+ * \return
+ */
 MXNET_DLL int MXDumpProfile();
 
-/*! \brief Set the number of OMP threads to use */
+/*!
+ * \brief Set whether to continuously write the profiling data to a file
+ * \param continuous_dump true to continuously write profiling data to a file
+ * \param delay_in_seconds Number of seconds (or fraction of seconds) to delay 
between writes
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXSetContinuousProfileDump(int continuous_dump, float 
delay_in_seconds);
+
+/*!
+ * \brief Pause profiler tuning collection
+ * \param paused If nonzero, profiling pauses. Otherwise, profiling 
resumes/continues
+ * \return 0 when success, -1 when failure happens.
+ * \note pausing and resuming is global and not recursive
+ */
+MXNET_DLL int MXProfilePause(int paused);
 
 Review comment:
   Toggle?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156564306
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -56,3 +55,228 @@ 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 = ProfileHandle()
+check_call(_LIB.MXProfileCreateDomain(c_str(name), 
ctypes.byref(domain_handle)))
+return domain_handle
+
+def create_task(domain_handle, name):
+task_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateTask(domain_handle,
+c_str(name),
+ctypes.byref(task_handle)))
+return task_handle
+
+def destroy_task(task_handle):
+check_call(_LIB.MXProfileDestroyHandle(task_handle))
+
+def task_start(task_handle):
+check_call(_LIB.MXProfileDurationStart(task_handle))
+
+def task_stop(task_handle):
+check_call(_LIB.MXProfileDurationStop(task_handle))
+
+def create_frame(domain_handle, name):
+frame_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateFrame(domain_handle,
+ c_str(name),
+ ctypes.byref(frame_handle)))
+return frame_handle
+
+def destroy_frame(frame_handle):
+check_call(_LIB.MXProfileDestroyHandle(frame_handle))
+
+def frame_start(frame_handle):
+check_call(_LIB.MXProfileDurationStart(frame_handle))
+
+def frame_stop(frame_handle):
+check_call(_LIB.MXProfileDurationStop(frame_handle))
+
+def create_event(name):
+event_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateEvent(c_str(name), 
ctypes.byref(event_handle)))
+return event_handle
+
+def destroy_event(event_handle):
+check_call(_LIB.MXProfileDestroyHandle(event_handle))
+
+def event_start(event_handle):
+check_call(_LIB.MXProfileDurationStart(event_handle))
+
+def event_stop(event_handle):
+check_call(_LIB.MXProfileDurationStop(event_handle))
+
+def tune_pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def tune_resume():
+check_call(_LIB.MXProfilePause(int(0)))
+
+def create_counter(domain_handle, name, value=None):
+counter_handle = ProfileHandle()
+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.MXProfileDestroyHandle(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_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'):
+check_call(_LIB.MXProfileSetInstantMarker(domain_handle, c_str(name), 
c_str(scope)))
+
+
+class Domain:
+"""Profiling domain, used to group sub-objects like tasks, counters, etc 
into categories
 
 Review comment:
   . at the 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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156564128
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -56,3 +55,228 @@ 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 = ProfileHandle()
+check_call(_LIB.MXProfileCreateDomain(c_str(name), 
ctypes.byref(domain_handle)))
+return domain_handle
+
+def create_task(domain_handle, name):
+task_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateTask(domain_handle,
+c_str(name),
+ctypes.byref(task_handle)))
+return task_handle
+
+def destroy_task(task_handle):
+check_call(_LIB.MXProfileDestroyHandle(task_handle))
+
+def task_start(task_handle):
+check_call(_LIB.MXProfileDurationStart(task_handle))
+
+def task_stop(task_handle):
+check_call(_LIB.MXProfileDurationStop(task_handle))
+
+def create_frame(domain_handle, name):
+frame_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateFrame(domain_handle,
+ c_str(name),
+ ctypes.byref(frame_handle)))
+return frame_handle
+
+def destroy_frame(frame_handle):
+check_call(_LIB.MXProfileDestroyHandle(frame_handle))
+
+def frame_start(frame_handle):
+check_call(_LIB.MXProfileDurationStart(frame_handle))
+
+def frame_stop(frame_handle):
+check_call(_LIB.MXProfileDurationStop(frame_handle))
+
+def create_event(name):
+event_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateEvent(c_str(name), 
ctypes.byref(event_handle)))
+return event_handle
+
+def destroy_event(event_handle):
+check_call(_LIB.MXProfileDestroyHandle(event_handle))
+
+def event_start(event_handle):
+check_call(_LIB.MXProfileDurationStart(event_handle))
+
+def event_stop(event_handle):
+check_call(_LIB.MXProfileDurationStop(event_handle))
+
+def tune_pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def tune_resume():
+check_call(_LIB.MXProfilePause(int(0)))
+
+def create_counter(domain_handle, name, value=None):
+counter_handle = ProfileHandle()
+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.MXProfileDestroyHandle(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_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'):
+check_call(_LIB.MXProfileSetInstantMarker(domain_handle, c_str(name), 
c_str(scope)))
+
+
+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
 
 Review comment:
   add new_frame/create_frame/frame (not sure which is better) method to Domain.


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156562684
 
 

 ##
 File path: include/mxnet/c_api.h
 ##
 @@ -211,13 +213,12 @@ MXNET_DLL int MXRandomSeed(int seed);
 MXNET_DLL int MXNotifyShutdown();
 /*!
  * \brief Set up configuration of profiler
- * \param mode indicate the working mode of profiler,
- *  record anly symbolic operator when mode == 0,
- *  record all operator when mode == 1
+ * \param mode indicate the working mode of profiler
  * \param filename where to save trace file
+ * \param append_mode Whether DumpProfile() call should append to the same 
profile data file
  * \return 0 when success, -1 when failure happens.
  */
-MXNET_DLL int MXSetProfilerConfig(int mode, const char* filename);
+MXNET_DLL int MXSetProfilerConfig(const char *mode, const char* filename, int 
append_mode);
 
 Review comment:
   change to kwargs


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156564463
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -56,3 +55,228 @@ 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 = ProfileHandle()
+check_call(_LIB.MXProfileCreateDomain(c_str(name), 
ctypes.byref(domain_handle)))
+return domain_handle
+
+def create_task(domain_handle, name):
+task_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateTask(domain_handle,
+c_str(name),
+ctypes.byref(task_handle)))
+return task_handle
+
+def destroy_task(task_handle):
+check_call(_LIB.MXProfileDestroyHandle(task_handle))
+
+def task_start(task_handle):
+check_call(_LIB.MXProfileDurationStart(task_handle))
+
+def task_stop(task_handle):
+check_call(_LIB.MXProfileDurationStop(task_handle))
+
+def create_frame(domain_handle, name):
+frame_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateFrame(domain_handle,
+ c_str(name),
+ ctypes.byref(frame_handle)))
+return frame_handle
+
+def destroy_frame(frame_handle):
+check_call(_LIB.MXProfileDestroyHandle(frame_handle))
+
+def frame_start(frame_handle):
+check_call(_LIB.MXProfileDurationStart(frame_handle))
+
+def frame_stop(frame_handle):
+check_call(_LIB.MXProfileDurationStop(frame_handle))
+
+def create_event(name):
+event_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateEvent(c_str(name), 
ctypes.byref(event_handle)))
+return event_handle
+
+def destroy_event(event_handle):
+check_call(_LIB.MXProfileDestroyHandle(event_handle))
+
+def event_start(event_handle):
+check_call(_LIB.MXProfileDurationStart(event_handle))
+
+def event_stop(event_handle):
+check_call(_LIB.MXProfileDurationStop(event_handle))
+
+def tune_pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def tune_resume():
+check_call(_LIB.MXProfilePause(int(0)))
+
+def create_counter(domain_handle, name, value=None):
+counter_handle = ProfileHandle()
+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.MXProfileDestroyHandle(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_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'):
+check_call(_LIB.MXProfileSetInstantMarker(domain_handle, c_str(name), 
c_str(scope)))
+
+
+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.
+When frames are 

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156564589
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -56,3 +55,228 @@ 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 = ProfileHandle()
+check_call(_LIB.MXProfileCreateDomain(c_str(name), 
ctypes.byref(domain_handle)))
+return domain_handle
+
+def create_task(domain_handle, name):
+task_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateTask(domain_handle,
+c_str(name),
+ctypes.byref(task_handle)))
+return task_handle
+
+def destroy_task(task_handle):
+check_call(_LIB.MXProfileDestroyHandle(task_handle))
+
+def task_start(task_handle):
+check_call(_LIB.MXProfileDurationStart(task_handle))
+
+def task_stop(task_handle):
+check_call(_LIB.MXProfileDurationStop(task_handle))
+
+def create_frame(domain_handle, name):
+frame_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateFrame(domain_handle,
+ c_str(name),
+ ctypes.byref(frame_handle)))
+return frame_handle
+
+def destroy_frame(frame_handle):
+check_call(_LIB.MXProfileDestroyHandle(frame_handle))
+
+def frame_start(frame_handle):
+check_call(_LIB.MXProfileDurationStart(frame_handle))
+
+def frame_stop(frame_handle):
+check_call(_LIB.MXProfileDurationStop(frame_handle))
+
+def create_event(name):
+event_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateEvent(c_str(name), 
ctypes.byref(event_handle)))
+return event_handle
+
+def destroy_event(event_handle):
+check_call(_LIB.MXProfileDestroyHandle(event_handle))
+
+def event_start(event_handle):
+check_call(_LIB.MXProfileDurationStart(event_handle))
+
+def event_stop(event_handle):
+check_call(_LIB.MXProfileDurationStop(event_handle))
+
+def tune_pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def tune_resume():
+check_call(_LIB.MXProfilePause(int(0)))
+
+def create_counter(domain_handle, name, value=None):
+counter_handle = ProfileHandle()
+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.MXProfileDestroyHandle(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_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'):
+check_call(_LIB.MXProfileSetInstantMarker(domain_handle, c_str(name), 
c_str(scope)))
+
+
+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.
+When frames are 

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156563911
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -56,3 +55,228 @@ 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 = ProfileHandle()
+check_call(_LIB.MXProfileCreateDomain(c_str(name), 
ctypes.byref(domain_handle)))
+return domain_handle
+
+def create_task(domain_handle, name):
+task_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateTask(domain_handle,
+c_str(name),
+ctypes.byref(task_handle)))
+return task_handle
+
+def destroy_task(task_handle):
+check_call(_LIB.MXProfileDestroyHandle(task_handle))
+
+def task_start(task_handle):
+check_call(_LIB.MXProfileDurationStart(task_handle))
+
+def task_stop(task_handle):
+check_call(_LIB.MXProfileDurationStop(task_handle))
+
+def create_frame(domain_handle, name):
+frame_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateFrame(domain_handle,
+ c_str(name),
+ ctypes.byref(frame_handle)))
+return frame_handle
+
+def destroy_frame(frame_handle):
+check_call(_LIB.MXProfileDestroyHandle(frame_handle))
+
+def frame_start(frame_handle):
+check_call(_LIB.MXProfileDurationStart(frame_handle))
+
+def frame_stop(frame_handle):
+check_call(_LIB.MXProfileDurationStop(frame_handle))
+
+def create_event(name):
+event_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateEvent(c_str(name), 
ctypes.byref(event_handle)))
+return event_handle
+
+def destroy_event(event_handle):
+check_call(_LIB.MXProfileDestroyHandle(event_handle))
+
+def event_start(event_handle):
+check_call(_LIB.MXProfileDurationStart(event_handle))
+
+def event_stop(event_handle):
+check_call(_LIB.MXProfileDurationStop(event_handle))
+
+def tune_pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def tune_resume():
+check_call(_LIB.MXProfilePause(int(0)))
+
+def create_counter(domain_handle, name, value=None):
+counter_handle = ProfileHandle()
+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.MXProfileDestroyHandle(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_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'):
+check_call(_LIB.MXProfileSetInstantMarker(domain_handle, c_str(name), 
c_str(scope)))
+
+
+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:
 
 Review comment:
   Task(object)


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156564338
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -56,3 +55,228 @@ 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 = ProfileHandle()
+check_call(_LIB.MXProfileCreateDomain(c_str(name), 
ctypes.byref(domain_handle)))
+return domain_handle
+
+def create_task(domain_handle, name):
+task_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateTask(domain_handle,
+c_str(name),
+ctypes.byref(task_handle)))
+return task_handle
+
+def destroy_task(task_handle):
+check_call(_LIB.MXProfileDestroyHandle(task_handle))
+
+def task_start(task_handle):
+check_call(_LIB.MXProfileDurationStart(task_handle))
+
+def task_stop(task_handle):
+check_call(_LIB.MXProfileDurationStop(task_handle))
+
+def create_frame(domain_handle, name):
+frame_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateFrame(domain_handle,
+ c_str(name),
+ ctypes.byref(frame_handle)))
+return frame_handle
+
+def destroy_frame(frame_handle):
+check_call(_LIB.MXProfileDestroyHandle(frame_handle))
+
+def frame_start(frame_handle):
+check_call(_LIB.MXProfileDurationStart(frame_handle))
+
+def frame_stop(frame_handle):
+check_call(_LIB.MXProfileDurationStop(frame_handle))
+
+def create_event(name):
+event_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateEvent(c_str(name), 
ctypes.byref(event_handle)))
+return event_handle
+
+def destroy_event(event_handle):
+check_call(_LIB.MXProfileDestroyHandle(event_handle))
+
+def event_start(event_handle):
+check_call(_LIB.MXProfileDurationStart(event_handle))
+
+def event_stop(event_handle):
+check_call(_LIB.MXProfileDurationStop(event_handle))
+
+def tune_pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def tune_resume():
+check_call(_LIB.MXProfilePause(int(0)))
+
+def create_counter(domain_handle, name, value=None):
+counter_handle = ProfileHandle()
+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.MXProfileDestroyHandle(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_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'):
+check_call(_LIB.MXProfileSetInstantMarker(domain_handle, c_str(name), 
c_str(scope)))
+
+
+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
+"""
 
 Review comment:
   
   ```
   Parameters
   ---
   ```
   Follow the convention


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156562698
 
 

 ##
 File path: include/mxnet/c_api.h
 ##
 @@ -227,10 +228,131 @@ MXNET_DLL int MXSetProfilerConfig(int mode, const char* 
filename);
  */
 MXNET_DLL int MXSetProfilerState(int state);
 
-/*! \brief Save profile and stop profiler */
+/*!
+ * \brief Save profile and stop profiler
+ * \param append true if appending to current profile file, false for truncate
+ * \return
+ */
 MXNET_DLL int MXDumpProfile();
 
-/*! \brief Set the number of OMP threads to use */
+/*!
+ * \brief Set whether to continuously write the profiling data to a file
+ * \param continuous_dump true to continuously write profiling data to a file
+ * \param delay_in_seconds Number of seconds (or fraction of seconds) to delay 
between writes
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXSetContinuousProfileDump(int continuous_dump, float 
delay_in_seconds);
 
 Review comment:
   merge this into config


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156565366
 
 

 ##
 File path: src/engine/naive_engine.cc
 ##
 @@ -130,22 +125,17 @@ class NaiveEngine final : public Engine {
 NaiveEngine::OnComplete, nullptr);
 this->req_completed_ = false;
 #if MXNET_USE_PROFILER
-Profiler *profiler = Profiler::Get();
+profile::Profiler *profiler = profile::Profiler::Get();
 NaiveOpr *opr = nullptr;
-bool profiling = (profiler->GetState() == Profiler::kRunning) &&
-   (profiler->GetMode() == Profiler::kAllOperator) &&
+bool profiling = (profiler->GetState() == profile::Profiler::kRunning) &&
 
 Review comment:
   add profiler->IsEnabledFor(mode)


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2018-01-02 Thread GitBox
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_r156564518
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -56,3 +55,228 @@ 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 = ProfileHandle()
+check_call(_LIB.MXProfileCreateDomain(c_str(name), 
ctypes.byref(domain_handle)))
+return domain_handle
+
+def create_task(domain_handle, name):
+task_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateTask(domain_handle,
+c_str(name),
+ctypes.byref(task_handle)))
+return task_handle
+
+def destroy_task(task_handle):
+check_call(_LIB.MXProfileDestroyHandle(task_handle))
+
+def task_start(task_handle):
+check_call(_LIB.MXProfileDurationStart(task_handle))
+
+def task_stop(task_handle):
+check_call(_LIB.MXProfileDurationStop(task_handle))
+
+def create_frame(domain_handle, name):
+frame_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateFrame(domain_handle,
+ c_str(name),
+ ctypes.byref(frame_handle)))
+return frame_handle
+
+def destroy_frame(frame_handle):
+check_call(_LIB.MXProfileDestroyHandle(frame_handle))
+
+def frame_start(frame_handle):
+check_call(_LIB.MXProfileDurationStart(frame_handle))
+
+def frame_stop(frame_handle):
+check_call(_LIB.MXProfileDurationStop(frame_handle))
+
+def create_event(name):
+event_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateEvent(c_str(name), 
ctypes.byref(event_handle)))
+return event_handle
+
+def destroy_event(event_handle):
+check_call(_LIB.MXProfileDestroyHandle(event_handle))
+
+def event_start(event_handle):
+check_call(_LIB.MXProfileDurationStart(event_handle))
+
+def event_stop(event_handle):
+check_call(_LIB.MXProfileDurationStop(event_handle))
+
+def tune_pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def tune_resume():
+check_call(_LIB.MXProfilePause(int(0)))
+
+def create_counter(domain_handle, name, value=None):
+counter_handle = ProfileHandle()
+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.MXProfileDestroyHandle(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_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'):
+check_call(_LIB.MXProfileSetInstantMarker(domain_handle, c_str(name), 
c_str(scope)))
+
+
+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.
+When frames are 

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-12 Thread GitBox
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_r156519270
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -56,3 +53,235 @@ 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 = ProfileHandle()
+check_call(_LIB.MXProfileCreateDomain(c_str(name), 
ctypes.byref(domain_handle)))
+return domain_handle
+
+def create_task(domain_handle, name):
+task_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateTask(domain_handle,
+c_str(name),
+ctypes.byref(task_handle)))
+return task_handle
+
+def destroy_task(task_handle):
+check_call(_LIB.MXProfileDestroyHandle(task_handle))
+
+def task_start(task_handle):
+check_call(_LIB.MXProfileDurationStart(task_handle))
+
+def task_stop(task_handle):
+check_call(_LIB.MXProfileDurationStop(task_handle))
+
+def create_frame(domain_handle, name):
+frame_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateFrame(domain_handle,
+ c_str(name),
+ ctypes.byref(frame_handle)))
+return frame_handle
+
+def destroy_frame(frame_handle):
+check_call(_LIB.MXProfileDestroyHandle(frame_handle))
+
+def frame_start(frame_handle):
+check_call(_LIB.MXProfileDurationStart(frame_handle))
+
+def frame_stop(frame_handle):
+check_call(_LIB.MXProfileDurationStop(frame_handle))
+
+def create_event(name):
+event_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateEvent(c_str(name), 
ctypes.byref(event_handle)))
+return event_handle
+
+def destroy_event(event_handle):
+check_call(_LIB.MXProfileDestroyHandle(event_handle))
+
+def event_start(event_handle):
+check_call(_LIB.MXProfileDurationStart(event_handle))
+
+def event_stop(event_handle):
+check_call(_LIB.MXProfileDurationStop(event_handle))
+
+def tune_pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def tune_resume():
+check_call(_LIB.MXProfilePause(int(0)))
+
+def create_counter(domain_handle, name, value=None):
+counter_handle = ProfileHandle()
+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.MXProfileDestroyHandle(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'):
+check_call(_LIB.MXProfileSetInstantMarker(domain_handle, c_str(name), 
c_str(scope)))
+
+
+class Domain:
 
 Review comment:
   class Domain(object):


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-12 Thread GitBox
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_r156519228
 
 

 ##
 File path: include/mxnet/c_api.h
 ##
 @@ -227,10 +227,138 @@ MXNET_DLL int MXSetProfilerConfig(int mode, const char* 
filename);
  */
 MXNET_DLL int MXSetProfilerState(int state);
 
-/*! \brief Save profile and stop profiler */
+/*!
+ * \brief Save profile and stop profiler
+ * \param append true if appending to current profile file, false for truncate
+ * \return
+ */
 MXNET_DLL int MXDumpProfile();
 
-/*! \brief Set the number of OMP threads to use */
+/*!
+ * \brief Set whether to continuously write the profiling data to a file
+ * \param continuous_dump true to continuously write profiling data to a file
+ * \param delay_in_seconds Number of seconds (or fraction of seconds) to delay 
between writes
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXSetContinuousProfileDump(int continuous_dump, float 
delay_in_seconds);
+
+/*!
+ * \brief Control whether to append profile data dumps to the output file or 
whether to truncate
+ * \param append true to append subsequent MXDumpProfile() calls to the 
preexisting file
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXSetDumpProfileAppendMode(int append);
 
 Review comment:
   Why not merge this with the config api?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-10 Thread GitBox
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_r155958990
 
 

 ##
 File path: src/c_api/c_api_common.h
 ##
 @@ -35,16 +35,16 @@
 #include 
 
 /*! \brief  macro to guard beginning and end section of all functions */
-#define API_BEGIN() try {
+#define API_BEGIN() try { on_enter_api(__FUNCTION__);
 
 Review comment:
   what's the overhead of this?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-10 Thread GitBox
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)
+
+

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-10 Thread GitBox
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_r155958912
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -56,3 +53,235 @@ 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 = ProfileHandle()
+check_call(_LIB.MXProfileCreateDomain(c_str(name), 
ctypes.byref(domain_handle)))
+return domain_handle
+
+def create_task(domain_handle, name):
+task_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateTask(domain_handle,
+c_str(name),
+ctypes.byref(task_handle)))
+return task_handle
+
+def destroy_task(task_handle):
+check_call(_LIB.MXProfileDestroyHandle(task_handle))
+
+def task_start(task_handle):
+check_call(_LIB.MXProfileDurationStart(task_handle))
+
+def task_stop(task_handle):
+check_call(_LIB.MXProfileDurationStop(task_handle))
+
+def create_frame(domain_handle, name):
+frame_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateFrame(domain_handle,
+ c_str(name),
+ ctypes.byref(frame_handle)))
+return frame_handle
+
+def destroy_frame(frame_handle):
+check_call(_LIB.MXProfileDestroyHandle(frame_handle))
+
+def frame_start(frame_handle):
+check_call(_LIB.MXProfileDurationStart(frame_handle))
+
+def frame_stop(frame_handle):
+check_call(_LIB.MXProfileDurationStop(frame_handle))
+
+def create_event(name):
+event_handle = ProfileHandle()
+check_call(_LIB.MXProfileCreateEvent(c_str(name), 
ctypes.byref(event_handle)))
+return event_handle
+
+def destroy_event(event_handle):
+check_call(_LIB.MXProfileDestroyHandle(event_handle))
+
+def event_start(event_handle):
+check_call(_LIB.MXProfileDurationStart(event_handle))
+
+def event_stop(event_handle):
+check_call(_LIB.MXProfileDurationStop(event_handle))
+
+def tune_pause():
+check_call(_LIB.MXProfilePause(int(1)))
+
+def tune_resume():
+check_call(_LIB.MXProfilePause(int(0)))
+
+def create_counter(domain_handle, name, value=None):
+counter_handle = ProfileHandle()
+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.MXProfileDestroyHandle(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'):
+check_call(_LIB.MXProfileSetInstantMarker(domain_handle, c_str(name), 
c_str(scope)))
+
+
+class Domain:
 
 Review comment:
   inherit object


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-10 Thread GitBox
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_r155958766
 
 

 ##
 File path: include/mxnet/c_api.h
 ##
 @@ -227,10 +227,138 @@ MXNET_DLL int MXSetProfilerConfig(int mode, const char* 
filename);
  */
 MXNET_DLL int MXSetProfilerState(int state);
 
-/*! \brief Save profile and stop profiler */
+/*!
+ * \brief Save profile and stop profiler
+ * \param append true if appending to current profile file, false for truncate
+ * \return
+ */
 MXNET_DLL int MXDumpProfile();
 
-/*! \brief Set the number of OMP threads to use */
+/*!
+ * \brief Set whether to continuously write the profiling data to a file
+ * \param continuous_dump true to continuously write profiling data to a file
+ * \param delay_in_seconds Number of seconds (or fraction of seconds) to delay 
between writes
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXSetContinuousProfileDump(int continuous_dump, float 
delay_in_seconds);
+
+/*!
+ * \brief Control whether to append profile data dumps to the output file or 
whether to truncate
+ * \param append true to append subsequent MXDumpProfile() calls to the 
preexisting file
+ * \return 0 when success, -1 when failure happens.
+ */
+MXNET_DLL int MXSetDumpProfileAppendMode(int append);
 
 Review comment:
   Why are these part of config?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-10 Thread GitBox
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_r155958710
 
 

 ##
 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)
+
+

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-09 Thread GitBox
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_r155929416
 
 

 ##
 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)
+
+

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-06 Thread GitBox
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_r155401286
 
 

 ##
 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)
+
+

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-06 Thread GitBox
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_r155401074
 
 

 ##
 File path: src/storage/storage_profiler.h
 ##
 @@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef MXNET_STORAGE_STORAGE_PROFILER_H_
+#define MXNET_STORAGE_STORAGE_PROFILER_H_
+
+#include 
+#include 
+#include 
+#include "../engine/profiler.h"
+
+namespace mxnet {
+namespace storage {
+
+#if MXNET_USE_PROFILER
+/*!
+ * \brief Storage allocation/deallocation profiling via ProfileCounters
+ */
+class DeviceStorageProfiler {
 
 Review comment:
   Why isn't this in the engine profiler?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-06 Thread GitBox
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_r155400997
 
 

 ##
 File path: src/storage/storage.cc
 ##
 @@ -149,6 +155,9 @@ void StorageImpl::DirectFree(Storage::Handle handle) {
 return nullptr;
   });
   this->ActivateDevice(ctx);
+#if MXNET_USE_PROFILER
+  profiler_.OnFree(handle);
 
 Review comment:
   shouldn't it be placed after free?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-06 Thread GitBox
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_r155400761
 
 

 ##
 File path: src/ndarray/ndarray_function.cc
 ##
 @@ -26,24 +26,35 @@
 #include "./ndarray_function.h"
 #include "./ndarray_function-inl.h"
 #include "../common/utils.h"
+#include "../operator/mxnet_op.h"
 
 namespace mxnet {
 namespace ndarray {
 template<>
 void Copy(const TBlob , TBlob *to,
 Context from_ctx, Context to_ctx,
 RunContext ctx) {
+  using namespace mxnet::op;
   MSHADOW_TYPE_SWITCH(to->type_flag_, DType, {
 if (to->type_flag_ == from.type_flag_) {
-mshadow::Copy(to->FlatTo1D(),
-  from.FlatTo1D());
+  TBlob dest = to->FlatTo1D();
+  TBlob src = from.FlatTo1D();
+  const size_t size = src.Size();
+  if (dest.CheckContiguous() && src.CheckContiguous() && size >= 2 /* 
non-trivial size */) {
 
 Review comment:
   Do this inside mxnet_op::Kernel, cpu>?


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


[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-06 Thread GitBox
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_r155400486
 
 

 ##
 File path: src/engine/profiler.h
 ##
 @@ -94,81 +254,816 @@ struct DevStat {
 class Profiler {
  public:
   enum ProfilerMode {
-  kOnlySymbolic = 0,
-  kAllOperator  = 1
+  kSymbolic = 1,
+  kImperative = 2,
+  kAPI = 4,
+  kMemory = 8
   };
   enum ProfilerState {
   kNotRunning = 0,
   kRunning = 1
   };
+
   /*! \brief set state of profiler */
   void SetState(ProfilerState state);
   /*! \return state of profiler */
   inline ProfilerState GetState() const {
 return this->state_;
   }
   /*! \brief set configure of profiler */
-  void SetConfig(ProfilerMode mode, std::string output_filename);
+  void SetConfig(int mode, std::string output_filename);
   /*! \return mode of profiler */
-  inline ProfilerMode GetMode() const {
+  inline int GetMode() const {
 return this->mode_;
   }
   /*! \return whether the profiler is enabled to output */
   inline bool IsEnableOutput() const {
 return this->enable_output_;
   }
-  /*! \brief dump the profile file */
-  void DumpProfile();
+  /*!
+   * \brief dump the profile file
+   * \param peform_cleanup Close off the json trace structures (ie last pass)
+   */
+  void DumpProfile(bool peform_cleanup = true);
+
+  /*!
+   * \brief Set whether calls to DumpProfile() should append or truncate the 
output file
+   * \param append true if profile information should be appended to the 
existing file
+   */
+  void SetDumpProfileAppendMode(bool append);
+
+  /*!
+   * \brief Set continuous asynchronous profile dump
+   * \param continuous_dump Whether to continuously dump profile information
+   * \param delay_in_seconds Delay between asynchronous dumps
+   */
+  void SetContinuousProfileDump(bool continuous_dump, float delay_in_seconds = 
1.0f);
+
   /*! \return the profiler init time, time unit is microsecond (10^-6) s */
   inline uint64_t GetInitTime() const {
 return init_time_;
   }
-  /*! \brief add one operation execution record in
-   *   corresponding device statistics */
-  OprExecStat* AddOprStat(int dev_type, uint32_t dev_id);
+  /*!
+   * \brief add one operation execution record in corresponding device 
statistics
+   * \tparam SetExtraInfoFunction
+   * \param dev_type
+   * \param dev_id
+   * \param set_extra_info_function
+   * \note Because when this function exits, the object is written to the 
profile queue,
+   *   and at that point, could be consumed and/or destroyed at any moment,
+   *   any preprocessing on the object is to be done in the 
set_extra_info_function
+   *   callback.  Another option is to use the 
CreateProfileStat()/AddProfileStat() pair,
+   *   adding it only after
+   */
+  template
+  void AddNewProfileStat(SetExtraInfoFunction set_extra_info_function, Args... 
args) {
+if (!paused_) {
+  std::unique_ptr stat = CreateProfileStat(args...);
+  set_extra_info_function(stat.get());
+  AddProfileStat();
+}
+  }
+
   /*! \return Profiler singleton */
   static Profiler* Get();
 
+  /*!DurationStat
+   * \brief Check the last append mode sent to DumpProfile (false by default)
+   * \return true if profile is in append mode, false if DumpFile() will 
truncate
+   */
+  bool append_mode() const { return append_profile_; }
+
+  /*!
+   * \brief Set whether statistic collection is to be paused
+   * \param paused true if statistic collection is to be paused, otherwise
+   * resume statistic collection
+   * \note Pause/Resume is not recursive
+   */
+  void set_paused(bool paused) { paused_ = paused; }
+
+  /*!
+   * \brief Get the calculated device count (numb er of devices to track in 
profile data).
+   * \return Device count
+   * \note Number of CPU's + Number of GPU's + One for CPU-Pinned
+   */
+  MSHADOW_CINLINE size_t DeviceCount() const { return cpu_num_ + gpu_num_ + 2; 
}
+
+  /*!
+   * \brief Compute device index given device type and id
+   * \param dev_type Device type
+   * \param dev_id Device ID
+   * \return Device index for indexing into device-specific data
+   */
+  size_t DeviceIndex(mxnet::Context::DeviceType dev_type, int32_t dev_id);
+
+  /*!
+   * \brief Device name
+   * \param dev_type Device type
+   * \param dev_id Device ID
+   * \return Character pointer to device name
+   */
+  const char *DeviceName(mxnet::Context::DeviceType dev_type, int32_t dev_id);
+
+
+  /*!
+   * \brief Device name
+   * \param dev_type Device type
+   * \param dev_id Device ID
+   * \return Character pointer to device name
+   */
+  const char *DeviceName(const size_t index);
+
  protected:
   /*! \brief make constructor protected. */
   Profiler();
+  /*! \brief Destructor */
+  ~Profiler();
 
  private:
+  /*!
+   * \brief Create a new profile statistic object
+   * \tparam StatType The type of the profile 

[GitHub] piiswrong commented on a change in pull request #8972: Profiling enhancements, python API, vtune and chrome tracing objects, etc.

2017-12-06 Thread GitBox
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_r155399240
 
 

 ##
 File path: python/mxnet/profiler.py
 ##
 @@ -35,10 +35,23 @@ def profiler_set_config(mode='symbolic', 
filename='profile.json'):
 filename : string, optional
 The name of output trace file. Defaults to 'profile.json'.
 """
-mode2int = {'symbolic': 0, 'all': 1}
-check_call(_LIB.MXSetProfilerConfig(
-ctypes.c_int(mode2int[mode]),
-c_str(filename)))
+mode2int = {'symbolic': 1,
 
 Review comment:
   do this in backend with dmlc::parameter


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