Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging execution traces #2

Open
mmore500 opened this issue Mar 29, 2020 · 4 comments
Open

logging execution traces #2

mmore500 opened this issue Mar 29, 2020 · 4 comments

Comments

@mmore500
Copy link
Contributor

lately I've found the following "hack-on" to old SGP's FindBestFuncMatch super useful for tracing which modules are activating/calling other modules. It's nice using a static seen data structure because it makes it really easy to evaluate over a population. This could possibly also be practicable without a static data structure, though, too. Later in the post-processing pipeline (or maybe if we're clever it would be convenient to be able to somehow in the logging process) we could just filter out duplicate caller/callee pairs.

Maybe we could wrap something of the like (but with proper logging instead of just printing, etc.) in a ifndef macro so it would be super easy to activate? Maybe there are other logging features we could activate via macro? or maybe a better way?

    /// Find best matching functions (by ID) given affinity.
    emp::vector<size_t> FindBestFuncMatch(const affinity_t & affinity) {
      // no need to transform to values because we're using
      // matchbin uids equivalent to function uids
      // also, we've delegated responsibility RE: the number of matches to
      // return to the MatchBin Selector
      const auto res = matchBin.Match(affinity);

      static std::set<
        std::pair<
          emp::BitSet<32>,
          emp::BitSet<32>
        >
      > seen;

      if (res.size()) {

        // std::cout << affinity << std::endl;

        const auto [it, success] = seen.insert({
          affinity,
          matchBin.GetTag(res[0])
        });

        if (success) std::cout << affinity << " " << matchBin.GetTag(res[0]) << std::endl;

      }

      return res;

    }
@mmore500
Copy link
Contributor Author

With some design guidance maybe this could be a good undergraduate project?

@amlalejini
Copy link
Owner

Macros to turn on or there might even be something clever we can do with template specialization. Would want to think about where the best place to inject the tracking is, though. Because the user could want to track different sources of function calls (e.g., might have various types of signals and want to differentiate which signal/call types trigger which functions).

But, yes! This would be a great candidate for undergrad project + a trace web visualization tool (that I would be more than happy to pair program out)!

@mmore500
Copy link
Contributor Author

mmore500 commented Apr 9, 2020

I've also been tracking regulation with a similar paste-in into MatchBin on Empirical, which I figured I'd throw on here in hopes of one day putting together a better way to accomplish this.

        static std::set<
          std::pair<
            emp::BitSet<32>,
            emp::BitSet<32>
          >
        > seen;

        if (cacheResult(n) && cacheResult(n).value().size()) {

          const auto [it, success] = seen.insert({
            query,
            GetTag(cacheResult(n).value()[0])
          });

          if (success) std::cout << "R: " << query << " " << GetTag(cacheResult(n).value()[0]) << std::endl;

        }

@mmore500
Copy link
Contributor Author

mmore500 commented Apr 9, 2020

one idea could be to just hook logging up to the debug macro so that if you compile in debug mode you get logging, too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants