Powertrace: a program that periodically prints out the power consumption; suitable for experiments or simulations that want to measure power consumption
This commit is contained in:
parent
60425aa355
commit
5e6fd67213
5 changed files with 266 additions and 0 deletions
1
apps/powertrace/Makefile.powertrace
Normal file
1
apps/powertrace/Makefile.powertrace
Normal file
|
@ -0,0 +1 @@
|
|||
powertrace_src = powertrace.c
|
118
apps/powertrace/powertrace.c
Normal file
118
apps/powertrace/powertrace.c
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 THE INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: powertrace.c,v 1.1 2010/02/20 14:15:45 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Powertrace: periodically print out power consumption
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "sys/compower.h"
|
||||
#include "node-id.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
PROCESS(powertrace_process, "Periodic power output");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
print_power(void)
|
||||
{
|
||||
static uint32_t last_cpu, last_lpm, last_transmit, last_listen;
|
||||
static uint32_t last_idle_transmit, last_idle_listen;
|
||||
|
||||
static uint32_t cpu, lpm, transmit, listen;
|
||||
static uint32_t idle_transmit, idle_listen;
|
||||
|
||||
static uint32_t seqno;
|
||||
|
||||
uint32_t time;
|
||||
|
||||
energest_flush();
|
||||
|
||||
cpu = energest_type_time(ENERGEST_TYPE_CPU) - last_cpu;
|
||||
lpm = energest_type_time(ENERGEST_TYPE_LPM) - last_lpm;
|
||||
transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT) - last_transmit;
|
||||
listen = energest_type_time(ENERGEST_TYPE_LISTEN) - last_listen;
|
||||
idle_transmit = compower_idle_activity.transmit - last_idle_transmit;
|
||||
idle_listen = compower_idle_activity.listen - last_idle_listen;
|
||||
|
||||
last_cpu = energest_type_time(ENERGEST_TYPE_CPU);
|
||||
last_lpm = energest_type_time(ENERGEST_TYPE_LPM);
|
||||
last_transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT);
|
||||
last_listen = energest_type_time(ENERGEST_TYPE_LISTEN);
|
||||
last_idle_listen = compower_idle_activity.listen;
|
||||
last_idle_transmit = compower_idle_activity.transmit;
|
||||
|
||||
time = cpu + lpm;
|
||||
|
||||
printf("P %d %lu %lu %lu %lu %lu %lu %lu (radio %d.%02d%% tx %d.%02d%% listen %d.%02d%%)\n",
|
||||
node_id, seqno++,
|
||||
cpu, lpm, transmit, listen, idle_transmit, idle_listen,
|
||||
(int)((100L * (transmit + listen)) / time),
|
||||
(int)((10000L * (transmit + listen) / time) - (100L * (transmit + listen)) / time),
|
||||
(int)((100L * (transmit)) / time),
|
||||
(int)((10000L * (transmit)) / time - (100L * (transmit)) / time),
|
||||
(int)((100L * (listen)) / time),
|
||||
(int)((10000L * (listen)) / time - (100L * (listen)) / time));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(powertrace_process, ev, data)
|
||||
{
|
||||
static struct etimer periodic;
|
||||
clock_time_t *period;
|
||||
PROCESS_BEGIN();
|
||||
|
||||
period = data;
|
||||
|
||||
if(period == NULL) {
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
etimer_set(&periodic, *period);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_UNTIL(etimer_expired(&periodic));
|
||||
etimer_reset(&periodic);
|
||||
print_power();
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
powertrace_start(clock_time_t period)
|
||||
{
|
||||
process_start(&powertrace_process, (void *)&period);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
48
apps/powertrace/powertrace.h
Normal file
48
apps/powertrace/powertrace.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 THE INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: powertrace.h,v 1.1 2010/02/20 14:15:45 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Header file for the powertrace application
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef POWERTRACE_H
|
||||
#define POWERTRACE_H
|
||||
|
||||
#include "sys/clock.h"
|
||||
|
||||
void powertrace_start(clock_time_t perioc);
|
||||
|
||||
#endif /* POWERTRACE_H */
|
6
examples/powertrace/Makefile
Normal file
6
examples/powertrace/Makefile
Normal file
|
@ -0,0 +1,6 @@
|
|||
CONTIKI_PROJECT = example-powertrace
|
||||
APPS+=powertrace
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
CONTIKI = ../..
|
||||
include $(CONTIKI)/Makefile.include
|
93
examples/powertrace/example-powertrace.c
Normal file
93
examples/powertrace/example-powertrace.c
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 THE INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: example-powertrace.c,v 1.1 2010/02/20 14:15:45 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Demonstrating the powertrace application with broadcasts
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "net/rime.h"
|
||||
#include "random.h"
|
||||
|
||||
#include "powertrace.h"
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(example_broadcast_process, "BROADCAST example");
|
||||
AUTOSTART_PROCESSES(&example_broadcast_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from)
|
||||
{
|
||||
printf("broadcast message received from %d.%d: '%s'\n",
|
||||
from->u8[0], from->u8[1], (char *)packetbuf_dataptr());
|
||||
}
|
||||
static const struct broadcast_callbacks broadcast_call = {broadcast_recv};
|
||||
static struct broadcast_conn broadcast;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(example_broadcast_process, ev, data)
|
||||
{
|
||||
static struct etimer et;
|
||||
|
||||
PROCESS_EXITHANDLER(broadcast_close(&broadcast);)
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
|
||||
/* Start powertracing, once every two seconds. */
|
||||
powertrace_start(CLOCK_SECOND * 2);
|
||||
|
||||
broadcast_open(&broadcast, 129, &broadcast_call);
|
||||
|
||||
while(1) {
|
||||
|
||||
/* Delay 2-4 seconds */
|
||||
etimer_set(&et, CLOCK_SECOND * 4 + random_rand() % (CLOCK_SECOND * 4));
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
|
||||
packetbuf_copyfrom("Hello", 6);
|
||||
broadcast_send(&broadcast);
|
||||
printf("broadcast message sent\n");
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
Loading…
Reference in a new issue