forked from OSchip/llvm-project
Make the stepping perf test case actually work.
llvm-svn: 177964
This commit is contained in:
parent
8d9716265e
commit
08f5fa7a6e
|
@ -8,14 +8,18 @@
|
|||
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <getopt.h>
|
||||
|
||||
using namespace lldb_perf;
|
||||
|
||||
class StepTest : public TestCase
|
||||
{
|
||||
typedef void (*no_function) (void);
|
||||
|
||||
public:
|
||||
StepTest() :
|
||||
m_do_one_step_over_measurement (std::function<void(StepTest &, int)>(&StepTest::DoOneStep))
|
||||
StepTest(bool use_single_stepping = false) :
|
||||
m_main_source("stepping-testcase.cpp"),
|
||||
m_use_single_stepping(use_single_stepping)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -25,11 +29,32 @@ public:
|
|||
virtual bool
|
||||
Setup (int argc, const char **argv)
|
||||
{
|
||||
m_app_path.assign(argv[1]);
|
||||
m_out_path.assign(argv[2]);
|
||||
TestCase::Setup (argc, argv);
|
||||
|
||||
// Toggle the fast stepping command on or off as required.
|
||||
const char *single_step_cmd = "settings set target.use-fast-stepping false";
|
||||
const char *fast_step_cmd = "settings set target.use-fast-stepping true";
|
||||
const char *cmd_to_use;
|
||||
|
||||
if (m_use_single_stepping)
|
||||
cmd_to_use = single_step_cmd;
|
||||
else
|
||||
cmd_to_use = fast_step_cmd;
|
||||
|
||||
SBCommandReturnObject return_object;
|
||||
m_debugger.GetCommandInterpreter().HandleCommand(cmd_to_use,
|
||||
return_object);
|
||||
if (!return_object.Succeeded())
|
||||
{
|
||||
if (return_object.GetError() != NULL)
|
||||
printf ("Got an error running settings set: %s.\n", return_object.GetError());
|
||||
else
|
||||
printf ("Failed running settings set, no error.\n");
|
||||
}
|
||||
|
||||
m_target = m_debugger.CreateTarget(m_app_path.c_str());
|
||||
m_first_bp = m_target.BreakpointCreateBySourceRegex("Here is some code to stop at originally.", m_main_source);
|
||||
|
||||
const char* file_arg = m_app_path.c_str();
|
||||
const char* empty = nullptr;
|
||||
const char* args[] = {file_arg, empty};
|
||||
|
@ -38,45 +63,267 @@ public:
|
|||
return Launch (launch_info);
|
||||
}
|
||||
|
||||
void
|
||||
DoOneStep (int sequence)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WriteResults (Results &results)
|
||||
{
|
||||
// results.Write(m_out_path.c_str());
|
||||
// Gotta turn off the last timer now.
|
||||
size_t num_time_measurements = m_time_measurements.size();
|
||||
|
||||
m_time_measurements[num_time_measurements - 1].Stop();
|
||||
|
||||
Results::Dictionary& results_dict = results.GetDictionary();
|
||||
const char *short_format_string = "step-time-%d";
|
||||
const size_t short_size = strlen(short_format_string) + 5;
|
||||
char short_buffer[short_size];
|
||||
const char *long_format_string = "The time it takes for step %d in the step sequence.";
|
||||
const size_t long_size = strlen(long_format_string) + 5;
|
||||
char long_buffer[long_size];
|
||||
|
||||
for (size_t i = 0; i < num_time_measurements; i++)
|
||||
{
|
||||
snprintf (short_buffer, short_size, short_format_string, i);
|
||||
snprintf (long_buffer, long_size, long_format_string, i);
|
||||
|
||||
results_dict.AddDouble(short_buffer,
|
||||
long_buffer,
|
||||
m_time_measurements[i].GetGauge().GetDeltaValue());
|
||||
|
||||
}
|
||||
|
||||
results.Write(m_out_path.c_str());
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
GetExecutablePath () const
|
||||
{
|
||||
if (m_app_path.empty())
|
||||
return NULL;
|
||||
return m_app_path.c_str();
|
||||
}
|
||||
|
||||
const char *
|
||||
GetResultFilePath () const
|
||||
{
|
||||
if (m_out_path.empty())
|
||||
return NULL;
|
||||
return m_out_path.c_str();
|
||||
}
|
||||
|
||||
void
|
||||
SetExecutablePath (const char *path)
|
||||
{
|
||||
if (path && path[0])
|
||||
m_app_path = path;
|
||||
else
|
||||
m_app_path.clear();
|
||||
}
|
||||
|
||||
void
|
||||
SetResultFilePath (const char *path)
|
||||
{
|
||||
if (path && path[0])
|
||||
m_out_path = path;
|
||||
else
|
||||
m_out_path.clear();
|
||||
}
|
||||
|
||||
void
|
||||
SetUseSingleStep (bool use_it)
|
||||
{
|
||||
m_use_single_stepping = use_it;
|
||||
}
|
||||
private:
|
||||
virtual void
|
||||
TestStep (int counter, ActionWanted &next_action)
|
||||
{
|
||||
if (counter > 0)
|
||||
m_time_measurements[counter - 1].Stop();
|
||||
|
||||
if (counter == 0)
|
||||
m_first_bp.SetEnabled(false);
|
||||
|
||||
m_time_measurements.push_back(TimeMeasurement<no_function>());
|
||||
next_action.StepOver(m_process.GetThreadAtIndex(0));
|
||||
m_time_measurements[counter].Start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
TimeMeasurement<std::function<void(StepTest &, int)> > m_do_one_step_over_measurement;
|
||||
SBBreakpoint m_first_bp;
|
||||
SBFileSpec m_main_source;
|
||||
std::vector<TimeMeasurement<no_function> > m_time_measurements;
|
||||
bool m_use_single_stepping;
|
||||
std::string m_app_path;
|
||||
std::string m_out_path;
|
||||
|
||||
|
||||
};
|
||||
|
||||
// argv[1] == path to app
|
||||
// argv[2] == path to result
|
||||
struct Options
|
||||
{
|
||||
std::string test_file_path;
|
||||
std::string out_file;
|
||||
bool verbose;
|
||||
bool fast_step;
|
||||
bool error;
|
||||
bool print_help;
|
||||
|
||||
Options() :
|
||||
verbose (false),
|
||||
fast_step (true),
|
||||
error (false),
|
||||
print_help (false)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static struct option g_long_options[] = {
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "single-step", no_argument, NULL, 's' },
|
||||
{ "test-file", required_argument, NULL, 't' },
|
||||
{ "out-file", required_argument, NULL, 'o' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
|
||||
std::string
|
||||
GetShortOptionString (struct option *long_options)
|
||||
{
|
||||
std::string option_string;
|
||||
for (int i = 0; long_options[i].name != NULL; ++i)
|
||||
{
|
||||
if (long_options[i].flag == NULL)
|
||||
{
|
||||
option_string.push_back ((char) long_options[i].val);
|
||||
switch (long_options[i].has_arg)
|
||||
{
|
||||
default:
|
||||
case no_argument:
|
||||
break;
|
||||
case required_argument:
|
||||
option_string.push_back (':');
|
||||
break;
|
||||
case optional_argument:
|
||||
option_string.append (2, ':');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return option_string;
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
if (argc != 3)
|
||||
{
|
||||
printf ("Wrong number of arguments, should be \"path to app\", \"path to result.\"\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Prepare for & make calls to getopt_long.
|
||||
|
||||
std::string short_option_string (GetShortOptionString(g_long_options));
|
||||
|
||||
StepTest test;
|
||||
TestCase::Run(test,argc,argv);
|
||||
|
||||
Options option_data;
|
||||
bool done = false;
|
||||
|
||||
#if __GLIBC__
|
||||
optind = 0;
|
||||
#else
|
||||
optreset = 1;
|
||||
optind = 1;
|
||||
#endif
|
||||
while (!done)
|
||||
{
|
||||
int long_options_index = -1;
|
||||
const int short_option = ::getopt_long_only (argc,
|
||||
const_cast<char **>(argv),
|
||||
short_option_string.c_str(),
|
||||
g_long_options,
|
||||
&long_options_index);
|
||||
|
||||
switch (short_option)
|
||||
{
|
||||
case 0:
|
||||
// Already handled
|
||||
break;
|
||||
|
||||
case -1:
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
option_data.print_help = true;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
option_data.print_help = true;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
option_data.verbose = true;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
option_data.fast_step = false;
|
||||
test.SetUseSingleStep(true);
|
||||
break;
|
||||
|
||||
case 't':
|
||||
{
|
||||
SBFileSpec file(optarg);
|
||||
if (file.Exists())
|
||||
test.SetExecutablePath(optarg);
|
||||
else
|
||||
fprintf(stderr, "error: file specified in --test-file (-t) option doesn't exist: '%s'\n", optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
test.SetResultFilePath(optarg);
|
||||
break;
|
||||
|
||||
default:
|
||||
option_data.error = true;
|
||||
option_data.print_help = true;
|
||||
fprintf (stderr, "error: unrecognized option %c\n", short_option);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (option_data.print_help)
|
||||
{
|
||||
puts(R"(
|
||||
NAME
|
||||
lldb-perf-stepping -- a tool that measures LLDB peformance of simple stepping operations.
|
||||
|
||||
SYNOPSIS
|
||||
lldb-perf-stepping --test-file=FILE [--out-file=PATH --verbose --fast-step]
|
||||
|
||||
DESCRIPTION
|
||||
Runs a set of stepping operations, timing each step and outputs results
|
||||
to a plist file.
|
||||
)");
|
||||
exit(0);
|
||||
}
|
||||
if (option_data.error)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (test.GetExecutablePath() == NULL)
|
||||
{
|
||||
// --clang is mandatory
|
||||
option_data.print_help = true;
|
||||
option_data.error = true;
|
||||
fprintf (stderr, "error: the '--test-file=PATH' option is mandatory\n");
|
||||
}
|
||||
|
||||
// Update argc and argv after parsing options
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
test.SetVerbose(true);
|
||||
TestCase::Run(test, argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
struct struct_for_copying
|
||||
{
|
||||
struct_for_copying (int in_int, double in_double, const char *in_string) :
|
||||
int_value(in_int),
|
||||
double_value(in_double),
|
||||
string_value (in_string)
|
||||
{
|
||||
|
||||
}
|
||||
struct_for_copying()
|
||||
{
|
||||
struct_for_copying (0, 0, "");
|
||||
}
|
||||
|
||||
int int_value;
|
||||
double double_value;
|
||||
std::string string_value;
|
||||
};
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
struct_for_copying input_struct (150 * argc, 10.0 * argc, argv[0]);
|
||||
struct_for_copying output_struct;
|
||||
int some_int = 44;
|
||||
double some_double = 34.5;
|
||||
double other_double;
|
||||
size_t vector_size;
|
||||
std::vector<struct_for_copying> my_vector;
|
||||
|
||||
printf ("Here is some code to stop at originally. Got: %d, %p.\n", argc, argv);
|
||||
output_struct = input_struct;
|
||||
other_double = (some_double * some_int)/((double) argc);
|
||||
other_double = other_double > 0 ? some_double/other_double : some_double > 0 ? other_double/some_double : 10.0;
|
||||
my_vector.push_back (input_struct);
|
||||
vector_size = my_vector.size();
|
||||
|
||||
return vector_size == 0 ? 0 : 1;
|
||||
}
|
|
@ -66,6 +66,7 @@
|
|||
4C86C5CB16F7C1D300844407 /* LLDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C86C5C616F7A37800844407 /* LLDB.framework */; };
|
||||
4C86C5CC16F7C1E000844407 /* LLDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C86C5C616F7A37800844407 /* LLDB.framework */; };
|
||||
4C86C5DA16F7CED300844407 /* fmts_tester.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4C1E37B316F79E4600FF10BB /* fmts_tester.mm */; };
|
||||
4CDDF51017011EBB00D95015 /* stepping-testcase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE3708716FB70E100BFD501 /* stepping-testcase.cpp */; };
|
||||
4CE3707316FB701000BFD501 /* lldb-perf-stepping.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE3707216FB701000BFD501 /* lldb-perf-stepping.cpp */; };
|
||||
4CE3707516FB703B00BFD501 /* liblldbperf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C1E373916F4035D00FF10BB /* liblldbperf.a */; };
|
||||
4CE3707616FB704300BFD501 /* LLDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 264B3DE816F7E47600D1E7AB /* LLDB.framework */; };
|
||||
|
@ -246,12 +247,8 @@
|
|||
4C86C5C616F7A37800844407 /* LLDB.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LLDB.framework; path = build/Debug/LLDB.framework; sourceTree = "<group>"; };
|
||||
4C86C5D116F7CC8900844407 /* format-tester */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "format-tester"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
4CE3705416FB6FA100BFD501 /* lldb-perf-step */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "lldb-perf-step"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
4CE3705616FB6FA100BFD501 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
|
||||
4CE3705816FB6FA100BFD501 /* lldb_step_test.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = lldb_step_test.1; sourceTree = "<group>"; };
|
||||
4CE3707216FB701000BFD501 /* lldb-perf-stepping.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "lldb-perf-stepping.cpp"; path = "stepping/lldb-perf-stepping.cpp"; sourceTree = "<group>"; };
|
||||
4CE3707C16FB70AD00BFD501 /* stepping-testcase */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "stepping-testcase"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
4CE3707E16FB70AD00BFD501 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
|
||||
4CE3708016FB70AD00BFD501 /* stepping_testcase.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = stepping_testcase.1; sourceTree = "<group>"; };
|
||||
4CE3708716FB70E100BFD501 /* stepping-testcase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "stepping-testcase.cpp"; path = "stepping/stepping-testcase.cpp"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
@ -346,8 +343,6 @@
|
|||
26DBAD4616FA637D008243D2 /* common */,
|
||||
4C1E375A16F4081300FF10BB /* cfcpp */,
|
||||
4C1E374116F407C800FF10BB /* lib */,
|
||||
4CE3705516FB6FA100BFD501 /* lldb-step-test */,
|
||||
4CE3707D16FB70AD00BFD501 /* stepping-testcase */,
|
||||
4C1E373A16F4035D00FF10BB /* Products */,
|
||||
4C1E37DD16F7A03900FF10BB /* Frameworks */,
|
||||
);
|
||||
|
@ -466,15 +461,6 @@
|
|||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
4CE3705516FB6FA100BFD501 /* lldb-step-test */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4CE3705616FB6FA100BFD501 /* main.cpp */,
|
||||
4CE3705816FB6FA100BFD501 /* lldb_step_test.1 */,
|
||||
);
|
||||
path = "lldb-step-test";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
4CE3707416FB701E00BFD501 /* stepping */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -484,15 +470,6 @@
|
|||
name = stepping;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
4CE3707D16FB70AD00BFD501 /* stepping-testcase */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4CE3707E16FB70AD00BFD501 /* main.cpp */,
|
||||
4CE3708016FB70AD00BFD501 /* stepping_testcase.1 */,
|
||||
);
|
||||
path = "stepping-testcase";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
|
@ -797,6 +774,7 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
4CDDF51017011EBB00D95015 /* stepping-testcase.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1075,6 +1053,7 @@
|
|||
"$(inherited)",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.9;
|
||||
OTHER_LDFLAGS = "-Wl,-rpath,@loader_path/../../../../build/Debug";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = macosx;
|
||||
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../ $(SRCROOT)/../../include/";
|
||||
|
@ -1087,6 +1066,7 @@
|
|||
CLANG_ENABLE_MODULES = YES;
|
||||
GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.9;
|
||||
OTHER_LDFLAGS = "-Wl,-rpath,@loader_path/../../../../build/Debug";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = macosx;
|
||||
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../ $(SRCROOT)/../../include/";
|
||||
|
|
Loading…
Reference in New Issue