Skip to content

Commit

Permalink
i#2006 drcachesim: add class analyzer
Browse files Browse the repository at this point in the history
Add class analyzer and make class simulator inherit from class analyzer
for broader trace based analysis tools.
  • Loading branch information
zhaoqin committed Sep 15, 2016
1 parent f96ec6e commit b11c906
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 15 deletions.
55 changes: 55 additions & 0 deletions clients/drcachesim/simulator/analyzer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* **********************************************************
* Copyright (c) 2016 Google, Inc. All rights reserved.
* **********************************************************/

/*
* 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 following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Google, Inc. 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 VMWARE, INC. 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.
*/

/* analyzer: represent a memory trace analysis tool.
*/

#ifndef _ANALYZER_H_
#define _ANALYZER_H_ 1

#include "ipc_reader.h"

class analyzer_t
{
public:
analyzer_t() {}
virtual bool init() = 0;
virtual ~analyzer_t() {};
virtual bool run() = 0;
virtual bool print_stats() = 0;

protected:
ipc_reader_t ipc_end;
ipc_reader_t ipc_iter;
};

#endif /* _ANALYZER_H_ */
28 changes: 14 additions & 14 deletions clients/drcachesim/simulator/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* DAMAGE.
*/

/* launcher: the front end for the cache simulator */
/* launcher: the front end for the trace analyzer */

// FIXME i#1727: the Windows implementation is not tested (needs
// the named pipe implementation to be finished).
Expand Down Expand Up @@ -155,7 +155,7 @@ _tmain(int argc, const TCHAR *targv[])
char buf[MAXIMUM_PATH];
drfront_status_t sc;
bool is64, is32;
simulator_t *simulator = NULL;
analyzer_t *analyzer = NULL;
std::string tracer_ops;

#if defined(WINDOWS) && !defined(_UNICODE)
Expand All @@ -168,7 +168,7 @@ _tmain(int argc, const TCHAR *targv[])
#endif

// This frontend exists mainly because we have a standalone application
// to launch, the simulator. We are not currently looking for a polished
// to launch, the analyzer. We are not currently looking for a polished
// tool launcher independent of drrun. Thus, we skip all the logic around
// default root and client directories and assume we were invoked from
// a pre-configured .drrun file with proper paths.
Expand Down Expand Up @@ -222,19 +222,19 @@ _tmain(int argc, const TCHAR *targv[])
assert(false); // won't get here
}

// declare the simulator based on its type
// declare the analyzer based on its type
if (op_simulator_type.get_value() == CPU_CACHE)
simulator = new cache_simulator_t;
analyzer = new cache_simulator_t;
else if (op_simulator_type.get_value() == TLB)
simulator = new tlb_simulator_t;
analyzer = new tlb_simulator_t;
else {
ERROR("Usage error: unsupported simulator type. "
ERROR("Usage error: unsupported analyzer type. "
"Please choose " CPU_CACHE" or " TLB".\n");
return false;
}

if (!simulator->init()) {
FATAL_ERROR("failed to initialize simulator");
if (!analyzer->init()) {
FATAL_ERROR("failed to initialize analyzer");
assert(false); // won't get here
}

Expand Down Expand Up @@ -268,8 +268,8 @@ _tmain(int argc, const TCHAR *targv[])
dr_inject_process_run(inject_data);
#endif

if (!simulator->run()) {
FATAL_ERROR("failed to run simulator");
if (!analyzer->run()) {
FATAL_ERROR("failed to run analyzer");
assert(false); // won't get here
}

Expand All @@ -290,10 +290,10 @@ _tmain(int argc, const TCHAR *targv[])
// XXX: we may want a prefix on our output
std::cerr << "---- <application exited with code " << errcode <<
"> ----" << std::endl;
simulator->print_stats();
analyzer->print_stats();

// release simulator's space
delete simulator;
// release analyzer's space
delete analyzer;

sc = drfront_cleanup_args(argv, argc);
if (sc != DRFRONT_SUCCESS)
Expand Down
3 changes: 2 additions & 1 deletion clients/drcachesim/simulator/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@
#define _SIMULATOR_H_ 1

#include <map>
#include "analyzer.h"
#include "caching_device_stats.h"
#include "caching_device.h"
#include "ipc_reader.h"

class simulator_t
class simulator_t : public analyzer_t
{
public:
simulator_t() {}
Expand Down

0 comments on commit b11c906

Please sign in to comment.