74c99d39c800193f07a881ce98ee4b7065cee6dc
hiram
  Fri Sep 13 10:00:57 2019 -0700
get the warning message out of the warning only message to be used elsewhere and add measureTiming printout to hgGateway refs #23217

diff --git src/hg/hgGateway/hgGateway.c src/hg/hgGateway/hgGateway.c
index 859d427..968ad8f 100644
--- src/hg/hgGateway/hgGateway.c
+++ src/hg/hgGateway/hgGateway.c
@@ -23,30 +23,32 @@
 #include "hui.h"
 #include "jsHelper.h"
 #include "jsonParse.h"
 #include "obscure.h"  // for readInGulp
 #include "regexHelper.h"
 #include "suggest.h"
 #include "trackHub.h"
 #include "web.h"
 #include "botDelay.h"
 
 /* Global Variables */
 struct cart *cart = NULL;             /* CGI and other variables */
 struct hash *oldVars = NULL;          /* Old contents of cart before it was updated by CGI */
 
 static boolean issueBotWarning = FALSE;
+static int measureTiming = 0;
+static long enteredMainTime = 0;
 
 #define SEARCH_TERM "hggw_term"
 
 static char *maybeGetDescriptionText(char *db)
 /* Slurp the description.html file for db into a string (if possible, don't die if
  * we can't read it) and return it. */
 {
 struct errCatch *errCatch = errCatchNew();
 char *descText = NULL;
 if (errCatchStart(errCatch))
     {
     char *htmlPath = hHtmlPath(db);
     if (isNotEmpty(htmlPath))
         descText = udcFileReadAll(htmlPath, NULL, 0, NULL);
     }
@@ -275,30 +277,41 @@
 static void doMainPage()
 /* Send HTML with javascript to bootstrap the user interface. */
 {
 // Start web page with new banner
 char *db = NULL, *genome = NULL, *clade = NULL;
 getDbGenomeClade(cart, &db, &genome, &clade, oldVars);
 // If CGI has &lastDbPos=..., handle that here and save position to cart so it's in place for
 // future cartJson calls.
 char *position = cartGetPosition(cart, db, NULL);
 cartSetString(cart, "position", position);
 webStartJWest(cart, db, "Genome Browser Gateway");
 
 if (cgiIsOnWeb())
     checkForGeoMirrorRedirect(cart);
 
+#define HOG_WARNING_BOX_START "<div id='hogWarningRow' class='jwRow'>" \
+         "<div id='hogWarningBox' class='jwWarningBox'>"
+#define HOG_WARNING_BOX_END "</div></div>"
+
+if (issueBotWarning)
+    {
+    char *hogHost = getenv("REMOTE_ADDR");
+    char *delayMsg = botDelayWarningMsg(hogHost, botDelayMillis);
+    printf("%s%s%s\n", HOG_WARNING_BOX_START, delayMsg, HOG_WARNING_BOX_END);
+    }
+
 #define WARNING_BOX_START "<div id=\"previewWarningRow\" class=\"jwRow\">" \
          "<div id=\"previewWarningBox\" class=\"jwWarningBox\">"
 
 #define UNDER_DEV "Data and tools on this site are under development, have not been reviewed " \
          "for quality, and are subject to change at any time. "
 
 #define MAIN_SITE "The high-quality, reviewed public site of the UCSC Genome Browser is " \
          "available for use at <a href=\"http://genome.ucsc.edu/\">http://genome.ucsc.edu/</a>."
 
 #define WARNING_BOX_END "</div></div>"
 
 if (hIsPreviewHost())
     {
     puts(WARNING_BOX_START
          "WARNING: This is the UCSC Genome Browser preview site. "
@@ -367,30 +380,39 @@
 webIncludeResourceFile("jquery-ui.css");
 jsIncludeFile("jquery-ui.js", NULL);
 jsIncludeFile("jquery.watermarkinput.js", NULL);
 jsIncludeFile("autocompleteCat.js",NULL);
 jsIncludeFile("utils.js",NULL);
 
 // Phylogenetic tree .js file, produced by dbDbTaxonomy.pl:
 char *defaultDbDbTree = webTimeStampedLinkToResource("dbDbTaxonomy.js", FALSE);
 char *dbDbTree = cfgOptionDefault("hgGateway.dbDbTaxonomy", defaultDbDbTree);
 if (isNotEmpty(dbDbTree))
     printf("<script src=\"%s\"></script>\n", dbDbTree);
 
 // Main JS for hgGateway:
 jsIncludeFile("hgGateway.js", NULL);
 
+#define TIMING_WARNING_BOX_START "<div id='hogWarningRow' class='jwRow'>" \
+         "<div id='hogWarningBox' class='jwWarningBox'>"
+#define TIMING_WARNING_BOX_END "</div></div>"
+if (measureTiming)
+    {
+    printf("%selapsed time %ld ms (%d ms bottleneck)%s\n",
+	TIMING_WARNING_BOX_START, clock1000() - enteredMainTime,
+	botDelayMillis, TIMING_WARNING_BOX_END);
+    }
 webIncludeFile("inc/jWestFooter.html");
 
 cartFlushHubWarnings();
 
 webEndJWest();
 }
 
 void doMiddle(struct cart *theCart)
 /* Depending on invocation, either perform a query and print out results
  * or display the main page. */
 {
 cart = theCart;
 if (cgiOptionalString(CARTJSON_COMMAND))
     doCartJson();
 else
@@ -867,31 +889,32 @@
     writeDbDbMatch(jw, match, term, category);
 // Write out assembly hub matches, if any.
 writeAssemblyHubMatches(jw, aHubMatchList);
 jsonWriteListEnd(jw);
 puts(jw->dy->string);
 jsonWriteFree(&jw);
 }
 
 int main(int argc, char *argv[])
 /* Process CGI / command line. */
 {
 /* Null terminated list of CGI Variables we don't want to save
  * permanently. */
 char *excludeVars[] = {SEARCH_TERM, CARTJSON_COMMAND, NULL,};
 cgiSpoof(&argc, argv);
-long enteredMainTime = clock1000();
+measureTiming = cgiOptionalInt("measureTiming", 0);
+enteredMainTime = clock1000();
 if (cgiOptionalString(SEARCH_TERM))
     {
     /* less bottleneck penalty for this operation, same as hgTracks */
 #define delayFraction   0.25
     issueBotWarning = earlyBotCheck(enteredMainTime, "hgGateway", delayFraction, 0, 0, "json");
     // Skip the cart for speedy searches
     lookupTerm();
     }
 else
     {
     /* standard default bottleneck penalty for this operation */
     issueBotWarning = earlyBotCheck(enteredMainTime, "hgGateway", 0.0, 0, 0, "html");
     oldVars = hashNew(10);
     cartEmptyShellNoContent(doMiddle, hUserCookie(), excludeVars, oldVars);
     cgiExitTime("hgGateway", enteredMainTime);