Jump to content
  • How to find specific scripts in DXP files in the Spotfire Library using the Application Profiler


    In this article we will look specifically at how to use the Application Profiler tool to search a Spotfire library to find DXP files containing scripts that include a certain statement in the body of the script.

     

    In large Spotfire installations with very many DXP files in the library, how can you find out which file that contains a certain configuration of a visualization,  a specific custom expression, or a specific IronPython or JavaScript snippet?

    This can be a hard task if you think of doing it manually, going through 100s or 1000s of DXP files. Fortunately Spotfire contains a tool called the Application Profiler, which is able to scan any number of files in the Spotfire Library automatically in order to  gather information about the files. The result is then displayed as a set of data tables in a Spotfire Dashboard.

    In this article we will look specifically at how to use the Application Profiler tool to search a Spotfire library to find DXP files containing scripts that include a certain statement in the body of the script.

    If you are interested in more general information about the Application Profiler and how it can be used, please read this tech note:

    Before we start: the Application Profiler tool requires that the user is member of a group that has the "Diagnostics" license enabled (See "Groups and Licenses" in the Administration Manager - User's Guide). The Application Profiler is reached through the Tools menu, under Diagnostics  in the Spotfire installed client. If you cant find "Diagnostics" or "Application Profiler", you don't have the required license for this and need to contact your Spotfire Administrator. Also, the Application Profiler supports Basic (username/password) and Windows Integrated Authentication. In both cases the Application Profiler is authenticated as the current user. 

    The Task

    Our task is very specific: finding DXP files containing scripts with a certain name, and also scripts which include a certain statement in the body of the script. Specifically we want to know if the script uses  the "document.ready" event. This is nothing that the Application Profiler does right out of the box. Thus, we will need to write some IronPython that will do this for us.

    The IronPython scripts to be run from Application Profiler

    Below are two scripts, the first one does the actual job of finding scripts in DXP files that contain the document.ready event, the second one is just needed in order to declare the available output columns for the first script.

    Note: both scripts are available in the attached .zip file in case you want to try it out.

    findScripts.py

    # This script looks for  usage of the document ready event
    # in scripts by finding all scripts in the Document (DXP file),
    # then looping over those scripts searching for text that
    # matches #the document ready event, and finally writing
    # the script name.
    
    from System.IO import *
    
    #import regular expression
    
    import re
    
    #get hold of all scripts through the ScriptManager
    
    s = Document.ScriptManager.GetScripts()
    
    #Initialize variables
    
    foundScripts = ""
    dReady = ""
    
    #now iterate over all scripts we got from the ScriptManager
    
    for y in s:
        foundScripts = foundScripts + y.Name + ";\n"
        m = re.search('document\s*\)\.ready', y.ScriptCode)
        if m:
            dReady = dReady + y.Name + ";\n"
    
    #finally we write the name of the scripts we found to the data
    
    OutputColumns["Scripts"] = foundScripts
    OutputColumns["DocumentReady"] = dReady
     

    Columns.py

    # This is just a script that is required in order to
    # declare the output columns we want to use in the above
    # script.
    
    from System import Tuple, String
    from Spotfire.Dxp.Data import DataType
    
    OutputColumnDataTypes.Add(Tuple.Create[String,DataType]("Scripts", DataType.String))
    OutputColumnDataTypes.Add(Tuple.Create[String,DataType]("DocumentReady", DataType.String))
     

    Running scripts in the Application Profiler

    Scripts in the Application Profiler can be executed from three contexts: for a whole Document (DXP file), for a Data table or for a visualization. In this case it is enough to run the script once per Document (DXP file). The below screen identifies how to configure the Application Profiler to run the scripts, and how to set the DXP fiels it will execute on.
    apscreen.png.11c05c94ef7c632901416dd54038df02.png

    Pushing the "Start" button at the bottom makes the Application Profiler run the scripts on each DXP file identified in the "Included Paths" field. After it is finished, pushing "Show Analysis" makes Spotfire load the data fields created by the Application Profiler during its run. In this example we got the following results:
    apresults.thumb.png.8d3546a2618c354f7a5e77b269b010a0.png

    Above we can see that the Application Profiler tested three files, whereof 2 contained no scripts at all and one contained three scripts where one of the scripts contained code that relied on the document.ready event.

    Summary

    This is just one example of using Scripts in the Application Profiler to find something specific in a potentially large number of DXP files.  The Application Profiler scripts can use the public API in Spotfire and as such can be used for a variety of tasks such as looking for certain configurations, custom expressions, scripts or finding other information about the DXP files.

    application_profiler_scripts.zip

    • Like 1

    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...