Commit 75d291e2 authored by miller86's avatar miller86
Browse files

I fixed a performance issue in Namescheme utility where it would build

up and then tear down each conversion spec's evaluation tree upon an
invokation of the GetName method.

I fixed a leak destructing DebugStreams that has been there since 2004.

I added various of the unit test codes in src/common/utility to common's
CMakeList.txt so that they get compiled by default.

I added a new 'unit' class of tests and added the unit tests from
src/common/utility there.

I removed mdserver/main/testmds.C as whatever testing that afforded is
fully subsumbed by VisIt's normal testing.

I fixed a cut-n-paste error in top level CMakeLists.txt where include
paths for several dirs in src/common were incorrect.


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@13476 18c085ea-50e0-402c-830e-de6fd14e8384
parent 92188f5e
......@@ -1176,10 +1176,6 @@ SET(VISIT_COMMON_INCLUDES
${VISIT_SOURCE_DIR}/common/proxybase
${VISIT_SOURCE_DIR}/common/state
${VISIT_SOURCE_DIR}/common/utility
${VISIT_SOURCE_DIR}/common/common/misc
${VISIT_SOURCE_DIR}/common/common/plugin
${VISIT_SOURCE_DIR}/common/common/state
${VISIT_SOURCE_DIR}/common/common/utility
)
......
......@@ -316,6 +316,12 @@ ADD_LIBRARY(visitcommon
# Specify the libraries to link against on Windows
IF(WIN32)
TARGET_LINK_LIBRARIES(visitcommon ws2_32 shlwapi userenv)
ELSE(WIN32)
ADD_EXECUTABLE(StringHelpers_test utility/StringHelpers_test.C)
TARGET_LINK_LIBRARIES(StringHelpers_test visitcommon ${CMAKE_THREAD_LIBS} ${DL_LIB})
ADD_EXECUTABLE(Namescheme_test utility/Namescheme_test.C)
TARGET_LINK_LIBRARIES(Namescheme_test visitcommon ${CMAKE_THREAD_LIBS} ${DL_LIB})
ADD_EXECUTABLE(MRUCache_test utility/MRUCache_test.C)
ENDIF(WIN32)
VISIT_INSTALL_TARGETS(visitcommon)
......@@ -489,10 +489,14 @@ DebugStreamFull::DebugStreamFull(int level_) : ostream(new DebugStreamBuf)
// Change the DebugStreamBuf member to be a pointered value instead of a
// referenced value so that it works with the MIPSpro compiler.
//
// Mark C. Miller, Tue Jan 11 09:27:18 PST 2011
// Added missing call to delete buf. Since above change in 2004, we have
// been leaking these bufs on exit.
// ****************************************************************************
DebugStreamFull::~DebugStreamFull()
{
buf->close();
delete buf;
}
......
......@@ -80,7 +80,7 @@ int main()
// load caches and see how things behave
for (i = 0; i < 2*CACHE_SIZE; i++)
{
cerr << "Iteration " << i << endl;
cout << "Iteration " << i << endl;
char tmp[256];
sprintf(tmp, "item %02d", i);
string tmpStr = string(tmp);
......@@ -112,7 +112,7 @@ int main()
const int n = fullName.size();
vector<string> keysToRemove;
cerr << "Iterating to find and remove all keys beginning with \"" << fullName.c_str() << "\"" << endl;
cout << "Iterating to find and remove all keys beginning with \"" << fullName.c_str() << "\"" << endl;
for (it = delCache.begin(); it != delCache.end(); it++)
{
if (fullName.compare(0, n, it->first, 0, n) == 0)
......@@ -125,9 +125,9 @@ int main()
callbackCache.remove(keysToRemove[j]);
delCache.remove(keysToRemove[j]);
adelCache.remove(keysToRemove[j]);
cerr << "Removed item with key \"" << keysToRemove[j].c_str() << "\"" << endl;
cout << "Removed item with key \"" << keysToRemove[j].c_str() << "\"" << endl;
}
cerr << "Iterating to see what remains in cache" << endl;
cout << "Iterating to see what remains in cache" << endl;
for (it = delCache.begin(); it != delCache.end(); it++)
cerr << "Item with key \"" << it->first.c_str() << "\" still in cache" << endl;
cout << "Item with key \"" << it->first.c_str() << "\" still in cache" << endl;
}
......@@ -334,6 +334,7 @@ Namescheme::Namescheme(const char *fmt, ...)
this->arrnames = 0;
this->arrvals = 0;
this->exprstrs = 0;
this->exprtrees = 0;
va_list ap;
int i, j, k, n, pass, ncspecs, done;
......@@ -398,6 +399,8 @@ Namescheme::Namescheme(const char *fmt, ...)
// allocate various arrays needed by the naming scheme
this->exprstrs = (char **) calloc(this->ncspecs, sizeof(char*));
this->exprtrees = (Namescheme::DBexprnode **) calloc(this->ncspecs,
sizeof(Namescheme::DBexprnode*));
if (this->narrefs > 0)
{
this->arrnames = (char **) calloc(this->narrefs, sizeof(char*));
......@@ -432,8 +435,12 @@ Namescheme::Namescheme(const char *fmt, ...)
}
else if (fmt[i] == this->delim || fmt[i] == '\0')
{
char *exprstr1, *exprstr2;
this->exprstrs[ncspecs] = (char*)calloc(i-(n+1)+1, sizeof(char));
strncpy(this->exprstrs[ncspecs], &fmt[n+1], i-(n+1));
exprstr1 = exprstr2 = strdup(this->exprstrs[ncspecs]);
this->exprtrees[ncspecs] = BuildExprTree((const char **) &exprstr1);
free(exprstr2);
ncspecs++;
if (fmt[i] == '\0' ||
(fmt[i] == this->delim && fmt[i] == '\0'))
......@@ -465,8 +472,12 @@ Namescheme::~Namescheme()
FREE(embedstrs[i]);
FREE(embedstrs);
for (i = 0; i < ncspecs; i++)
{
FREE(exprstrs[i]);
FreeTree(exprtrees[i]);
}
FREE(exprstrs);
FREE(exprtrees);
for (i = 0; i < narrefs; i++)
{
FREE(arrnames[i]);
......@@ -487,7 +498,6 @@ Namescheme::~Namescheme()
// ****************************************************************************
const char *Namescheme::GetName(int natnum)
{
char *currentExpr, *tmpExpr;
static char retval[1024];
int i;
......@@ -504,21 +514,13 @@ const char *Namescheme::GetName(int natnum)
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
Namescheme::DBexprnode *exprtree;
int theVal;
currentExpr = strdup(this->exprstrs[i]);
tmpExpr = currentExpr;
exprtree = BuildExprTree((const char **)&currentExpr);
theVal = EvalExprTree(this, exprtree, natnum);
FreeTree(exprtree);
int theVal = EvalExprTree(this, this->exprtrees[i], natnum);
strncpy(tmpfmt, this->fmtptrs[i], this->fmtptrs[i+1] - this->fmtptrs[i]);
if (strcmp(tmpfmt, "%s") == 0)
sprintf(tmp, tmpfmt, this->embedstrs[theVal]);
else
sprintf(tmp, tmpfmt, theVal);
strcat(retval, tmp);
FREE(tmpExpr);
}
return retval;
}
......@@ -102,6 +102,7 @@ class UTILITY_API Namescheme
char **arrnames; // array names used by array refs
const int **arrvals; // pointer to actual array data assoc. with each name
char **exprstrs; // expressions to be evaluated for each conv. spec.
DBexprnode **exprtrees; // Built expression trees for each conv. spec.
};
#endif
......@@ -85,15 +85,6 @@ int main()
if (strcmp(ns->GetName(25), "level2,patch16") != 0) return 1; // F
if (strcmp(ns->GetName(26), "level3,patch0") != 0) return 1; // G
if (strcmp(ns->GetName(30), "level3,patch4") != 0) return 1; // H
#if 0
printf("\"%s\"\n", ns->GetName( 1));
printf("\"%s\"\n", ns->GetName( 3));
printf("\"%s\"\n", ns->GetName( 8));
printf("\"%s\"\n", ns->GetName( 9));
printf("\"%s\"\n", ns->GetName(20));
printf("\"%s\"\n", ns->GetName(25));
printf("\"%s\"\n", ns->GetName(26));
#endif
delete ns;
// Test multiple conversion specifiers
......
......@@ -44,6 +44,9 @@
#
# Mark C. Miller, Thu Jul 29 13:09:44 PDT 2010
# Removed LibPipelineStubs as mdserver is now linked with libvisit_vtk
#
# Mark C. Miller, Tue Jan 11 11:14:08 PST 2011
# Removed testmds. It is obsoleted by other testing.
#****************************************************************************/
SET(MDSERVER_SOURCES
......@@ -132,9 +135,4 @@ IF(VISIT_STATIC)
)
ENDIF(VISIT_STATIC)
IF (NOT WIN32)
ADD_EXECUTABLE(testmds EXCLUDE_FROM_ALL testmds.C)
TARGET_LINK_LIBRARIES(testmds mdserverproxy mdserverrpc visitcommon avtdbatts)
ENDIF (NOT WIN32)
VISIT_INSTALL_TARGETS(mdserver)
/*****************************************************************************
*
* Copyright (c) 2000 - 2010, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
#include <MDServerProxy.h>
#include <VisItException.h>
#include <HostProfile.h>
#include <string>
#ifndef WIN32
#include <unistd.h>
#endif
#include <VisItInit.h>
#include <avtSIL.h>
#include <cstdlib>
using std::string;
// ****************************************************************************
// Function: main
//
// Purpose:
// This is the main function for the test mdserver program.
//
// Notes:
//
// Programmer: Jeremy Meredith
// Creation:
//
// Modifications:
// Brad Whitlock, Fri May 11 13:48:50 PST 2001
// I added code to pass extra command line arguments down to the mdserver
// proxy object. This allows us to pass things like "-beta".
//
// Jeremy Meredith, Thu Feb 27 14:09:50 PST 2003
// Some compilers don't understand std::strings in conjuction with the
// <iostream.h> (instead of <iostream>) headers, so I worked around it.
//
// Brad Whitlock, Fri Mar 28 12:54:37 PDT 2003
// I updated things to conform the MDServerProxy's new interface.
//
// Jeremy Meredith, Thu Oct 9 14:05:05 PDT 2003
// Added ability to manually specify a client host name or to have it
// parsed from the SSH_CLIENT (or related) environment variables. Added
// ability to specify an SSH port.
//
// Jeremy Meredith, Thu May 24 10:16:11 EDT 2007
// Added ssh tunneling argument.
//
// Mark C. Miller, Thu Apr 3 14:36:48 PDT 2008
// Moved setting of component name to before Initialize
// ****************************************************************************
int
main(int argc, char *argv[])
{
string hostName("localhost");
if (argc < 2)
{
cout << "Usage: " << argv[0] << " <hostname> [options]" << endl;
exit(-1);
}
// Initialize error logging.
VisItInit::SetComponentName("mdserver");
VisItInit::Initialize(argc, argv);
MDServerProxy *mdserver = new MDServerProxy();
if(argc > 1)
{
hostName = string(argv[1]);
for(int i = 2; i < argc; ++i)
mdserver->AddArgument(argv[i]);
}
string cwd;
const MDServerProxy::FileList *fl;
avtDatabaseMetaData md;
TRY
{
cout << "----------------------------------------" << endl;
cout << "Creating MDServer" << endl;
mdserver->Create(argv[1], HostProfile::MachineName, "", false, 0, false);
cout << "----------------------------------------" << endl;
cout << "Getting Directory" << endl;
cwd = mdserver->GetDirectory();
cout << "\tdirectory == " << cwd.c_str() << endl;
cout << "----------------------------------------" << endl;
cout << "Changine directory to '/'" << endl;
mdserver->ChangeDirectory("/");
cout << "Getting Directory" << endl;
cwd = mdserver->GetDirectory();
cout << "\tdirectory == " << cwd.c_str() << endl;
cout << "----------------------------------------" << endl;
cout << "Reading Files" << endl;
fl = mdserver->GetFileList("*", false);
cout << "\tDIRECTORIES:\n";
for (int i=0; i<fl->dirs.size(); i++)
{
cout << "\t\t";
if (fl->dirs[i].CanAccess()) cout << "+ "; else cout << "- ";
cout << fl->dirs[i].name.c_str() << endl;
}
cout << "\tFILES:\n";
for (int i=0; i<fl->files.size(); i++)
{
cout << "\t\t";
if (fl->files[i].CanAccess()) cout << "+ "; else cout << "- ";
cout << fl->files[i].size << "\t\t"<< fl->files[i].name.c_str() << endl;
}
cout << "----------------------------------------" << endl;
cout << "Changine directory to '~meredith/visit/data/silo/3d'" << endl;
mdserver->ChangeDirectory("~meredith/visit/data/silo/3d");
cout << "Getting Directory" << endl;
cwd = mdserver->GetDirectory();
cout << "\tdirectory == " << cwd.c_str() << endl;
cout << "----------------------------------------" << endl;
cout << "Getting metadata for curv3d.silo" << endl;
md = *(mdserver->GetMetaData("curv3d.silo"));
cout << "Metadata = " << endl;
md.Print(cout);
cout << "----------------------------------------" << endl;
cout << "Getting SIL for curv3d.silo" << endl;
avtSIL s1(*(mdserver->GetSIL("curv3d.silo")));
cout << "SIL = " << endl;
s1.Print(cout);
cout << "----------------------------------------" << endl;
cout << "Getting metadata for ~meredith/visit/data/silo/2d/curv2d.silo"
<< endl;
md = *(mdserver->GetMetaData("~meredith/visit/data/silo/2d/curv2d.silo"));
cout << "Metadata = " << endl;
md.Print(cout);
cout << "----------------------------------------" << endl;
cout << "Getting SIL for ~meredith/data/curv2d.silo" << endl;
avtSIL s2(*(mdserver->GetSIL("~meredith/data/curv2d.silo")));
cout << "SIL = " << endl;
s2.Print(cout);
cout << "----------------------------------------" << endl;
cout << "Closing MDServer" << endl;
mdserver->Close();
}
CATCH2(VisItException, ve)
{
cerr << "Caught a VisItException of type: " << ve.GetExceptionType().c_str() << endl;
}
ENDTRY
cout << "Exiting...." << endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment