From d7d2733a5c84235614908217de331eb7bf775ee5 Mon Sep 17 00:00:00 2001 From: jaumenin Date: Fri, 28 Oct 2011 17:27:42 +0200 Subject: [PATCH] Simulation script to profile simulation time --- src/lte/examples/lena-runtime-profiler.cc | 194 ++++++++++++++++++++++ src/lte/examples/wscript | 4 +- src/lte/helper/lena-helper.cc | 13 +- src/lte/helper/lena-helper.h | 5 + src/lte/helper/mac-stats-calculator.cc | 12 ++ src/lte/helper/mac-stats-calculator.h | 4 + src/lte/helper/rlc-stats-calculator.cc | 12 ++ src/lte/helper/rlc-stats-calculator.h | 4 + src/lte/test/lte-test-run-time.pl | 45 +++++ 9 files changed, 289 insertions(+), 4 deletions(-) create mode 100644 src/lte/examples/lena-runtime-profiler.cc create mode 100755 src/lte/test/lte-test-run-time.pl diff --git a/src/lte/examples/lena-runtime-profiler.cc b/src/lte/examples/lena-runtime-profiler.cc new file mode 100644 index 000000000..5d544a56a --- /dev/null +++ b/src/lte/examples/lena-runtime-profiler.cc @@ -0,0 +1,194 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Jaume Nin + */ + +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/mobility-module.h" +#include "ns3/lte-module.h" +#include "ns3/config-store.h" +#include "ns3/gtk-config-store.h" + +#include +#include +#include + +using namespace ns3; +using std::vector; + +int +main (int argc, char *argv[]) +{ + uint32_t nEnbPerFloor = 1; + uint32_t nUe = 1; + uint32_t nFloors = 0; + double simTime = 1.0; + std::string traceDirectory = ""; + CommandLine cmd; + + cmd.AddValue("nEnb", "Number of eNodeBs per floor", nEnbPerFloor); + cmd.AddValue("nUe", "Number of UEs", nUe); + cmd.AddValue("nFloors", "Number of floors, 0 for Friis propagation model", + nFloors); + cmd.AddValue("simTime", "Total duration of the simulation (in seconds)", + simTime); + cmd.AddValue("traceDirectory", + "Destination folder where the traces will be stored", traceDirectory); + cmd.Parse(argc, argv); + + ConfigStore inputConfig; + inputConfig.ConfigureDefaults(); + + // parse again so you can override default values from the command line + cmd.Parse(argc, argv); + + // Geometry of the scenario (in meters) + // Assume squared building + double nodeHeight = 1.5; + double roomHeight = 3; + double roomLength = 8; + uint32_t nRooms = ceil (sqrt (nEnbPerFloor)); + uint32_t nEnb; + + Ptr < LenaHelper > lena = CreateObject (); + lena->EnableLogComponents (); + if (nFloors == 0) + { + lena->SetAttribute("PropagationModel", + StringValue("ns3::FriisPropagationLossModel")); + nEnb = nEnbPerFloor; + } + else + { + lena->SetAttribute("PropagationModel", + StringValue("ns3::BuildingsPropagationLossModel")); + nEnb = nFloors * nEnbPerFloor; + } + + // Create Nodes: eNodeB and UE + NodeContainer enbNodes; + vector < NodeContainer > ueNodes; + + enbNodes.Create(nEnb); + for (uint32_t i = 0; i < nEnb; i++) + { + NodeContainer ueNode; + ueNode.Create(nUe); + ueNodes.push_back(ueNode); + } + + MobilityHelper mobility; + vector enbPosition; + Ptr < ListPositionAllocator > positionAlloc = CreateObject (); + + if (nFloors == 0) + { + mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); + // Position of eNBs + uint32_t plantedEnb = 0; + for (uint32_t row = 0; row < nRooms; row++) + { + for (uint32_t column = 0; column < nRooms && plantedEnb < nEnbPerFloor; column++, plantedEnb++) + { + Vector v(roomLength * (column + 0.5), roomLength * (row + 0.5), nodeHeight); + positionAlloc->Add(v); + enbPosition.push_back(v); + } + } + mobility.SetPositionAllocator(positionAlloc); + mobility.Install (enbNodes); + } + else + { + Ptr < Building > building = Create (0.0, nRooms * roomLength, + 0.0, nRooms * roomLength, + 0.0, nFloors* roomHeight); + building->SetBuildingType(Building::Residential); + building->SetExtWallsType(Building::ConcreteWithWindows); + building->SetFloorsNumber(nFloors); + building->SetNumberRoomX(nRooms); + building->SetNumberRoomY(nRooms); + mobility.SetMobilityModel("ns3::BuildingsMobilityModel"); + for (uint32_t floor = 0; floor < nFloors; floor++) + { + uint32_t plantedEnb = 0; + for (uint32_t row = 0; row < nRooms; row++) + { + for (uint32_t column = 0; column < nRooms && plantedEnb < nEnbPerFloor; column++, plantedEnb++) + { + Vector v (roomLength * (column + 0.5), + roomLength * (row + 0.5), + nodeHeight + roomHeight * floor); + positionAlloc->Add(v); + enbPosition.push_back(v); + } + } + } + mobility.SetPositionAllocator(positionAlloc); + mobility.Install (enbNodes); + + + } + + // Position of UEs attached to eNB + for (uint32_t i = 0; i < nEnb; i++) + { + + UniformVariable posX(enbPosition[i].x - roomLength * 0.5, + enbPosition[i].x + roomLength * 0.5); + UniformVariable posY(enbPosition[i].y - roomLength * 0.5, + enbPosition[i].y + roomLength * 0.5); +/* for (uint32_t j = 0; j < nUe; j++) + {*/ + positionAlloc->Add( + Vector(enbPosition[i].x, enbPosition[i].y, enbPosition[i].z)); + //Vector(posX.GetValue(), posY.GetValue(), nodeHeight)); + //} + mobility.Install(ueNodes[i]); + } + + + // Create Devices and install them in the Nodes (eNB and UE) + NetDeviceContainer enbDevs; + vector < NetDeviceContainer > ueDevs; + //NetDeviceContainer ueDevs2; + enbDevs = lena->InstallEnbDevice(enbNodes); + for (uint32_t i = 0; i < nEnb; i++) + { + NetDeviceContainer ueDev = lena->InstallUeDevice(ueNodes[i]); + ueDevs.push_back(ueDev); + lena->Attach(ueDev, enbDevs.Get(i)); + enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; + EpsBearer bearer(q); + lena->ActivateEpsBearer(ueDev, bearer); + } + + Simulator::Stop(Seconds(simTime)); + lena->SetTraceDirectory(traceDirectory); + lena->EnableRlcTraces(); + lena->EnableMacTraces(); + + Simulator::Run(); + + /*GtkConfigStore config; + config.ConfigureAttributes ();*/ + + Simulator::Destroy(); + return 0; +} diff --git a/src/lte/examples/wscript b/src/lte/examples/wscript index aa22a6e8f..78870f127 100644 --- a/src/lte/examples/wscript +++ b/src/lte/examples/wscript @@ -10,6 +10,6 @@ def build(bld): obj = bld.create_ns3_program('lena-rlc-calculator', ['lte']) obj.source = 'lena-rlc-calculator.cc' - obj = bld.create_ns3_program('profiling-reference', + obj = bld.create_ns3_program('lena-runtime-profiler', ['lte']) - obj.source = 'profiling-reference.cc' + obj.source = 'lena-runtime-profiler.cc' diff --git a/src/lte/helper/lena-helper.cc b/src/lte/helper/lena-helper.cc index 162c23b56..9605a98bf 100644 --- a/src/lte/helper/lena-helper.cc +++ b/src/lte/helper/lena-helper.cc @@ -421,10 +421,10 @@ LenaHelper::EnableLogComponents (void) LogComponentEnable ("LteSinrChunkProcessor", LOG_LEVEL_ALL); LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL); - LogComponentEnable ("LossModel", LOG_LEVEL_ALL); +// LogComponentEnable ("LossModel", LOG_LEVEL_ALL); LogComponentEnable ("ShadowingLossModel", LOG_LEVEL_ALL); LogComponentEnable ("PenetrationLossModel", LOG_LEVEL_ALL); - LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL); +// LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL); LogComponentEnable ("PathLossModel", LOG_LEVEL_ALL); LogComponentEnable ("LteNetDevice", LOG_LEVEL_ALL); @@ -643,6 +643,15 @@ LenaHelper::EnableUlMacTraces (void) MakeBoundCallback (&UlSchedulingCallback, m_macStats)); } +void +LenaHelper::SetTraceDirectory (std::string path) +{ + m_macStats->SetDlOutputFilename(path + m_macStats->GetDlOutputFilename()); + m_macStats->SetUlOutputFilename(path + m_macStats->GetUlOutputFilename()); + m_rlcStats->SetDlOutputFilename(path + m_rlcStats->GetDlOutputFilename()); + m_rlcStats->SetUlOutputFilename(path + m_rlcStats->GetUlOutputFilename()); +} + Ptr LenaHelper::GetRlcStats (void) { diff --git a/src/lte/helper/lena-helper.h b/src/lte/helper/lena-helper.h index a023f151e..5db9ba9ec 100644 --- a/src/lte/helper/lena-helper.h +++ b/src/lte/helper/lena-helper.h @@ -183,6 +183,11 @@ public: */ void EnableUlRlcTraces (void); + /** + * Set the output directory for the MAC/RLC trace + */ + void SetTraceDirectory (std::string path); + Ptr GetRlcStats (void); protected: diff --git a/src/lte/helper/mac-stats-calculator.cc b/src/lte/helper/mac-stats-calculator.cc index 2d8e3521b..a45c39494 100644 --- a/src/lte/helper/mac-stats-calculator.cc +++ b/src/lte/helper/mac-stats-calculator.cc @@ -70,12 +70,24 @@ MacStatsCalculator::SetUlOutputFilename (std::string outputFilename) m_ulOutputFilename = outputFilename; } +std::string +MacStatsCalculator::GetUlOutputFilename (void) +{ + return m_ulOutputFilename; +} + void MacStatsCalculator::SetDlOutputFilename (std::string outputFilename) { m_dlOutputFilename = outputFilename; } +std::string +MacStatsCalculator::GetDlOutputFilename (void) +{ + return m_dlOutputFilename; +} + void MacStatsCalculator::DlScheduling (uint16_t cellId, uint64_t imsi, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2) diff --git a/src/lte/helper/mac-stats-calculator.h b/src/lte/helper/mac-stats-calculator.h index 04be0fef0..89ca69fa4 100644 --- a/src/lte/helper/mac-stats-calculator.h +++ b/src/lte/helper/mac-stats-calculator.h @@ -66,6 +66,8 @@ public: */ void SetUlOutputFilename (std::string outputFilename); + std::string GetUlOutputFilename (void); + /** * Set the name of the file where the downlink statistics will be stored. * @@ -73,6 +75,8 @@ public: */ void SetDlOutputFilename (std::string outputFilename); + std::string GetDlOutputFilename (void); + /** * Notifies the stats calculator that an downlink scheduling has occurred. * @param cellId Cell ID of the attached Enb diff --git a/src/lte/helper/rlc-stats-calculator.cc b/src/lte/helper/rlc-stats-calculator.cc index e55371b27..9e0a25d43 100644 --- a/src/lte/helper/rlc-stats-calculator.cc +++ b/src/lte/helper/rlc-stats-calculator.cc @@ -105,12 +105,24 @@ RlcStatsCalculator::SetUlOutputFilename (std::string outputFilename) m_ulOutputFilename = outputFilename; } +std::string +RlcStatsCalculator::GetUlOutputFilename (void) +{ + return m_ulOutputFilename; +} + void RlcStatsCalculator::SetDlOutputFilename (std::string outputFilename) { m_dlOutputFilename = outputFilename; } +std::string +RlcStatsCalculator::GetDlOutputFilename (void) +{ + return m_dlOutputFilename; +} + void RlcStatsCalculator::UlTxPdu (uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize) diff --git a/src/lte/helper/rlc-stats-calculator.h b/src/lte/helper/rlc-stats-calculator.h index f8eba9570..53993da9d 100644 --- a/src/lte/helper/rlc-stats-calculator.h +++ b/src/lte/helper/rlc-stats-calculator.h @@ -88,6 +88,8 @@ public: */ void SetUlOutputFilename (std::string outputFilename); + std::string GetUlOutputFilename (void); + /** * Set the name of the file where the downlink statistics will be stored. * @@ -95,6 +97,8 @@ public: */ void SetDlOutputFilename (std::string outputFilename); + std::string GetDlOutputFilename (void); + /** * Notifies the stats calculator that an uplink transmission has occurred. * @param imsi IMSI of the UE who transmitted the PDU diff --git a/src/lte/test/lte-test-run-time.pl b/src/lte/test/lte-test-run-time.pl new file mode 100755 index 000000000..2a0cba135 --- /dev/null +++ b/src/lte/test/lte-test-run-time.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl +use strict; +use IO::CaptureOutput qw(capture qxx qxy); +use Statistics::Descriptive; + +my $nIterations = 1; + +open( FILE, '>times.csv' ); +print FILE "#sTime\tnFloors\tnEnb\tnUe\trTime\trTDev\n"; + +my @nUe = ( 1, 5, 10, 15, 20, 25, 30 ); +my @nEnb = ( 1, 2, 4, 6, 8, 12, 14, 18, 22 ); +my @nFloors = ( 0, 1 ); +#$my @simTime = ( 1, 5, 10, 20 ); +my @simTime = ( 1 ); + +my $traceDirectory = "/home/jnin/tmp/ns-3-lena-dev/"; + +foreach my $time (@simTime) +{ + foreach my $floor (@nFloors) + { + foreach my $enb (@nEnb) + { + foreach my $ue (@nUe) + { + my $timeStats = Statistics::Descriptive::Full->new(); + for ( my $iteration = 0 ; $iteration < $nIterations ; $iteration++ ) + { + my $launch = "time ./waf --run \'lena-runtime-profiler --simTime=$time --nUe=$ue --nEnb=$enb --nFloors=$floor --traceDirectory=$traceDirectory\'"; + my $out, my $err; + print "$launch\n"; + capture { system($launch ) } \$out, \$err; + $err =~ /real(.+)m(.+)s/; + my $minutes = $1; + my $seconds = $minutes * 60 + $2; + $timeStats->add_data($seconds); + } + print FILE "$time\t$floor\t$enb\t$ue\t"; + print FILE $timeStats->mean() . "\t" + . $timeStats->standard_deviation() . "\n"; + } + } + } +}