serialize.cc (7490:1803e46ddf57) | serialize.cc (7491:e8ff1fb26dbc) |
---|---|
1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 413 unchanged lines hidden (view full) --- 422void 423Serializable::unserialize(Checkpoint *cp, const string §ion) 424{ 425} 426 427void 428Serializable::serializeAll(const string &cpt_dir) 429{ | 1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 413 unchanged lines hidden (view full) --- 422void 423Serializable::unserialize(Checkpoint *cp, const string §ion) 424{ 425} 426 427void 428Serializable::serializeAll(const string &cpt_dir) 429{ |
430 setCheckpointDir(cpt_dir); 431 string dir = Checkpoint::dir(); | 430 string dir = Checkpoint::setDir(cpt_dir); |
432 if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST) 433 fatal("couldn't mkdir %s\n", dir); 434 435 string cpt_file = dir + Checkpoint::baseFilename; 436 ofstream outstream(cpt_file.c_str()); 437 time_t t = time(NULL); 438 if (!outstream.is_open()) 439 fatal("Unable to open file %s for writing\n", cpt_file.c_str()); 440 outstream << "## checkpoint generated: " << ctime(&t); 441 442 globals.serialize(outstream); 443 SimObject::serializeAll(outstream); 444} 445 446void 447Serializable::unserializeAll(const string &cpt_dir) 448{ | 431 if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST) 432 fatal("couldn't mkdir %s\n", dir); 433 434 string cpt_file = dir + Checkpoint::baseFilename; 435 ofstream outstream(cpt_file.c_str()); 436 time_t t = time(NULL); 437 if (!outstream.is_open()) 438 fatal("Unable to open file %s for writing\n", cpt_file.c_str()); 439 outstream << "## checkpoint generated: " << ctime(&t); 440 441 globals.serialize(outstream); 442 SimObject::serializeAll(outstream); 443} 444 445void 446Serializable::unserializeAll(const string &cpt_dir) 447{ |
449 setCheckpointDir(cpt_dir); 450 string dir = Checkpoint::dir(); 451 string cpt_file = dir + Checkpoint::baseFilename; 452 string section = ""; | 448 string dir = Checkpoint::setDir(cpt_dir); |
453 | 449 |
454 DPRINTFR(Config, "Loading checkpoint dir '%s'\n", 455 dir); 456 Checkpoint *cp = new Checkpoint(dir, section); | 450 DPRINTFR(Config, "Loading checkpoint dir '%s'\n", dir); 451 Checkpoint *cp = new Checkpoint(dir); |
457 unserializeGlobals(cp); 458 SimObject::unserializeAll(cp); 459} 460 461void 462Serializable::unserializeGlobals(Checkpoint *cp) 463{ 464 globals.unserialize(cp); 465} 466 | 452 unserializeGlobals(cp); 453 SimObject::unserializeAll(cp); 454} 455 456void 457Serializable::unserializeGlobals(Checkpoint *cp) 458{ 459 globals.unserialize(cp); 460} 461 |
467const char *Checkpoint::baseFilename = "m5.cpt"; 468 469static string checkpointDirBase; 470 | |
471void | 462void |
472setCheckpointDir(const string &name) 473{ 474 checkpointDirBase = name; 475 if (checkpointDirBase[checkpointDirBase.size() - 1] != '/') 476 checkpointDirBase += "/"; 477} 478 479string 480Checkpoint::dir() 481{ 482 // use csprintf to insert curTick into directory name if it 483 // appears to have a format placeholder in it. 484 return (checkpointDirBase.find("%") != string::npos) ? 485 csprintf(checkpointDirBase, curTick) : checkpointDirBase; 486} 487 488void | |
489debug_serialize(const string &cpt_dir) 490{ 491 Serializable::serializeAll(cpt_dir); 492} 493 494 495//////////////////////////////////////////////////////////////////////// 496// --- 52 unchanged lines hidden (view full) --- 549Serializable::create(Checkpoint *cp, const string §ion) 550{ 551 Serializable *object = SerializableClass::createObject(cp, section); 552 object->unserialize(cp, section); 553 return object; 554} 555 556 | 463debug_serialize(const string &cpt_dir) 464{ 465 Serializable::serializeAll(cpt_dir); 466} 467 468 469//////////////////////////////////////////////////////////////////////// 470// --- 52 unchanged lines hidden (view full) --- 523Serializable::create(Checkpoint *cp, const string §ion) 524{ 525 Serializable *object = SerializableClass::createObject(cp, section); 526 object->unserialize(cp, section); 527 return object; 528} 529 530 |
557Checkpoint::Checkpoint(const string &cpt_dir, const string &path) 558 : db(new IniFile), basePath(path), cptDir(cpt_dir) | 531const char *Checkpoint::baseFilename = "m5.cpt"; 532 533string Checkpoint::currentDirectory; 534 535string 536Checkpoint::setDir(const string &name) |
559{ | 537{ |
538 // use csprintf to insert curTick into directory name if it 539 // appears to have a format placeholder in it. 540 currentDirectory = (name.find("%") != string::npos) ? 541 csprintf(name, curTick) : name; 542 if (currentDirectory[currentDirectory.size() - 1] != '/') 543 currentDirectory += "/"; 544 return currentDirectory; 545} 546 547string 548Checkpoint::dir() 549{ 550 return currentDirectory; 551} 552 553 554Checkpoint::Checkpoint(const string &cpt_dir) 555 : db(new IniFile), cptDir(cpt_dir) 556{ |
|
560 string filename = cpt_dir + "/" + Checkpoint::baseFilename; 561 if (!db->load(filename)) { 562 fatal("Can't load checkpoint file '%s'\n", filename); 563 } 564} 565 566 567bool --- 25 unchanged lines hidden --- | 557 string filename = cpt_dir + "/" + Checkpoint::baseFilename; 558 if (!db->load(filename)) { 559 fatal("Can't load checkpoint file '%s'\n", filename); 560 } 561} 562 563 564bool --- 25 unchanged lines hidden --- |