The invention provides a lightweight class method for system power consumption optimization based on online learning. The method comprises the steps of: 1, performing program compiling to generate target codes; 2, starting a monitoring module to monitor hardware events; 3, performing normalization processing of events; 4, building a system power consumption module; 5, designing different optimization modes; 6, designing a value function module; 7, writing the power consumption module, a penalty factor and the value function module into an agent module Agent; 8, designing a software timer and starting the third step and the seventh step regularly; 9, executing a program, the seventh step and the third step and updating the Agent; 10; setting convergence; 11, according to results of the Agent module, going to the second step and starting from the third step until operation is over. Through the steps, temperature, performance and power consumption are comprehensively and synergistically considered and a lightweight class machine learning algorithm is used to search for existing optimization space, so that the effects of low power consumption and reasonable performance are achieved and the problem is solved that working time is influenced because embedded devices are limited by batteries.