2013-03-21 11:39:51 +08:00
|
|
|
//===-- formatters.cpp ------------------------------------------*- C++ -*-===//
|
2013-03-15 03:00:42 +08:00
|
|
|
//
|
2013-03-21 11:39:51 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2013-03-15 03:00:42 +08:00
|
|
|
//
|
2013-03-21 11:39:51 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2013-03-15 03:00:42 +08:00
|
|
|
//
|
2013-03-21 11:39:51 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2013-03-15 03:00:42 +08:00
|
|
|
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
|
|
|
|
#include "lldb-perf/lib/Timer.h"
|
|
|
|
#include "lldb-perf/lib/Metric.h"
|
|
|
|
#include "lldb-perf/lib/Measurement.h"
|
|
|
|
#include "lldb-perf/lib/TestCase.h"
|
|
|
|
#include "lldb-perf/lib/Xcode.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fstream>
|
|
|
|
|
2013-03-19 06:34:00 +08:00
|
|
|
using namespace lldb_perf;
|
2013-03-15 03:00:42 +08:00
|
|
|
|
|
|
|
class FormattersTest : public TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FormattersTest () : TestCase()
|
|
|
|
{
|
|
|
|
m_dump_std_vector_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
|
2013-03-19 06:34:00 +08:00
|
|
|
lldb_perf::Xcode::FetchVariable (value,1,false);
|
2013-03-15 03:00:42 +08:00
|
|
|
}, "std-vector", "time to dump an std::vector");
|
|
|
|
m_dump_std_list_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
|
2013-03-19 06:34:00 +08:00
|
|
|
lldb_perf::Xcode::FetchVariable (value,1,false);
|
2013-03-15 03:00:42 +08:00
|
|
|
}, "std-list", "time to dump an std::list");
|
|
|
|
m_dump_std_map_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
|
2013-03-19 06:34:00 +08:00
|
|
|
lldb_perf::Xcode::FetchVariable (value,1,false);
|
2013-03-15 03:00:42 +08:00
|
|
|
}, "std-map", "time to dump an std::map");
|
2013-03-21 07:01:28 +08:00
|
|
|
|
|
|
|
// use this in manual mode
|
|
|
|
m_dump_std_string_measurement = CreateTimeMeasurement([] () -> void {
|
2013-03-15 03:00:42 +08:00
|
|
|
}, "std-string", "time to dump an std::string");
|
|
|
|
|
|
|
|
m_dump_nsstring_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
|
2013-03-19 06:34:00 +08:00
|
|
|
lldb_perf::Xcode::FetchVariable (value,0,false);
|
2013-03-15 03:00:42 +08:00
|
|
|
}, "ns-string", "time to dump an NSString");
|
|
|
|
|
|
|
|
m_dump_nsarray_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
|
2013-03-19 06:34:00 +08:00
|
|
|
lldb_perf::Xcode::FetchVariable (value,1,false);
|
2013-03-15 03:00:42 +08:00
|
|
|
}, "ns-array", "time to dump an NSArray");
|
|
|
|
|
|
|
|
m_dump_nsdictionary_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
|
2013-03-19 06:34:00 +08:00
|
|
|
lldb_perf::Xcode::FetchVariable (value,1,false);
|
2013-03-15 03:00:42 +08:00
|
|
|
}, "ns-dictionary", "time to dump an NSDictionary");
|
|
|
|
|
|
|
|
m_dump_nsset_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
|
2013-03-19 06:34:00 +08:00
|
|
|
lldb_perf::Xcode::FetchVariable (value,1,false);
|
2013-03-15 03:00:42 +08:00
|
|
|
}, "ns-set", "time to dump an NSSet");
|
|
|
|
|
|
|
|
m_dump_nsbundle_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
|
2013-03-19 06:34:00 +08:00
|
|
|
lldb_perf::Xcode::FetchVariable (value,1,false);
|
2013-03-15 03:00:42 +08:00
|
|
|
}, "ns-bundle", "time to dump an NSBundle");
|
|
|
|
|
|
|
|
m_dump_nsdate_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
|
2013-03-19 06:34:00 +08:00
|
|
|
lldb_perf::Xcode::FetchVariable (value,0,false);
|
2013-03-15 03:00:42 +08:00
|
|
|
}, "ns-date", "time to dump an NSDate");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~FormattersTest ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-19 12:41:22 +08:00
|
|
|
virtual bool
|
2013-04-02 02:02:25 +08:00
|
|
|
Setup (int& argc, const char**& argv)
|
2013-03-15 03:00:42 +08:00
|
|
|
{
|
|
|
|
m_app_path.assign(argv[1]);
|
|
|
|
m_out_path.assign(argv[2]);
|
|
|
|
m_target = m_debugger.CreateTarget(m_app_path.c_str());
|
|
|
|
m_target.BreakpointCreateByName("main");
|
2013-03-19 12:41:22 +08:00
|
|
|
SBLaunchInfo launch_info(argv);
|
|
|
|
return Launch (launch_info);
|
2013-03-15 03:00:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DoTest ()
|
|
|
|
{
|
2013-03-19 12:41:22 +08:00
|
|
|
SBFrame frame_zero(m_thread.GetFrameAtIndex(0));
|
2013-03-15 03:00:42 +08:00
|
|
|
|
|
|
|
m_dump_nsarray_measurement(frame_zero.FindVariable("nsarray", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsarray_measurement(frame_zero.FindVariable("nsmutablearray", lldb::eDynamicCanRunTarget));
|
|
|
|
|
|
|
|
m_dump_nsdictionary_measurement(frame_zero.FindVariable("nsdictionary", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsdictionary_measurement(frame_zero.FindVariable("nsmutabledictionary", lldb::eDynamicCanRunTarget));
|
|
|
|
|
|
|
|
m_dump_nsstring_measurement(frame_zero.FindVariable("str0", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsstring_measurement(frame_zero.FindVariable("str1", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsstring_measurement(frame_zero.FindVariable("str2", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsstring_measurement(frame_zero.FindVariable("str3", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsstring_measurement(frame_zero.FindVariable("str4", lldb::eDynamicCanRunTarget));
|
|
|
|
|
|
|
|
m_dump_nsdate_measurement(frame_zero.FindVariable("me", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsdate_measurement(frame_zero.FindVariable("cutie", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsdate_measurement(frame_zero.FindVariable("mom", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsdate_measurement(frame_zero.FindVariable("dad", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsdate_measurement(frame_zero.FindVariable("today", lldb::eDynamicCanRunTarget));
|
|
|
|
|
|
|
|
m_dump_nsbundle_measurement(frame_zero.FindVariable("bundles", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsbundle_measurement(frame_zero.FindVariable("frameworks", lldb::eDynamicCanRunTarget));
|
|
|
|
|
|
|
|
m_dump_nsset_measurement(frame_zero.FindVariable("nsset", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_nsset_measurement(frame_zero.FindVariable("nsmutableset", lldb::eDynamicCanRunTarget));
|
|
|
|
|
|
|
|
m_dump_std_vector_measurement(frame_zero.FindVariable("vector", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_std_list_measurement(frame_zero.FindVariable("list", lldb::eDynamicCanRunTarget));
|
|
|
|
m_dump_std_map_measurement(frame_zero.FindVariable("map", lldb::eDynamicCanRunTarget));
|
|
|
|
|
2013-03-21 07:01:28 +08:00
|
|
|
auto sstr0 = frame_zero.FindVariable("sstr0", lldb::eDynamicCanRunTarget);
|
|
|
|
auto sstr1 = frame_zero.FindVariable("sstr1", lldb::eDynamicCanRunTarget);
|
|
|
|
auto sstr2 = frame_zero.FindVariable("sstr2", lldb::eDynamicCanRunTarget);
|
|
|
|
auto sstr3 = frame_zero.FindVariable("sstr3", lldb::eDynamicCanRunTarget);
|
|
|
|
auto sstr4 = frame_zero.FindVariable("sstr4", lldb::eDynamicCanRunTarget);
|
|
|
|
|
2013-03-21 11:32:24 +08:00
|
|
|
m_dump_std_string_measurement.Start();
|
2013-03-21 07:01:28 +08:00
|
|
|
Xcode::FetchVariable(sstr0,0,false);
|
2013-03-21 11:32:24 +08:00
|
|
|
m_dump_std_string_measurement.Stop();
|
2013-03-21 07:01:28 +08:00
|
|
|
|
2013-03-21 11:32:24 +08:00
|
|
|
m_dump_std_string_measurement.Start();
|
2013-03-21 07:01:28 +08:00
|
|
|
Xcode::FetchVariable(sstr1,0,false);
|
2013-03-21 11:32:24 +08:00
|
|
|
m_dump_std_string_measurement.Stop();
|
2013-03-21 07:01:28 +08:00
|
|
|
|
2013-03-21 11:32:24 +08:00
|
|
|
m_dump_std_string_measurement.Start();
|
2013-03-21 07:01:28 +08:00
|
|
|
Xcode::FetchVariable(sstr2,0,false);
|
2013-03-21 11:32:24 +08:00
|
|
|
m_dump_std_string_measurement.Stop();
|
2013-03-21 07:01:28 +08:00
|
|
|
|
2013-03-21 11:32:24 +08:00
|
|
|
m_dump_std_string_measurement.Start();
|
2013-03-21 07:01:28 +08:00
|
|
|
Xcode::FetchVariable(sstr3,0,false);
|
2013-03-21 11:32:24 +08:00
|
|
|
m_dump_std_string_measurement.Stop();
|
2013-03-21 07:01:28 +08:00
|
|
|
|
2013-03-21 11:32:24 +08:00
|
|
|
m_dump_std_string_measurement.Start();
|
2013-03-21 07:01:28 +08:00
|
|
|
Xcode::FetchVariable(sstr4,0,false);
|
2013-03-21 11:32:24 +08:00
|
|
|
m_dump_std_string_measurement.Stop();
|
2013-03-21 07:01:28 +08:00
|
|
|
|
2013-03-15 03:00:42 +08:00
|
|
|
}
|
|
|
|
|
2013-03-19 06:34:00 +08:00
|
|
|
virtual void
|
|
|
|
TestStep (int counter, ActionWanted &next_action)
|
2013-03-15 03:00:42 +08:00
|
|
|
{
|
2013-03-19 06:34:00 +08:00
|
|
|
switch (counter)
|
2013-03-15 03:00:42 +08:00
|
|
|
{
|
2013-03-19 06:34:00 +08:00
|
|
|
case 0:
|
2013-04-11 08:28:12 +08:00
|
|
|
m_target.BreakpointCreateByLocation("fmts_tester.mm", 78);
|
2013-03-19 06:34:00 +08:00
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
DoTest ();
|
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
DoTest ();
|
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
DoTest ();
|
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
DoTest ();
|
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
DoTest ();
|
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
DoTest ();
|
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
DoTest ();
|
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
DoTest ();
|
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
DoTest ();
|
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
DoTest ();
|
|
|
|
next_action.Continue();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
next_action.Kill();
|
|
|
|
break;
|
2013-03-15 03:00:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 10:31:35 +08:00
|
|
|
virtual void
|
|
|
|
WriteResults (Results &results)
|
2013-03-15 03:00:42 +08:00
|
|
|
{
|
2013-04-16 05:24:00 +08:00
|
|
|
m_dump_std_vector_measurement.WriteAverageAndStandardDeviation(results);
|
|
|
|
m_dump_std_list_measurement.WriteAverageAndStandardDeviation(results);
|
|
|
|
m_dump_std_map_measurement.WriteAverageAndStandardDeviation(results);
|
|
|
|
m_dump_std_string_measurement.WriteAverageAndStandardDeviation(results);
|
|
|
|
|
|
|
|
m_dump_nsstring_measurement.WriteAverageAndStandardDeviation(results);
|
|
|
|
m_dump_nsarray_measurement.WriteAverageAndStandardDeviation(results);
|
|
|
|
m_dump_nsdictionary_measurement.WriteAverageAndStandardDeviation(results);
|
|
|
|
m_dump_nsset_measurement.WriteAverageAndStandardDeviation(results);
|
|
|
|
m_dump_nsbundle_measurement.WriteAverageAndStandardDeviation(results);
|
|
|
|
m_dump_nsdate_measurement.WriteAverageAndStandardDeviation(results);
|
2013-03-22 10:31:35 +08:00
|
|
|
results.Write(m_out_path.c_str());
|
2013-03-15 03:00:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// C++ formatters
|
|
|
|
TimeMeasurement<std::function<void(SBValue)>> m_dump_std_vector_measurement;
|
|
|
|
TimeMeasurement<std::function<void(SBValue)>> m_dump_std_list_measurement;
|
|
|
|
TimeMeasurement<std::function<void(SBValue)>> m_dump_std_map_measurement;
|
2013-03-21 07:01:28 +08:00
|
|
|
TimeMeasurement<std::function<void()>> m_dump_std_string_measurement;
|
2013-03-15 03:00:42 +08:00
|
|
|
|
|
|
|
// Cocoa formatters
|
|
|
|
TimeMeasurement<std::function<void(SBValue)>> m_dump_nsstring_measurement;
|
|
|
|
TimeMeasurement<std::function<void(SBValue)>> m_dump_nsarray_measurement;
|
|
|
|
TimeMeasurement<std::function<void(SBValue)>> m_dump_nsdictionary_measurement;
|
|
|
|
TimeMeasurement<std::function<void(SBValue)>> m_dump_nsset_measurement;
|
|
|
|
TimeMeasurement<std::function<void(SBValue)>> m_dump_nsbundle_measurement;
|
|
|
|
TimeMeasurement<std::function<void(SBValue)>> m_dump_nsdate_measurement;
|
|
|
|
|
|
|
|
// useful files
|
|
|
|
std::string m_app_path;
|
|
|
|
std::string m_out_path;
|
|
|
|
};
|
|
|
|
|
|
|
|
// argv[1] == path to app
|
|
|
|
// argv[2] == path to result
|
|
|
|
int main(int argc, const char * argv[])
|
|
|
|
{
|
|
|
|
FormattersTest frmtest;
|
|
|
|
frmtest.SetVerbose(true);
|
|
|
|
TestCase::Run(frmtest,argc,argv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|