
    Je_                         d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZmZ dd	lmZ  G d
 d      Z G d de      Zy)z
Profiler Plugin.
    )Signal)PluginsSpyderDockablePlugin)on_plugin_availableon_plugin_teardown_)ApplicationMenus)ProfilerConfigPage)ProfilerWidgetis_profiler_installed)get_run_configurationc                       e Zd ZdZy)ProfilerActionsprofile_current_filename_actionN)__name__
__module____qualname__ProfileCurrentFile     @/usr/lib/python3/dist-packages/spyder/plugins/profiler/plugin.pyr   r      s    :r   r   c                      e Zd ZdZdZej                  ej                  gZej                  gZ
ej                  gZeZeZeZdZ e       Z	  e       Z	 ed        Zd Zd Zd Z eej                        d	        Z eej                        d
        Z eej                        d        Z eej                        d        Z  eej                        d        Z! eej                        d        Z"d Z#d Z$d Z%y)Profilerz7
    Profiler (after python's profile and pstats).
    profilerFc                      t        d      S )Nr   r   r   r   r   get_namezProfiler.get_name:   s    }r   c                     t        d      S )Nz*Profile your scripts and find bottlenecks.r   selfs    r   get_descriptionzProfiler.get_description>   s    =>>r   c                 $    | j                  d      S )Nr   )create_iconr   s    r   get_iconzProfiler.get_iconA   s    
++r   c                    | j                         }|j                  j                  | j                         |j                  j                  | j                         | j	                  t
        j                  t        d      t        d      | j                  d      | j                  d      }|j                  t                      y )NzRun profilerr   T)texttipicon	triggeredregister_shortcut)
get_widgetsig_startedconnectsig_finishedcreate_actionr   r   r	   r#   run_profiler
setEnabledr   )r    widget
run_actions      r   on_initializezProfiler.on_initializeD   s    """4#3#34##D$5$56''..>".!!!*-''" ( 

 	356r   )pluginc                     | j                         }| j                  t        j                        }|j                  j                  |j                         y N)r+   
get_pluginr   Editorsig_edit_goto_requestedr-   loadr    r2   editors      r   on_editor_availablezProfiler.on_editor_availableT   s8    "0&&..v{{;r   c                 d    | j                  t        j                        }|j                  |        y r7   )r8   r   Preferencesregister_plugin_preferencesr    preferencess     r   on_preferences_availablez!Profiler.on_preferences_availableZ   s$    oog&9&9://5r   c                     | j                  t        j                        }| j                  t        j
                        }|j                  |t        j                         y N)menu_id)	r8   r   MainMenu
get_actionr   r   add_item_to_application_menur
   Run)r    mainmenur3   s      r   on_main_menu_availablezProfiler.on_main_menu_available_   sI    ??7#3#34___%G%GH
-- 0 4 4 	. 	6r   c                     | j                         }| j                  t        j                        }|j                  j                  |j                         y r7   )r+   r8   r   r9   r:   
disconnectr;   r<   s      r   on_editor_teardownzProfiler.on_editor_teardowng   s8    "0&&11&++>r   c                 d    | j                  t        j                        }|j                  |        y r7   )r8   r   r@   deregister_plugin_preferencesrB   s     r   on_preferences_teardownz Profiler.on_preferences_teardownm   s$    oog&9&9:11$7r   c                     | j                  t        j                        }|j                  t        j
                  t        j                         y rF   )r8   r   rH   !remove_item_from_application_menur   r   r
   rK   )r    rL   s     r   on_main_menu_teardownzProfiler.on_main_menu_teardownr   s;    ??7#3#3422..$(( 	3 	
r   c                     | j                  t        j                        }|j                         r0| j	                          | j                  |j                                yy)z
        Run profiler.

        Notes
        -----
        This method will check if the file on the editor can be saved first.
        N)r8   r   r9   saveswitch_to_pluginanalyzeget_current_filename)r    r=   s     r   r0   zProfiler.run_profiler}   sE     0;;=!!#LL4467 r   c                 @    | j                         j                          y)z 
        Stop profiler.
        N)r+   stopr   s    r   stop_profilerzProfiler.stop_profiler   s     	 r   c                     dg }}t        |      }|0|j                  r|j                  }|j                  r|j                  }| j                         j                  |||       y)z
        Run profile analysis on `filename`.

        Parameters
        ----------
        filename: str
            Path to file to analyze.
        N)wdirargs)r   wdir_enabledr`   args_enabledra   r+   rZ   )r    filenamer`   ra   runconfs        r   rZ   zProfiler.analyze   sd     2d'1##||##||!! 	" 	
r   N)&r   r   r   __doc__NAMEr   r@   r9   REQUIRESrH   OPTIONALHelpTABIFYr   WIDGET_CLASSCONF_SECTIONr   CONF_WIDGET_CLASS	CONF_FILEr   r,   r.   staticmethodr   r!   r$   r4   r   r>   rD   rM   r   rP   rS   rV   r0   r^   rZ   r   r   r   r   r   "   sN    D##W^^4H  !Hll^F!LL*I (KM8LN  ?,7  /< 0<
  3 346 56  0 016 26 w~~.? /?
 w2238 48 w//0
 1
8!
r   r   N)rf   qtpy.QtCorer   spyder.api.pluginsr   r   )spyder.api.plugin_registration.decoratorsr   r   spyder.api.translationsr	   spyder.plugins.mainmenu.apir
    spyder.plugins.profiler.confpager   +spyder.plugins.profiler.widgets.main_widgetr   r   spyder.plugins.run.widgetsr   r   r   r   r   r   <module>ry      sD   
  =- % 8 ?P <
; ;D
# D
r   