summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2010-03-01 18:42:18 -0800
committerJosh Stone <jistone@redhat.com>2010-03-02 16:05:18 -0800
commit9b3c54b2fc836e20a0a7895aa759938e62eaacf9 (patch)
treea9db703d81f4fbabe886c5acb77d6c5cb0964a07
parent6b067d7d20c10acb68d768003bf8031f155e5f39 (diff)
downloadsystemtap-steved-9b3c54b2fc836e20a0a7895aa759938e62eaacf9.tar.gz
systemtap-steved-9b3c54b2fc836e20a0a7895aa759938e62eaacf9.tar.xz
systemtap-steved-9b3c54b2fc836e20a0a7895aa759938e62eaacf9.zip
PR11246 cont'd: Separate script/stapconf caching
I'm separating the caching and creation logic for stapconf, so it can be conditionalized on s.use_cache instead of s.use_script_cache. * session.h (systemtap_session): Store base_hash for better reuse. * hash.cxx (get_base_hash): Get the base from the session, or build it. (find_hash): Split into separate script/stapconf versions. * cache.cxx (add_to_cache, get_from_cache): Ditto. * main.cxx (main): Adapt caller, and delay stapconf until pass-4.
-rw-r--r--cache.cxx44
-rw-r--r--cache.h7
-rw-r--r--elaborate.cxx1
-rw-r--r--hash.cxx40
-rw-r--r--hash.h3
-rw-r--r--main.cxx14
-rw-r--r--session.h2
7 files changed, 69 insertions, 42 deletions
diff --git a/cache.cxx b/cache.cxx
index 1b083d69..6b51f21c 100644
--- a/cache.cxx
+++ b/cache.cxx
@@ -46,14 +46,10 @@ static void clean_cache(systemtap_session& s);
void
-add_to_cache(systemtap_session& s)
+add_stapconf_to_cache(systemtap_session& s)
{
bool verbose = s.verbose > 1;
- // PR10543: clean the cache *before* we try putting something new into it.
- // We don't want to risk having the brand new contents being erased again.
- clean_cache(s);
-
string stapconf_src_path = s.tmpdir + "/" + s.stapconf_name;
if (!copy_file(stapconf_src_path, s.stapconf_path, verbose))
{
@@ -63,6 +59,17 @@ add_to_cache(systemtap_session& s)
// s.use_script_cache = false;
// return;
}
+}
+
+
+void
+add_script_to_cache(systemtap_session& s)
+{
+ bool verbose = s.verbose > 1;
+
+ // PR10543: clean the cache *before* we try putting something new into it.
+ // We don't want to risk having the brand new contents being erased again.
+ clean_cache(s);
string module_src_path = s.tmpdir + "/" + s.module_name + ".ko";
STAP_PROBE2(stap, cache__add__module, module_src_path.c_str(), s.hash_path.c_str());
@@ -92,16 +99,10 @@ add_to_cache(systemtap_session& s)
bool
-get_from_cache(systemtap_session& s)
+get_stapconf_from_cache(systemtap_session& s)
{
string stapconf_dest_path = s.tmpdir + "/" + s.stapconf_name;
- string module_dest_path = s.tmpdir + "/" + s.module_name + ".ko";
- string c_src_path = s.hash_path;
- int fd_stapconf, fd_module, fd_c;
-
- if (c_src_path.rfind(".ko") == (c_src_path.size() - 3))
- c_src_path.resize(c_src_path.size() - 3);
- c_src_path += ".c";
+ int fd_stapconf;
// See if stapconf exists
fd_stapconf = open(s.stapconf_path.c_str(), O_RDONLY);
@@ -122,7 +123,22 @@ get_from_cache(systemtap_session& s)
close(fd_stapconf);
if (s.verbose > 1)
- clog << "Pass 3: using cached " << s.stapconf_path << endl;
+ clog << "Pass 4: using cached " << s.stapconf_path << endl;
+
+ return true;
+}
+
+
+bool
+get_script_from_cache(systemtap_session& s)
+{
+ string module_dest_path = s.tmpdir + "/" + s.module_name + ".ko";
+ string c_src_path = s.hash_path;
+ int fd_module, fd_c;
+
+ if (c_src_path.rfind(".ko") == (c_src_path.size() - 3))
+ c_src_path.resize(c_src_path.size() - 3);
+ c_src_path += ".c";
// See if module exists
fd_module = open(s.hash_path.c_str(), O_RDONLY);
diff --git a/cache.h b/cache.h
index 89f44a43..548fa8c8 100644
--- a/cache.h
+++ b/cache.h
@@ -1,4 +1,7 @@
-void add_to_cache(systemtap_session& s);
-bool get_from_cache(systemtap_session& s);
+void add_script_to_cache(systemtap_session& s);
+bool get_script_from_cache(systemtap_session& s);
+
+void add_stapconf_to_cache(systemtap_session& s);
+bool get_stapconf_from_cache(systemtap_session& s);
/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
diff --git a/elaborate.cxx b/elaborate.cxx
index f442aceb..a2ab8522 100644
--- a/elaborate.cxx
+++ b/elaborate.cxx
@@ -1516,6 +1516,7 @@ semantic_pass (systemtap_session& s)
systemtap_session::systemtap_session ():
// NB: pointer members must be manually initialized!
+ base_hash(0),
pattern_root(new match_node),
user_file (0),
be_derived_probes(0),
diff --git a/hash.cxx b/hash.cxx
index 36a71a42..6c37dbc7 100644
--- a/hash.cxx
+++ b/hash.cxx
@@ -104,9 +104,15 @@ void create_hash_log(const string &type_str, const string &parms, const string &
log_file.close();
}
-static void
-get_base_hash (systemtap_session& s, hash& h)
+static const hash&
+get_base_hash (systemtap_session& s)
{
+ if (s.base_hash)
+ return *s.base_hash;
+
+ s.base_hash = new hash();
+ hash& h = *s.base_hash;
+
// Hash kernel release and arch.
h.add(s.kernel_release);
h.add(s.kernel_build_tree);
@@ -141,6 +147,8 @@ get_base_hash (systemtap_session& s, hash& h)
// know exactly where we're getting run from, we'll use
// /proc/self/exe.
h.add_file("/proc/self/exe");
+
+ return h;
}
@@ -178,10 +186,10 @@ create_hashdir (systemtap_session& s, const string& result, string& hashdir)
}
-static void
-find_script_hash (systemtap_session& s, const string& script, const hash &base)
+void
+find_script_hash (systemtap_session& s, const string& script)
{
- hash h(base);
+ hash h(get_base_hash(s));
struct stat st;
// Hash getuid. This really shouldn't be necessary (since who you
@@ -260,10 +268,10 @@ find_script_hash (systemtap_session& s, const string& script, const hash &base)
}
-static void
-find_stapconf_hash (systemtap_session& s, const hash& base)
+void
+find_stapconf_hash (systemtap_session& s)
{
- hash h(base);
+ hash h(get_base_hash(s));
// Add any custom kbuild flags
for (unsigned i = 0; i < s.kbuildflags.size(); i++)
@@ -282,21 +290,10 @@ find_stapconf_hash (systemtap_session& s, const hash& base)
}
-void
-find_hash (systemtap_session& s, const string& script)
-{
- hash base;
- get_base_hash(s, base);
- find_stapconf_hash(s, base);
- find_script_hash(s, script, base);
-}
-
-
string
find_tracequery_hash (systemtap_session& s, const vector<string>& headers)
{
- hash h;
- get_base_hash(s, h);
+ hash h(get_base_hash(s));
// Add the tracepoint headers to the computed hash
for (size_t i = 0; i < headers.size(); ++i)
@@ -321,8 +318,7 @@ find_tracequery_hash (systemtap_session& s, const vector<string>& headers)
string
find_typequery_hash (systemtap_session& s, const string& name)
{
- hash h;
- get_base_hash(s, h);
+ hash h(get_base_hash(s));
// Add the typequery name to distinguish the hash
h.add(name);
diff --git a/hash.h b/hash.h
index 0c1a745f..bbe4e89c 100644
--- a/hash.h
+++ b/hash.h
@@ -41,7 +41,8 @@ public:
std::string get_parms();
};
-void find_hash (systemtap_session& s, const std::string& script);
+void find_script_hash (systemtap_session& s, const std::string& script);
+void find_stapconf_hash (systemtap_session& s);
std::string find_tracequery_hash (systemtap_session& s,
const std::vector<std::string>& headers);
std::string find_typequery_hash (systemtap_session& s, const std::string& name);
diff --git a/main.cxx b/main.cxx
index 04431e72..6d3f649b 100644
--- a/main.cxx
+++ b/main.cxx
@@ -1300,10 +1300,10 @@ main (int argc, char * const argv [])
}
// Generate hash
- find_hash (s, o.str());
+ find_script_hash (s, o.str());
// See if we can use cached source/module.
- if (get_from_cache(s))
+ if (get_script_from_cache(s))
{
// If our last pass isn't 5, we're done (since passes 3 and
// 4 just generate what we just pulled out of the cache).
@@ -1352,6 +1352,12 @@ main (int argc, char * const argv [])
times (& tms_before);
gettimeofday (&tv_before, NULL);
STAP_PROBE1(stap, pass4__start, &s);
+
+ if (s.use_cache)
+ {
+ find_stapconf_hash(s);
+ get_stapconf_from_cache(s);
+ }
rc = compile_pass (s);
if (rc == 0 && s.last_pass == 4)
@@ -1377,7 +1383,9 @@ main (int argc, char * const argv [])
{
// Update cache. Cache cleaning is kicked off at the beginning of this function.
if (s.use_script_cache)
- add_to_cache(s);
+ add_script_to_cache(s);
+ if (s.use_cache)
+ add_stapconf_to_cache(s);
// We may need to save the module in $CWD if the cache was
// inaccessible for some reason.
diff --git a/session.h b/session.h
index f45f6c77..ccf6c1da 100644
--- a/session.h
+++ b/session.h
@@ -22,6 +22,7 @@ extern "C" {
// forward decls for all referenced systemtap types
+struct hash;
struct match_node;
struct stapfile;
struct vardecl;
@@ -131,6 +132,7 @@ struct systemtap_session
std::string cache_path;
std::string hash_path;
std::string stapconf_path;
+ hash *base_hash;
// dwarfless operation
bool consult_symtab;