1. A computer program product for associating energy consumption with a task, the computer program product comprising: a computer readable storage medium having computer usable program code embodied therewith, the computer usable program code comprising a computer usable program code configured to: cause each of a plurality of processor cores to record, into a register of the processor core, a task identifier associated with a task to be executed on the processor core wherein a processor comprises the plurality of processor cores; in response to detection of a first event, cause those of the plurality of processor cores corresponding to the first event or executing a task corresponding to the first event to write energy consumption data of the processor core in association with the task identifier in the register of the processor core to a first memory shared by the plurality of process cores, wherein each of the plurality of processor cores has energy consumption data that indicates energy consumption by components associated with the processor core, and wherein the processor further comprises the first memory; periodically read the energy consumption data and associated task identifier from the first memory; aggregate the energy consumption data by task identifier; for each task identifier read from the first memory, write the aggregated energy consumption data to a second memory, wherein the second memory is external to the processor; detecting a signal from a hypervisor at a power state change register; and causing each of the plurality of processor cores to write additional energy consumption data of the processor core in association with the task identifier in the register associated with the processor core to the first memory shared by the plurality of processor cores.