Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: src/IceGlobalContext.h

Issue 1784243006: Subzero: Improve the use of timers. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceELFObjectWriter.cpp ('k') | src/IceGlobalContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===// 1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 TimerList(const TimerList &) = delete; 111 TimerList(const TimerList &) = delete;
112 TimerList &operator=(const TimerList &) = delete; 112 TimerList &operator=(const TimerList &) = delete;
113 113
114 public: 114 public:
115 TimerList() = default; 115 TimerList() = default;
116 /// initInto() initializes a target list of timers based on the 116 /// initInto() initializes a target list of timers based on the
117 /// current list. In particular, it creates the same number of 117 /// current list. In particular, it creates the same number of
118 /// timers, in the same order, with the same names, but initially 118 /// timers, in the same order, with the same names, but initially
119 /// empty of timing data. 119 /// empty of timing data.
120 void initInto(TimerList &Dest) const { 120 void initInto(TimerList &Dest) const {
121 if (!BuildDefs::dump()) 121 if (!BuildDefs::timers())
122 return; 122 return;
123 Dest.clear(); 123 Dest.clear();
124 for (const TimerStack &Stack : *this) { 124 for (const TimerStack &Stack : *this) {
125 Dest.push_back(TimerStack(Stack.getName())); 125 Dest.push_back(TimerStack(Stack.getName()));
126 } 126 }
127 } 127 }
128 void mergeFrom(TimerList &Src) { 128 void mergeFrom(TimerList &Src) {
129 if (!BuildDefs::dump()) 129 if (!BuildDefs::timers())
130 return; 130 return;
131 assert(size() == Src.size()); 131 assert(size() == Src.size());
132 size_type i = 0; 132 size_type i = 0;
133 for (TimerStack &Stack : *this) { 133 for (TimerStack &Stack : *this) {
134 assert(Stack.getName() == Src[i].getName()); 134 assert(Stack.getName() == Src[i].getName());
135 Stack.mergeFrom(Src[i]); 135 Stack.mergeFrom(Src[i]);
136 ++i; 136 ++i;
137 } 137 }
138 } 138 }
139 }; 139 };
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 TranslationThreads.clear(); 374 TranslationThreads.clear();
375 375
376 // Only notify the emit queue to end after all the translation threads have 376 // Only notify the emit queue to end after all the translation threads have
377 // ended. 377 // ended.
378 emitQueueNotifyEnd(); 378 emitQueueNotifyEnd();
379 for (std::thread &Worker : EmitterThreads) { 379 for (std::thread &Worker : EmitterThreads) {
380 Worker.join(); 380 Worker.join();
381 } 381 }
382 EmitterThreads.clear(); 382 EmitterThreads.clear();
383 383
384 if (BuildDefs::dump()) { 384 if (BuildDefs::timers()) {
385 auto Timers = getTimers(); 385 auto Timers = getTimers();
386 for (ThreadContext *TLS : AllThreadContexts) 386 for (ThreadContext *TLS : AllThreadContexts)
387 Timers->mergeFrom(TLS->Timers); 387 Timers->mergeFrom(TLS->Timers);
388 } 388 }
389 if (BuildDefs::dump()) { 389 if (BuildDefs::dump()) {
390 // Do a separate loop over AllThreadContexts to avoid holding two locks 390 // Do a separate loop over AllThreadContexts to avoid holding two locks
391 // at once. 391 // at once.
392 auto Stats = getStatsCumulative(); 392 auto Stats = getStatsCumulative();
393 for (ThreadContext *TLS : AllThreadContexts) 393 for (ThreadContext *TLS : AllThreadContexts)
394 Stats->add(TLS->StatsCumulative); 394 Stats->add(TLS->StatsCumulative);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 /// of code. 553 /// of code.
554 class TimerMarker { 554 class TimerMarker {
555 TimerMarker() = delete; 555 TimerMarker() = delete;
556 TimerMarker(const TimerMarker &) = delete; 556 TimerMarker(const TimerMarker &) = delete;
557 TimerMarker &operator=(const TimerMarker &) = delete; 557 TimerMarker &operator=(const TimerMarker &) = delete;
558 558
559 public: 559 public:
560 TimerMarker(TimerIdT ID, GlobalContext *Ctx, 560 TimerMarker(TimerIdT ID, GlobalContext *Ctx,
561 TimerStackIdT StackID = GlobalContext::TSK_Default) 561 TimerStackIdT StackID = GlobalContext::TSK_Default)
562 : ID(ID), Ctx(Ctx), StackID(StackID) { 562 : ID(ID), Ctx(Ctx), StackID(StackID) {
563 if (BuildDefs::dump()) 563 if (BuildDefs::timers())
564 push(); 564 push();
565 } 565 }
566 TimerMarker(TimerIdT ID, const Cfg *Func, 566 TimerMarker(TimerIdT ID, const Cfg *Func,
567 TimerStackIdT StackID = GlobalContext::TSK_Default) 567 TimerStackIdT StackID = GlobalContext::TSK_Default)
568 : ID(ID), Ctx(nullptr), StackID(StackID) { 568 : ID(ID), Ctx(nullptr), StackID(StackID) {
569 // Ctx gets set at the beginning of pushCfg(). 569 // Ctx gets set at the beginning of pushCfg().
570 if (BuildDefs::dump()) 570 if (BuildDefs::timers())
571 pushCfg(Func); 571 pushCfg(Func);
572 } 572 }
573 TimerMarker(GlobalContext *Ctx, const IceString &FuncName)
574 : ID(getTimerIdFromFuncName(Ctx, FuncName)), Ctx(Ctx),
575 StackID(GlobalContext::TSK_Funcs) {
576 if (BuildDefs::timers())
577 push();
578 }
573 579
574 ~TimerMarker() { 580 ~TimerMarker() {
575 if (BuildDefs::dump() && Active) 581 if (BuildDefs::timers() && Active)
576 Ctx->popTimer(ID, StackID); 582 Ctx->popTimer(ID, StackID);
577 } 583 }
578 584
579 private: 585 private:
580 void push(); 586 void push();
581 void pushCfg(const Cfg *Func); 587 void pushCfg(const Cfg *Func);
588 static TimerIdT getTimerIdFromFuncName(GlobalContext *Ctx,
589 const IceString &FuncName);
582 const TimerIdT ID; 590 const TimerIdT ID;
583 GlobalContext *Ctx; 591 GlobalContext *Ctx;
584 const TimerStackIdT StackID; 592 const TimerStackIdT StackID;
585 bool Active = false; 593 bool Active = false;
586 }; 594 };
587 595
588 /// Helper class for locking the streams and then automatically unlocking them. 596 /// Helper class for locking the streams and then automatically unlocking them.
589 class OstreamLocker { 597 class OstreamLocker {
590 private: 598 private:
591 OstreamLocker() = delete; 599 OstreamLocker() = delete;
592 OstreamLocker(const OstreamLocker &) = delete; 600 OstreamLocker(const OstreamLocker &) = delete;
593 OstreamLocker &operator=(const OstreamLocker &) = delete; 601 OstreamLocker &operator=(const OstreamLocker &) = delete;
594 602
595 public: 603 public:
596 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } 604 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); }
597 ~OstreamLocker() { Ctx->unlockStr(); } 605 ~OstreamLocker() { Ctx->unlockStr(); }
598 606
599 private: 607 private:
600 GlobalContext *const Ctx; 608 GlobalContext *const Ctx;
601 }; 609 };
602 610
603 } // end of namespace Ice 611 } // end of namespace Ice
604 612
605 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H 613 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H
OLDNEW
« no previous file with comments | « src/IceELFObjectWriter.cpp ('k') | src/IceGlobalContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698