| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2015 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License v1.0 |
| 6 | * which accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Matthew Khouzam - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.lttng.scope.lttng.kernel.core.analysis.os.handlers.internal; |
| 14 | |
| 15 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
| 16 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; |
| 17 | import org.lttng.scope.lttng.kernel.core.analysis.os.Attributes; |
| 18 | import org.lttng.scope.lttng.kernel.core.trace.layout.ILttngKernelEventLayout; |
| 19 | |
| 20 | import ca.polymtl.dorsal.libdelorean.ITmfStateSystemBuilder; |
| 21 | import ca.polymtl.dorsal.libdelorean.exceptions.AttributeNotFoundException; |
| 22 | import ca.polymtl.dorsal.libdelorean.statevalue.ITmfStateValue; |
| 23 | import ca.polymtl.dorsal.libdelorean.statevalue.TmfStateValue; |
| 24 | |
| 25 | /** |
| 26 | * Set Prio handler |
| 27 | */ |
| 28 | public class PiSetprioHandler extends KernelEventHandler { |
| 29 | |
| 30 | /** |
| 31 | * Constructor |
| 32 | * @param layout event layout |
| 33 | */ |
| 34 | public PiSetprioHandler(ILttngKernelEventLayout layout) { |
| 35 | super(layout); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public void handleEvent(ITmfStateSystemBuilder ss, ITmfEvent event) throws AttributeNotFoundException { |
| 40 | ITmfEventField content = event.getContent(); |
| 41 | Integer cpu = KernelEventHandlerUtils.getCpu(event); |
| 42 | Integer tid = ((Long) content.getField(getLayout().fieldTid()).getValue()).intValue(); |
| 43 | Integer prio = ((Long) content.getField(getLayout().fieldNewPrio()).getValue()).intValue(); |
| 44 | |
| 45 | String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu); |
| 46 | if (threadAttributeName == null) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | Integer updateThreadNode = ss.getQuarkRelativeAndAdd(KernelEventHandlerUtils.getNodeThreads(ss), threadAttributeName); |
| 51 | |
| 52 | /* Set the current prio for the new process */ |
| 53 | int quark = ss.getQuarkRelativeAndAdd(updateThreadNode, Attributes.PRIO); |
| 54 | ITmfStateValue value = TmfStateValue.newValueInt(prio); |
| 55 | ss.modifyAttribute(KernelEventHandlerUtils.getTimestamp(event), value, quark); |
| 56 | } |
| 57 | } |